Hi everybody.
My name is Martin. I want to use DS1302 basic library made by user named "Krodal" (This is the link Arduino Playground - DS1302) in my application where of course I use DS1302 rtc timer.
I am not familiar whit new convenience in C language programming, so I want to ask another people who know better.
I do not seem, that this function "void DS1302_clock_burst_write(uint8_t *p)" from that library works well. I do not think when I use there in function pointer to structure and I convert it to pointer to integer it begins to work with first member of that structure. For example: " DS1302_clock_burst_write((uint8_t *) &rtc)". First of course I filled members of "rtc" structure by values and then I used this function. But results I was expecting were different.
So I made test where I put values of my defined structure "rtc" to serial monitor of Arduino and results were so, as I wrote them into "rtc" structure.
seconds = 15;
minutes = 0;
hours = 9;
dayofweek = 3;
dayofmonth = 9;
month = 7;
year = 2014;
memset((uint8_t*)&rtc, 0, sizeof(rtc));
rtc.Seconds = bin2bcd_l(seconds);
rtc.Seconds10 = bin2bcd_h(seconds);
rtc.CH = 0;
rtc.Minutes = bin2bcd_l(minutes);
rtc.Minutes10 = bin2bcd_h(minutes);
rtc.h24.Hour = bin2bcd_l(hours);
rtc.h24.Hour10 = bin2bcd_h(hours);
rtc.h24.hour_12_24 = 0;
rtc.Date = bin2bcd_l(dayofmonth);
rtc.Date10 = bin2bcd_h(dayofmonth);
rtc.Day = dayofweek;
rtc.Month = bin2bcd_l(month);
rtc.Month10 = bin2bcd_h(month);
rtc.Year = bin2bcd_l(year - 2000);
rtc.Year10 = bin2bcd_h(year - 2000);
rtc.WP = 0;
// here it is correct and I can see correct values which are written in "rtc" structure also on serial monitor
#ifdef TEST
Serial.println(bcd2bin(rtc.Minutes10, rtc.Minutes));
Serial.println(bcd2bin(rtc.h24.Hour10, rtc.h24.Hour));
Serial.println(bcd2bin(rtc.Date10, rtc.Date));
Serial.println(rtc.Day);
Serial.println(bcd2bin(rtc.Month10, rtc.Month));
Serial.println(bcd2bin(rtc.Year10, rtc.Year));
#endif
/But after using these functions values on serial monitor are all zeros and I do not know why?
DS1302_clock_burst_write((uint8_t *) &rtc);
#ifdef TEST
DS1302_clock_burst_read((uint8_t*) &rtc);
Serial.println(bcd2bin(rtc.Minutes10, rtc.Minutes));
Serial.println(bcd2bin(rtc.h24.Hour10, rtc.h24.Hour));
Serial.println(bcd2bin(rtc.Date10, rtc.Date));
Serial.println(rtc.Day);
Serial.println(bcd2bin(rtc.Month10, rtc.Month));
Serial.println(bcd2bin(rtc.Year10, rtc.Year));
#endif
Can anybody help me please? Maybe someone of you hook up already whit this issue. I also controlled connection between Arduino an DS1302 module and controlled supply voltage and it seemed to be correct. And pins are correctly defined in my program too. So what can be problem?
Thanks for your help. Martin.