2019-01-11 12:55 PM
Dear,
I use SM32L152, I go to STOP mode regularly and as the possible source of waking up is either RTC or External interrupt. It works Fine until I change the System clocks from MSI 4 MHz to for example HSI on 16 MHz. If I change it, then MY MCU is woken up even if RTC alarm has not expire yet and no external interrupt happened.
I am really desperate. I will appreciate every advice.
Thank you very much, Jan.
2019-01-12 02:48 AM
How do you change he clock? Could it be that some other interrupt becomes enabled in the process?
2019-01-15 12:28 AM
To avoid misunderstanding: I change the clock only in CUBE_MX - not in running program.
But now it looks that it works. I dissabled LSI before reading from RTC calendar. I do not understand why it is needed because I have set BYPSHAD bit to1 - and I read the registers twice for getting correct values.
Th result is that if I have clock 2 or 4 MHz I do not have to dissable the LSI before reading reg form RTC. But for example if I change it to 16 MHz - then it does not work without the dissabling the LSI. It works as well when I dissable RTC before reading instead of LSI.
2019-01-17 01:04 AM
Hello,
To do a test-case, I need to know more information :
Best Regards,
Mohamed Aymen.
2019-01-17 02:13 AM
Hi,
I always run from internal oscilators. MSI (2 and 4 MHz) *** HSI or PLL for higher freq. I use STM32L152VBTxA.
Now I use MSI@4 MHz and it works even without RTC_Disable or LSI_Pause. But when I increase clocksto 16 MHz or higher so it does nt work reliably.
My reading from RTC looks like
HAL_RTC_GetTime( &RtcHandle, RTC_TimeStruct, RTC_FORMAT_BIN );
__HAL_RCC_RTC_DISABLE();
// __HAL_RCC_LSI_DISABLE();
do
{
firstRead = RTC_TimeStruct->SubSeconds;
HAL_RTC_GetDate( &RtcHandle, RTC_DateStruct, RTC_FORMAT_BIN );
HAL_RTC_GetTime( &RtcHandle, RTC_TimeStruct, RTC_FORMAT_BIN );
} while (firstRead != RTC_TimeStruct->SubSeconds);
// __HAL_RCC_LSI_ENABLE();
//while(( __HAL_RCC_GET_FLAG(RCC_FLAG_LSIRDY) == RESET));
__HAL_RCC_RTC_ENABLE();
Thanks, Jan.
2019-01-17 06:07 AM
Hello JAN,
If I understand correctly, you are unable to read the RTC registers ?
Best Regards,
Mohamed Aymen.
2019-01-17 08:34 AM
Hello Mohamed,
I have debugged it and have some findings:
1) I added HAL_RTC_GetDate() function after HAL_RTC_GetTime()
2) I have set the BYPSHAD bit to 1 and from Reference manual RM0038 section 20.3.6 I have the reading correct:
The software must read all the registers twice, and then
compare the results to confirm that the data is coherent and correct. Alternatively, the
software can just compare the two results of the least-significant calendar register.
3) When I debug it, it looks like I can read the time from RTC calendar correctly, BUT When I set up the WKUP alarm A to specific time for example now + 100 ms so the alarm A expire after 1/PRREDIV_S cycles.
4) When I add the mentioned __HAL_RCC_RTC_DISABLE() and Enable when I read the Time and Date - then the alarm A expire and wakeup exactly in right time (in my case after 100 ms).
That is all what I have discovered so far :smiling_face_with_smiling_eyes:
Thank you for any help.
Jan.
2019-01-17 08:41 AM
Hello JAN,
does that solve your problem ?
Best Regards,
Mohamed Aymen.
2019-01-17 11:16 PM
Hello,
basically yes, but I do not think that is the best way to solve it. There is probably any other problem and my solution is only crutch for it :)
Best Regards, Jan,