搜索
bottom↓
回复: 18

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

[复制链接]

出0入0汤圆

发表于 2016-8-16 10:55:03 | 显示全部楼层 |阅读模式
最近做一个项目用STM32F071的片子,调试RTC功能时发现设置闹钟功能后始终无法进中断,只要使能闹钟RTC_AlarmCmd(RTC_Alarm_A,ENABLE);就会直接跳到启动代码的B  .处,有没有人遇到过帮忙解答下,非常着急在线等

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

阿莫论坛20周年了!感谢大家的支持与爱护!!

月入3000的是反美的。收入3万是亲美的。收入30万是移民美国的。收入300万是取得绿卡后回国,教唆那些3000来反美的!

出0入0汤圆

 楼主| 发表于 2016-8-16 11:00:16 | 显示全部楼层
自己顶一下

出0入0汤圆

发表于 2016-8-16 11:06:40 | 显示全部楼层
使能前,关闹钟之类的中断标志试试?没用过,纯猜测

出0入0汤圆

 楼主| 发表于 2016-8-16 11:12:09 | 显示全部楼层
duxingkei 发表于 2016-8-16 11:06
使能前,关闹钟之类的中断标志试试?没用过,纯猜测

我试过关闹钟中断也没用,只要使能闹钟不开中断也死在B .这里

出0入0汤圆

 楼主| 发表于 2016-8-16 11:24:49 | 显示全部楼层
没人用STM32F0的片子吗?

出0入0汤圆

发表于 2016-8-16 12:59:26 | 显示全部楼层
信息太少,无法判断

出0入0汤圆

发表于 2016-8-16 15:40:09 | 显示全部楼层
你开了RTC的一个中断了吧,跳进了默认的RTC的一个IRQHandler

出0入0汤圆

 楼主| 发表于 2016-8-16 16:26:13 | 显示全部楼层
落叶随风 发表于 2016-8-16 15:40
你开了RTC的一个中断了吧,跳进了默认的RTC的一个IRQHandler

我发现是初始化了EXTI_Line17就会出现这种情况,但是不初始化EXTI_Line17正常的闹钟还是进不去

出0入0汤圆

发表于 2016-8-16 16:47:22 | 显示全部楼层
EXTI line 17 is connected to the RTC Alarm event.

所以要自己写一下RTC_IRQHandler中对RTC_IT_ALRA中断的处理

出0入0汤圆

发表于 2016-8-16 22:04:05 | 显示全部楼层
下面是我在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 */
}

出0入0汤圆

 楼主| 发表于 2016-8-17 15:32:00 | 显示全部楼层
Huge2014 发表于 2016-8-16 22:04
下面是我在STM32F051中用的秒中断设置:
/**
  * @brief  This function configures the RTC Alarm.

非常感谢,我的问题已经解决了,是因为中断服务函数名字写错了,写成了void RCC_IRQHandler(void),犯了这么幼稚的错误

出0入0汤圆

 楼主| 发表于 2016-8-17 15:40:28 | 显示全部楼层
另外我在调试的过程中发现STM32F0的固件库里有一处错误,和RTC相关的中断标志位宏定义有错,具体看下图

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

发表于 2016-8-18 14:45:09 | 显示全部楼层
轻若尘 发表于 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



  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位相与

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

发表于 2016-10-31 09:40:58 | 显示全部楼层
楼主你知道那个闹钟的设定时间是怎样计算?我RTC_AlarmMask没有所有屏蔽,只是屏蔽星期、时、分秒我没有屏蔽,但是中断的时间和我设定的不一样。

出0入0汤圆

 楼主| 发表于 2016-10-31 17:29:49 | 显示全部楼层
jaygeng 发表于 2016-10-31 09:40
楼主你知道那个闹钟的设定时间是怎样计算?我RTC_AlarmMask没有所有屏蔽,只是屏蔽星期、时、分秒我没有屏 ...

能说具体点吗?我直接调用的库函数初始化没有问题
RTC_AlarmCmd(RTC_Alarm_A,DISABLE);
RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);
RTC_AlarmCmd(RTC_Alarm_A,ENABLE);

出0入0汤圆

 楼主| 发表于 2016-10-31 17:34:53 | 显示全部楼层
落叶随风 发表于 2016-8-18 14:45
固件库应该是对的吧

非常感谢,是我理解有误

出0入0汤圆

发表于 2016-12-14 11:49:20 | 显示全部楼层
轻若尘 发表于 2016-10-31 17:29
能说具体点吗?我直接调用的库函数初始化没有问题
RTC_AlarmCmd(RTC_Alarm_A,DISABLE);
RTC_SetAlarm(RTC ...

谢谢楼主,是我忘记使能闹钟了

出0入0汤圆

发表于 2017-1-13 14:40:12 | 显示全部楼层
Huge2014 发表于 2016-8-16 22:04
下面是我在STM32F051中用的秒中断设置:
/**
  * @brief  This function configures the RTC Alarm.

我请教一下这个是怎么计算1s一个中断的??

/* Set AlarmA subseconds and enable SubSec Alarm : generate 1 interripts per Second */
RTC_AlarmSubSecondConfig(RTC_Alarm_A, 0xFF, RTC_AlarmSubSecondMask_SS14_8);

出0入0汤圆

发表于 2020-3-22 10:13:32 | 显示全部楼层
Huge2014 发表于 2016-8-16 22:04
下面是我在STM32F051中用的秒中断设置:
/**
  * @brief  This function configures the RTC Alarm.

请问楼上,我也是在用F051,但是按照你这个RTC配置怎么也进不来中断
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-4-26 08:15

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表