STM32L4 RTC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-03-15 11:43 AM
Hi all,
I'm facing an odd behavior working with an L4/Nucleo64/CubeMX/HAL. RTC peripheral. Same result w/ and w/o LSE oscillator.
Basically, a code like this:
while (1) {
HAL_RTC_GetTime(&hrtc, &sTime, FORMAT_BCD);
HAL_RTC_GetDate(&hrtc, &sDate, FORMAT_BCD); printf('DateTime ......', ......, sTime.Hours, sTime.Minutes, sTime.Seconds);HAL_Delay(1000);
}
Results in:
DateTime - 1/1/2000-1-0:0:0
DateTime - 1/1/2000-1-0:0:1DateTime - 1/1/2000-1-0:0:2DateTime - 1/1/2000-1-0:0:3DateTime - 1/1/2000-1-0:0:4DateTime - 1/1/2000-1-0:0:5DateTime - 1/1/2000-1-0:0:6DateTime - 1/1/2000-1-0:0:7DateTime - 1/1/2000-1-0:0:8DateTime - 1/1/2000-1-0:0:9 DateTime - 1/1/2000-1-0:0:16DateTime - 1/1/2000-1-0:0:17DateTime - 1/1/2000-1-0:0:18DateTime - 1/1/2000-1-0:0:19DateTime - 1/1/2000-1-0:0:20DateTime - 1/1/2000-1-0:0:21DateTime - 1/1/2000-1-0:0:22DateTime - 1/1/2000-1-0:0:23DateTime - 1/1/2000-1-0:0:24DateTime - 1/1/2000-1-0:0:25DateTime - 1/1/2000-1-0:0:32...
DateTime - 1/1/2000-1-0:0:56
DateTime - 1/1/2000-1-0:0:57DateTime - 1/1/2000-1-0:0:64DateTime - 1/1/2000-1-0:0:65...
DateTime - 1/1/2000-1-0:0:88
DateTime - 1/1/2000-1-0:0:89DateTime - 1/1/2000-1-0:1:0DateTime - 1/1/2000-1-0:1:1So:
- every 10 accesses to GetTime, RTC jumps 7 seconds after;
- seconds counts up to 90. Probably minutes and hours will be wrong later.
Any idea?
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-03-15 2:41 PM
BCD means Binary Coded Decimal (more precisely it's packed BCD).
In BCD, you count
0x00, 0x01, 0x02... 0x09, 0x10, 0x11, 0x12... 0x58, 0x59, 0x00, 0x01...
But you then take those BCD numbers and print them in decimal, which for the same sequence as above is:
0, 1, 2... 9, 16, 17, 18... 88, 89, 0, 1....
and that's exactly what you observe.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-03-15 2:41 PM
BCD means Binary Coded Decimal (more precisely it's packed BCD).
In BCD, you count
0x00, 0x01, 0x02... 0x09, 0x10, 0x11, 0x12... 0x58, 0x59, 0x00, 0x01...
But you then take those BCD numbers and print them in decimal, which for the same sequence as above is:
0, 1, 2... 9, 16, 17, 18... 88, 89, 0, 1....
and that's exactly what you observe.
JW
