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

DS1306 and spi problem

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



Joined: 09 Dec 2009
Posts: 37

View user's profile Send private message

DS1306 and spi problem
PostPosted: Fri Aug 27, 2010 5:57 am     Reply with quote

Hi
I am again with new problem with SPI that took 2 days also and could not find solution.

I have DS1306 RTC connected to 18F8722.
Connection is :
VCC1 to +5v
VCCIF TO +5V
VCC2 TO GROUND
VBAT TO 3V BATTERY

After I wrote a sample program to read the seconds I noticed the seconds is incrementing every 2 minutes ! I replaced the crystal 32768hz 3 times I thought the crystal is bad, but it still give me the same result.

Here is the code:
Thank you in advance
Code:

setup_spi(SPI_MASTER| SPI_MODE_0_0|SPI_CLK_DIV_64);

while(1)  // loop for ever
{
  output_h(0xd4);  // enable rtc active high
spi_write(0x00);  // address of seconds
second= spi_read(0);
output_h(0xd0);  // disable rtc

glcd_gotoxy(5,3,1);
printf(glcd_putc,"%x",second);   // put seconds in hex on glcd

delay_ms(10);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 27, 2010 11:21 am     Reply with quote

Quote:
setup_spi(SPI_MASTER| SPI_MODE_0_0|SPI_CLK_DIV_64);

while(1) // loop for ever
{
output_h(0xd4); // enable rtc active high
spi_write(0x00); // address of seconds
second= spi_read(0);
output_h(0xd0); // disable rtc

glcd_gotoxy(5,3,1);
printf(glcd_putc,"%x",second); // put seconds in hex on glcd

delay_ms(10);
}

Why are you writing to all bits on Port H, just to set the Enable pin high
and low ? Most people would use output_high(DS1306_ENABLE_PIN)
and output_low(DS1306_ENABLE_PIN), where DS1306_ENABLE_PIN is
set to PIN_H2 with a #define statement.


Quote:

setup_spi(SPI_MASTER| SPI_MODE_0_0|SPI_CLK_DIV_64);

Why are you using SPI mode 0 ? The ds1306 data sheet tells you
the supported SPI modes, right on the front page ! It says:
Quote:

Supports Motorola SPI (Serial Peripheral Interface)
Modes 1 and 3 or Standard 3-Wire

Download and read the data sheet carefully:
http://pdfserv.maxim-ic.com/en/ds/DS1306.pdf

Do you have the SERMODE pin connected to +5v on the ds1306 ?
You must do that, to configure it to use "4-wire" (i.e., SPI) mode.

---------
Edit:
Changed ds1305 to ds1306. All comments still apply.


Last edited by PCM programmer on Fri Aug 27, 2010 4:56 pm; edited 1 time in total
assaad



Joined: 09 Dec 2009
Posts: 37

View user's profile Send private message

PostPosted: Fri Aug 27, 2010 12:00 pm     Reply with quote

Thank you again for reply,

In my Ds1306 when I use mode 1 and 3 the spi bus hangs and stuck.
I use port h because I am using encoder to drive 4 chips on the same spi bus, so at the time only one chip is active. For Ds1306 I have an inverter connected to the output of the encoder because the enable of it active high.

Yes I have SERMODE conencted to Vdd .
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 27, 2010 4:57 pm     Reply with quote

I suggest that you remove the encoder and the inverter chips, and
disconnect all the other SPI slave devices, and only test the ds1306
with the PIC. Get the ds1306 working alone. Then later try to make
the encoder version of the project work.
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