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

2020-01-01 17:40发布

最近做一个项目用STM32F071的片子,调试RTC功能时发现设置闹钟功能后始终无法进中断,只要使能闹钟RTC_AlarmCmd(RTC_Alarm_A,ENABLE);就会直接跳到启动代码的B  .处,有没有人遇到过帮忙解答下,非常着急在线等
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
17条回答
轻若尘
1楼-- · 2020-01-02 20:45
落叶随风 发表于 2016-8-16 15:40
你开了RTC的一个中断了吧,跳进了默认的RTC的一个IRQHandler

我发现是初始化了EXTI_Line17就会出现这种情况,但是不初始化EXTI_Line17正常的闹钟还是进不去
落叶随风
2楼-- · 2020-01-02 23:10
EXTI line 17 is connected to the RTC Alarm event.

所以要自己写一下RTC_IRQHandler中对RTC_IT_ALRA中断的处理
Huge2014
3楼-- · 2020-01-03 04:40
下面是我在STM32F051中用的秒中断设置:
/**
  * @brief  This function configures the RTC Alarm.
  * @param  None
  * @retval None
  */
void RTC_AlarmConfig(void)
{
        EXTI_InitTypeDef EXTI_InitStructure;
        RTC_AlarmTypeDef RTC_AlarmStructure;
        NVIC_InitTypeDef NVIC_InitStructure;

//        RTC_AlarmStructInit(&RTC_AlarmStructure);
   
  /* EXTI configuration */
        EXTI_ClearITPendingBit(EXTI_Line17);
        EXTI_InitStructure.EXTI_Line = EXTI_Line17;
        EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
        EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
        EXTI_InitStructure.EXTI_LineCmd = ENABLE;
        EXTI_Init(&EXTI_InitStructure);
  
  /* Enable the RTC Alarm Interrupt */
        NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPriority = 1;
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);

  /* Set the alarmA Masks */
        RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_All;
        RTC_SetAlarm(RTC_Format_BCD, RTC_Alarm_A, &RTC_AlarmStructure);
  
  /* Set AlarmA subseconds and enable SubSec Alarm : generate 1 interripts per Second */
        RTC_AlarmSubSecondConfig(RTC_Alarm_A, 0xFF, RTC_AlarmSubSecondMask_SS14_8);

  /* Enable AlarmA interrupt */
        RTC_ITConfig(RTC_IT_ALRA, ENABLE);
  /* Enable the alarm  A */
        RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
}


这是秒中断
void RTC_IRQHandler(void)
{
        if(RTC_GetITStatus(RTC_IT_ALRA) != RESET)
        {
                RTC_TotalSeconds++;
                RTC_ClearITPendingBit(RTC_IT_ALRA);        /* Clear RTC AlarmA Flags */
        }
        EXTI_ClearITPendingBit(EXTI_Line17);        /* Clear the EXTIL line 17 */
}
轻若尘
4楼-- · 2020-01-03 05:24
 精彩回答 2  元偷偷看……
轻若尘
5楼-- · 2020-01-03 10:21
另外我在调试的过程中发现STM32F0的固件库里有一处错误,和RTC相关的中断标志位宏定义有错,具体看下图
落叶随风
6楼-- · 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位相与

一周热门 更多>