2024-07-26 10:45 PM
Hi ST Team,
Currently i am using STM32F105RBT6 in our project. In this project i am using microcontroller internal RTC module to monitor the time with LSE clock for RTC run. When the LSE crystal(32.768) is not mounted in our PCB then microcontroller stuck in SystemClock_Config() function & program control is not come in while loop.
We need a solution in which when LSE crystal is not mounted on PCB then controller shift its RTC clock to LSI & come in while loop to execute instruction.
Please help me to resolve this issue.
Thanks with Regards
Deepak
Embedded Enginner
2024-07-27 12:38 AM
- set RCC_BDCR.LSEON to enable LSE
- wait for RCC_BDCR.LSERDY to get being set, indicating that LSE is running; but for that wait use some sort of timeout - it can be a single loop counter, with number of counts selected so that it times out only after a reasonable LSE startup time (which can be up to 10 seconds)
- if timeout occured and RCC_BDCR.LSERDY is not set, it means, that the crystal is not mounted, so then you start LSI by setting RCC_CSR.LSION and waiting until RCC_CSR.LSIRDY is set
- only after that select RTC clock accordingly to whether LSE or LSI is running, in RCC_BDCR.RTCSEL, and then set up RTC itself
You have to be aware of the fact that LSI is very imprecise and not suitable for maintaining real-time.
If you have battery installed at VBAT, the procedure may be slightly different, with checking whether LSE already runs at the beginning.
JW