CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problem with PIC16f873@4MHZ and RTC DS1305

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
andreluizeng



Joined: 04 Apr 2006
Posts: 117
Location: Brasil

View user's profile Send private message Send e-mail MSN Messenger

Problem with PIC16f873@4MHZ and RTC DS1305
PostPosted: Tue Apr 04, 2006 3:00 pm     Reply with quote

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�. Very Happy
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 04, 2006 3:04 pm     Reply with quote

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

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Tue Apr 04, 2006 5:40 pm     Reply with quote

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







PostPosted: Wed Apr 05, 2006 6:25 am     Reply with quote

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

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Wed Apr 05, 2006 11:47 am     Reply with quote

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�
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group