2020-05-06 09:20 PM
Hi all,
I'm currently using a nucleo-L031 board for some testing and I came across a weird RTC phenomenon.
My goal is to do some ADC and send the data through USART, set up an RTC alarm for 10 seconds later, and then fall into stop mode.
I have set up the main system clock to be drawn from the HSE, and the timer setup to use the ADC works correctly (i.e. correctly samples 10 samples over 1 sec, then send the data through USART), so I know that the HSE is clocking.
I was able to achieve the RTC alarm and timing using the LSI and the LSE by adjusting the prescaler values correctly, but I was unable to do this using the HSE no matter the prescaler value. In fact, I even set the prescaler factor to both 1 and to 2^22, but neither had an effect on incrementing time which I tried to get using HAL_RTC_GetTime function.
I'm going to use an STM32F051K8 custom board with this program later, and the MCU is only compatible with an HSE but not an LSE, and considering timining is important in this project, I really need this solved.
Has anyone had this issue or solved it? Any help is much appreciated, thank you in advance!
Solved! Go to Solution.
2020-05-06 11:31 PM
2020-05-06 10:59 PM
Which RTC alarm did you set, ALRMAR/ALRMBR or WUTR? Check the RTC block diagram in the reference manual, note that the WUTR timer clocking bypasses some prescalers.
2020-05-06 11:16 PM
I set up ALRMAR (for the sole reason that this is the only one that is available on F051K8 as well).
I'm thinking it's not the alarm setup that's wrong, but that the RTC is not counting with HSE as the clock source - no matter the prescaler values or how long after initializing I use HAL_RTC_GetTime function, the value is always 00:00:00...
From the RTC block diagram, it does not seem like I need to do anything by selecting HSE instead of LSE.
Any other issues you can spot?
Thank you
2020-05-06 11:31 PM
HSE works in stop mode?
JW
2020-05-06 11:36 PM
Yes, RTC clock source is selected in the RCC, not in the RTC. Check the RCC->CR and RCC->CSR registers.
2020-05-07 01:10 AM
Hi, I checked the registers in debugging mode and found that
While looking this up, I found that HSE cannot be used during Stop mode as JW mentioned below... so I still don't know why during run mode it won't indicate correct timing with HAL_RTC_GetTime, but turns out I can't use HSE anyways for my purpose... Thank you anyways!
2020-05-07 01:12 AM
Hi JW,
thanks for pointing this out, this was directly stated in a lot of places in the reference manual, I just didn't look carefully. I think I'll just have to switch to an MCU with LSE instead ofHSE.
One thing that still bothers me though, is that even during run mode, the HSE clocked RTC didn't indicate correct timing with HAL_RTC_GetTime
Thank you
2020-05-07 03:32 AM
> I think I'll just have to switch to an MCU with LSE instead ofHSE.
Or don't use the stop mode, if you can achieve the target consumption in a different way (e.g. running the system clock aggressively low, carefully optimizing individual peripherals' clocks etc.)
>One thing that still bothers me though, is that even during run mode,
>the HSE clocked RTC didn't indicate correct timing with HAL_RTC_GetTime
Are the RTC prescalers set correctly? Read out and check.
JW