ds1307 drives me crazy..

hii,

i am finding problem with ds1307. it is interfaced to at89c51. the code is as follows:

void main() { init_timer(); //for lcd delay init_lcd(); set_time(); while(1) display_time(); }

void set_time() { rtc_start(); shiftout_rtc(RTC_WRITE); shiftout_rtc(0); shiftout_rtc(0x20); shiftout_rtc(0x00); //0x00 has no effect, on reading, i get //30 for minutes irrespective of the //value i send here. rtc_stop(); }

void display_time() { int i, j; char disp_buffer[2], seconds, minutes; rtc_start(); shiftout_rtc(RTC_WRITE); shiftout_rtc(0); rtc_start(); shiftout_rtc(RTC_READ); seconds = shiftin_rtc()&0x7f; send_ack(); minutes = shiftin_rtc()&0x7f; send_nack(); rtc_stop(); pass_cmd(0x80); sprintf(disp_buffer, "%x", seconds); for(j = 0; j < 2; j++) { pass_data(disp_buffer[j]); } pass_data(':'); sprintf(disp_buffer, "%x", minutes); for(j = 0; j < 2; j++) { pass_data(disp_buffer[j]); } }

void send_ack() { SCL_RTC = 1; delay_ep(100); SDA_RTC = 0; delay_ep(100); SCL_RTC = 0; delay_ep(100); }

void send_nack() {

SCL_RTC = 1; delay_ep(100); SDA_RTC = 1; delay_ep(100); SCL_RTC = 0; delay_ep(100); }

initial value got from reading the rtc is correct in case of seconds. it begins at 20, but increments bit slowly, in about 2 seconds. after

60, it becomes 0, then 10, 20, etc. also, minutes starts at 30 irrespective of the value i send, and doesn't increment properly. i use 32.768 watch xtal. there is no problem with rtc_start(), shiftout_rtc(), or rtc_stop() as they worked fine with an eeprom application i did earlier. i guess the trouble is with setting/reading the rtc, but i cant locate exactly.

any help will be appreciated. thanx

Reply to
DigitalBug
Loading thread data ...

hii folks, even the seconds do not work properly. ofcourse, it increments every second, but starts from 20 irrespective of the value i pass.

DigitalBug wrote:

Reply to
DigitalBug

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----

formatting link
The #1 Newsgroup Service in the World! 120,000+ Newsgroups

----= East and West-Coast Server Farms - Total Privacy via Encryption =----

Reply to
Nigel Thomson

Hi,

DigitalBug schrieb:

I found that many RTCs are upset when you access them too often. Limit your reads to once per seconds or so, and see what happens.

HTH Wolfgang

--
From-address is Spam trap
Use: wolfgang (dot) mahringer (at) sbg (dot) at
Reply to
Wolfgang Mahringer

the code i wrote for sending data into ds1307 is as follows:

void shiftout_rtc(char c) { int i; shftData_rtc=c; for(i=0;i

Reply to
DigitalBug

hi friends,

that was the problem. when i access the rtc only when required, things get displayed correctly. thanx folks for your help.

sharaf

Reply to
DigitalBug

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.