stm8 闹钟设定时死机,关闭看门狗就不死机。最后发现库函数有bug。
在库函数stm8l15x_rtc.c中加入下面红色代码。其实原理很简单,等待寄存器设置完成的时候,超时了。。
ErrorStatus RTC_AlarmCmd(FunctionalState NewState)
{
__IO uint16_t alrawfcount = 0;
ErrorStatus status = ERROR;
uint8_t temp1 = 0;
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
/* Disable the write protection for RTC registers */
RTC_WriteProtectionCmd(DISABLE);
/* Configure the Alarm state */
if (NewState != DISABLE)
{ /*Enable the Alarm*/
RTC->CR2 |= (uint8_t)(RTC_CR2_ALRAE);
status = SUCCESS;
}
else
{ /* Disable the Alarm */
RTC->CR2 &= (uint8_t)~(RTC_CR2_ALRAE) ;
/* Wait until ALRxWF flag is set */
temp1 = (uint8_t)(RTC->ISR1 & RTC_ISR1_ALRAWF);
whil

在使用STM8进行闹钟设定时遇到死机问题,关闭看门狗后不再出现死机现象。经过排查,发现是库函数stm8l15x_rtc.c中的RTC_AlarmCmd函数存在bug。为解决此问题,需要在函数内部加入特定的代码片段,用于在等待寄存器设置完成时避免超时,从而避免系统死机。
最低0.47元/天 解锁文章
6112

被折叠的 条评论
为什么被折叠?



