求救,有谁用过STM32F0的RTC闹钟功能,始终无法进中断

2020-01-01 17:40发布

最近做一个项目用STM32F071的片子,调试RTC功能时发现设置闹钟功能后始终无法进中断,只要使能闹钟RTC_AlarmCmd(RTC_Alarm_A,ENABLE);就会直接跳到启动代码的B  .处,有没有人遇到过帮忙解答下,非常着急在线等
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
18条回答
落叶随风
2020-01-03 13:28
轻若尘 发表于 2016-8-17 15:40
另外我在调试的过程中发现STM32F0的固件库里有一处错误,和RTC相关的中断标志位宏定义有错,具体看下图 ...

固件库应该是对的吧

  1. /**
  2.   * @brief  Enables or disables the specified RTC interrupts.
  3.   * @param  RTC_IT: specifies the RTC interrupt sources to be enabled or disabled.
  4.   *          This parameter can be any combination of the following values:
  5.   *            @arg RTC_IT_TS:  Time Stamp interrupt mask
  6.   *            @arg RTC_IT_ALRA:  Alarm A interrupt mask
  7.   *            @arg RTC_IT_TAMP: Tamper event interrupt mask
  8.   * @param  NewState: new state of the specified RTC interrupts.
  9.   *          This parameter can be: ENABLE or DISABLE.
  10.   * @retval None
  11.   */
  12. void RTC_ITConfig(uint32_t RTC_IT, FunctionalState NewState)
  13. {
  14.   /* Check the parameters */
  15.   assert_param(IS_RTC_CONFIG_IT(RTC_IT));
  16.   assert_param(IS_FUNCTIONAL_STATE(NewState));

  17.   /* Disable the write protection for RTC registers */
  18.   RTC->WPR = 0xCA;
  19.   RTC->WPR = 0x53;

  20.   if (NewState != DISABLE)
  21.   {
  22.     /* Configure the Interrupts in the RTC_CR register */
  23.     RTC->CR |= (uint32_t)(RTC_IT & ~RTC_TAFCR_TAMPIE);
  24.     /* Configure the Tamper Interrupt in the RTC_TAFCR */
  25.     RTC->TAFCR |= (uint32_t)(RTC_IT & RTC_TAFCR_TAMPIE);
  26.   }
  27.   else
  28.   {
  29.     /* Configure the Interrupts in the RTC_CR register */
  30.     RTC->CR &= (uint32_t)~(RTC_IT & (uint32_t)~RTC_TAFCR_TAMPIE);
  31.     /* Configure the Tamper Interrupt in the RTC_TAFCR */
  32.     RTC->TAFCR &= (uint32_t)~(RTC_IT & RTC_TAFCR_TAMPIE);
  33.   }
  34.   /* Enable the write protection for RTC registers */
  35.   RTC->WPR = 0xFF;
  36. }
复制代码

固件库RTC_ITConfig写的是RTC_CR

RTC_CR.jpg (95.49 KB, 下载次数: 0)

下载附件

2016-8-18 14:42 上传



  1. /**
  2.   * @brief  Checks whether the specified RTC interrupt has occurred or not.
  3.   * @param  RTC_IT: specifies the RTC interrupt source to check.
  4.   *          This parameter can be one of the following values:
  5.   *            @arg RTC_IT_TS: Time Stamp interrupt
  6.   *            @arg RTC_IT_ALRA: Alarm A interrupt
  7.   *            @arg RTC_IT_TAMP1: Tamper1 event interrupt
  8.   *            @arg RTC_IT_TAMP2: Tamper2 event interrupt
  9.   * @retval The new state of RTC_IT (SET or RESET).
  10.   */
  11. ITStatus RTC_GetITStatus(uint32_t RTC_IT)
  12. {
  13.   ITStatus bitstatus = RESET;
  14.   uint32_t tmpreg = 0, enablestatus = 0;

  15.   /* Check the parameters */
  16.   assert_param(IS_RTC_GET_IT(RTC_IT));
  17.   
  18.   /* Get the TAMPER Interrupt enable bit and pending bit */
  19.   tmpreg = (uint32_t)(RTC->TAFCR & (RTC_TAFCR_TAMPIE));

  20.   /* Get the Interrupt enable Status */
  21.   enablestatus = (uint32_t)((RTC->CR & RTC_IT) | (tmpreg & ((RTC_IT >> (RTC_IT >> 18)) >> 15)));
  22.   
  23.   /* Get the Interrupt pending bit */
  24.   [color=Red]tmpreg = (uint32_t)((RTC->ISR & (uint32_t)(RTC_IT >> 4)));[/color]
  25.   
  26.   /* Get the status of the Interrupt */
  27.   if ((enablestatus != (uint32_t)RESET) && ((tmpreg & 0x0000FFFF) != (uint32_t)RESET))
  28.   {
  29.     bitstatus = SET;
  30.   }
  31.   else
  32.   {
  33.     bitstatus = RESET;
  34.   }
  35.   return bitstatus;
  36. }
复制代码

在RTC_GetITStatus中,读了RTC_ISR并与RTC_IT值右移4位相与

一周热门 更多>