I am facing a fail in my GetTime measurement with your RTC module. I read the time at the beginning of my project and store it as StartTime variable. I use the ADC interrupt and I perform the measurement Seconds=RTC_GetTime()-StartTimeTime each 200ms. The measurement is performed perfectly from 0-16 seconds, then jumps to 23 and measures correctly till 32, then jumps again to 39 and so on. When variable Seconds is at 64, it jumps to 231... I don't know whether it is a clock issue or simply I need a kind of hexadecimal conversion. I attached both my UART log and the archived project so you can easily reproduce it. It is reproducible with the PRoC Eval Kit (project attached).
Looking forward to your feedback,
Solved! Go to Solution.
Thanks for the quick response. Is a predefined function to convert BCD to integer available? Or do I need to do it by myself?
Before conversion is jumping from 64 (0x40) to 231 (0xE7) and after conversion is jumping from 40 (0x28) to 81 (0x51). So nothing is clearer 😞 I am using %lu and %ld (my printed variable is uint32) in the sprintf function to check if this is just a display issue but I got the same results. I also tried to define my printed variable as Int instead of uint32 and I got the same result as well.
sprintf(MyBuffer, "Seconds: %lu\r\n", Seconds);
I have also used a open Software code in the Internet and I got the same issue, from 40 to 81 is always jumping the value.
Is there a kind of BCD to pure integer (uint32) conversion function? If you know how to solve the issue, I would really avoid to reinvent the wheel here 😄
Thanks for sharing the code Bobgoar. It looks like the functions RTC_GetSecond, RTC_GetMinutes and so on are working as expected and convert BCD to Decimal in a correct way and not as RTC_P4_ConvertBCDToDec function which doesn't really convert BCD to Decimal.
With the below code I am obtaining the total seconds as I wanted. I would prefer to use just one function for that instead of 4 but it seems to require additional coding and calculations.
Seconds = 86400*RTC_GetDay(RTC_GetTime())+