cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4 RTC

Posted on March 15, 2018 at 19:43

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:1

DateTime - 1/1/2000-1-0:0:2

DateTime - 1/1/2000-1-0:0:3

DateTime - 1/1/2000-1-0:0:4

DateTime - 1/1/2000-1-0:0:5

DateTime - 1/1/2000-1-0:0:6

DateTime - 1/1/2000-1-0:0:7

DateTime - 1/1/2000-1-0:0:8

DateTime - 1/1/2000-1-0:0:9 

DateTime - 1/1/2000-1-0:0:16

DateTime - 1/1/2000-1-0:0:17

DateTime - 1/1/2000-1-0:0:18

DateTime - 1/1/2000-1-0:0:19

DateTime - 1/1/2000-1-0:0:20

DateTime - 1/1/2000-1-0:0:21

DateTime - 1/1/2000-1-0:0:22

DateTime - 1/1/2000-1-0:0:23

DateTime - 1/1/2000-1-0:0:24

DateTime - 1/1/2000-1-0:0:25

DateTime - 1/1/2000-1-0:0:32

...

DateTime - 1/1/2000-1-0:0:56

DateTime - 1/1/2000-1-0:0:57

DateTime - 1/1/2000-1-0:0:64

DateTime - 1/1/2000-1-0:0:65

...

DateTime - 1/1/2000-1-0:0:88

DateTime - 1/1/2000-1-0:0:89

DateTime - 1/1/2000-1-0:1:0

DateTime - 1/1/2000-1-0:1:1

So:

  • 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?

1 ACCEPTED SOLUTION

Accepted Solutions
Posted on March 15, 2018 at 22:41

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

View solution in original post

1 REPLY 1
Posted on March 15, 2018 at 22:41

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