stm8 鬧鐘設定時死機

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);
    while ((alrawfcount != ALRAWF_TIMEOUT) && (temp1 == RESET))
    {                    //ALRAWF_TIMEOUT     ((uint16_t)0xFFFF)
      temp1 = (uint8_t)(RTC->ISR1 & RTC_ISR1_ALRAWF);   //加入這一段。
      alrawfcount++;
    }

    if ((RTC->ISR1 &  RTC_ISR1_ALRAWF) == RESET)
    {
      status = ERROR;
    }
    else
    {
      status = SUCCESS;
    }
  }

  /* Enable the write protection for RTC registers */
  RTC_WriteProtectionCmd(ENABLE);

  /* Return the status*/
  return (ErrorStatus)status;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章