cancel
Showing results for 
Search instead for 
Did you mean: 

RTC doesn't work with HSE but works with LSE and LSI

JLee.161
Associate III

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!

1 ACCEPTED SOLUTION

Accepted Solutions

HSE works in stop mode?

JW

View solution in original post

7 REPLIES 7
berendi
Principal

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.

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

HSE works in stop mode?

JW

Yes, RTC clock source is selected in the RCC, not in the RTC. Check the RCC->CR and RCC->CSR registers.

Hi, I checked the registers in debugging mode and found that

  • RCC_CR HSE_ON was set, indicating that HSE is on
  • RCC_CSR RTCSEL was set to 0x03, indicating that HSE w/ prescaler was set as the clock source for the RTC

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!

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

> 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