View previous topic :: View next topic |
Author |
Message |
andreluizeng
Joined: 04 Apr 2006 Posts: 117 Location: Brasil
|
Problem with PIC16f873@4MHZ and RTC DS1305 |
Posted: Tue Apr 04, 2006 3:00 pm |
|
|
Hello Guyz.
Im having my first experience with spi bus and it is not going well.
my power supply conections are:
VCCIF = +5V
VCC1 = +5V
VBAT = 0V
VCC2 = 0V
im initializing the EOSCK and WP before i do everything else.
i cant read anything from the RTC, see a part of code (Initialization):
Code: |
unsigned int TransfSPI (boolean Modo, unsigned int Endereco, unsigned int Dado) // 1 leitura 0 escrita
{
if (Modo)
{
delay_us (10);
spi_write (Endereco);
delay_us (10);
return spi_read (0);
}
else
{
delay_us (10);
spi_write (Endereco);
delay_us (10);
spi_write (Dado);
}
}
|
Code: |
void main()
{
setup_adc_ports (NO_ANALOGS);
setup_adc (ADC_OFF);
setup_counters (RTCC_INTERNAL, RTCC_DIV_2);
setup_spi (SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_4);
CKP = SMP = FALSE;
CKE = TRUE;
setup_timer_1 (T1_DISABLED);
setup_timer_2 (T2_DISABLED, 0, 1);
enable_interrupts (INT_RTCC);
enable_interrupts (global);
set_tris_c (0xD2);
.
.
.
TransfSPI (0, WCTRLRTC, 0x05);
|
where WCTRLRTC = write CTRL RTC = 0x8f
I'll not list the rest of code, it is unecessary, but after that i just write and read from the bus
I've tried to write on rtc registers (hours, minutes and seconds) and read these same values just to check if it was equals, but i just read zeros or garbage...
maybe my rtc (Component) is not good, but i dont think so.. it is new..
if somebody know how to fix my problem.
please. help me.
regards.
André. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Apr 04, 2006 3:04 pm |
|
|
CCS has a driver for the DS1305. It uses software SPI, but you
can change the #define statements in it so it uses your pins.
You can test your hardware this way. Look for DS1305.C in this folder:
c:\Program Files\PICC\Drivers |
|
|
andreluizeng
Joined: 04 Apr 2006 Posts: 117 Location: Brasil
|
|
Posted: Tue Apr 04, 2006 5:40 pm |
|
|
I checked it out, but i dont have this driver...
maybe my compiler´s version (v3.168, pcm, pch ,pcb) hasn´t this driver.
the only ones are: ds1302, ds1621, ds1621m, ds1624, ds1631, ds1868.
thanks for the help.
regards.
André |
|
|
abdullah bilir Guest
|
|
Posted: Wed Apr 05, 2006 6:25 am |
|
|
hi
when using rtcc you need to be with the time you spent in isr
I had problem alot of times wit timer too.now I use protus debugger to get time spent in isr if you spent more time or load timer with a lower value than its current value in isr you get un balanced timeouts.I generaly use function pointers that spents same time in isr for mutitasked isr routines |
|
|
andreluizeng
Joined: 04 Apr 2006 Posts: 117 Location: Brasil
|
|
Posted: Wed Apr 05, 2006 11:47 am |
|
|
hi Abdullah,
im not using rtcc to generate the rtc clock,
and my problem is: i cant comunicate PIC and DS1305 (RTC) on spi bus.
i dont know whats going on.
thanks for the help.
Regards.
André |
|
|
|