打印

STM32 RTC 的AlARM 中断问题

[复制链接]
7108|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
dfsa|  楼主 | 2010-10-11 22:49 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
不能进入STM32 RTC 的AlARM 中断服务程序,请求帮忙,不知道问题出在哪里?
        中断配置如下:void NVIC_Configuration(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;
  /* Configure the NVIC Preemption Priority Bits */  
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
  /* Enable the RTC Interrupt*/
  NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQChannel;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
    /* Enable the RTCAlarm Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQChannel;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);  
}
RTC配置中有:/* Wait for RTC registers synchronization */
  RTC_WaitForSynchro();
  /* Wait until last write operation on RTC registers has finished */
  RTC_WaitForLastTask();
  
  /* Enable the RTC Alarm */  
   RTC_ITConfig(RTC_IT_SEC, ENABLE);
    RTC_WaitForLastTask();
RTC_SetAlarm(RTC_GetCounter()+ 5);  
    RTC_WaitForLastTask();
    RTC_ITConfig(RTC_IT_ALR, ENABLE);
  /* Wait until last write operation on RTC registers has finished */
  RTC_WaitForLastTask();
中断服务程序:
void RTC_IRQHandler(void)
{
    if(RTC_GetITStatus(RTC_IT_SEC) != RESET)
  {
   //GPIO_ResetBits(GPIOB, GPIO_Pin_8);
    RTC_ClearITPendingBit(RTC_IT_SEC);     //首先必须清中断,否则一直响应中断
SecStatus = OneSec;         //设置标志位,表示现在达到一秒
    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
  }
  if(RTC_GetITStatus(RTC_IT_ALR) != RESET)
  {
    GPIO_SetBits(GPIOB, GPIO_Pin_9);  
    RTC_ClearITPendingBit(RTC_IT_ALR);     //首先必须清中断,否则一直响应中断
SecStatus = OneSec;         //设置标志位,表示现在达到一秒
  /*Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
    /* Set the RTC Alarm after 5s */
    RTC_SetAlarm(RTC_GetCounter()+ 5);
    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
   }
    /* Reset RTC Counter when Time is 23:59:59 */
    if(RTC_GetCounter() == 0x00015180)     //15180即为24小时的秒计数
    {
      RTC_SetCounter(0x0);
      /* Wait until last write operation on RTC registers has finished */
      RTC_WaitForLastTask();
    }
  }
在线仿真,进不去闹铃中断标志的服务程序,就算写在void RTCAlarm_IRQHandler (void) 里面也没有用,
到底是怎么回事呢?手册上说RTC_ALARM 是和EXTI_LINE17级联的,难道是配置的问题么?
沙发
bili| | 2010-10-13 11:20 | 只看该作者
既然都知道是级联的那你还不对EXTI17进行配置吗?
那就像两个开关串联,任何一个不配置使能都不能进入中断。

使用特权

评论回复
板凳
戴风海| | 2016-3-18 20:06 | 只看该作者
12小时的是多少

使用特权

评论回复
地板
风中的狙击手| | 2016-3-21 23:16 | 只看该作者
这样的老帖也能被楼上的给翻出来了;P 那我就简单地提下楼主的问题吧:是NVIC配置的问题,你把中断配置成了NVIC_PriorityGroup_0,(有0位抢占优先级,4位子优先级),但是你却给你的闹钟中断配置了抢占优先级为2,子优先级为1

使用特权

评论回复
5
598330983| | 2016-3-22 11:33 | 只看该作者
#ifndef __RTC_Alarm_H
#define __RTC_Alarm_H

//外部提供接口
#include "main.h"

//宏定义,单位s,0-4294967295s(71582788.25min)
//运行时间
#define WORK_TIMES 2
//待机时间
#define STANDBY_TIMES 2

extern void RTC_Alarm_Configuration(void);

#endif

-----------------------------------------------------------------------
#include "RTC_Alarm.h"

//RTC中断配置
static void RTC_NVIC_Config(void)
{   
    NVIC_InitTypeDef NVIC_InitStructure;

    NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQChannel;        //RTC全局中断
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;    //先占优先级1位,从优先级3位
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;   
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;        //使能该通道中断
    NVIC_Init(&NVIC_InitStructure);        //根据NVIC_InitStruct中指定的参数初始化外设NVIC寄存器
}

//RTC闹钟初始化:启动时钟、配置LSI做RTC时钟、设置预分频40000得到1Hz
//设置运行时间WORK_TIMES
void RTC_Alarm_Configuration(void)
{
        /* Enable PWR and BKP clocks */
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
        /* Allow access to BKP Domain */
        PWR_BackupAccessCmd(ENABLE);       
        /* Reset Backup Domain */
        BKP_DeInit();

    /* RTC clock source configuration ----------------------------------------*/
        /* Enable the LSI OSC */
          RCC_LSICmd(ENABLE);
    /* Wait till LSI is ready */
    while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
    {
    }
    /* Select the RTC Clock Source */
    RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
    /* Enable the RTC Clock */
    RCC_RTCCLKCmd(ENABLE);
        /* Wait for RTC registers synchronization */
        RTC_WaitForSynchro();
        /* Wait until last write operation on RTC registers has finished */
        RTC_WaitForLastTask();
        /* 使能RTC闹钟中断*/
        RTC_ITConfig(RTC_IT_ALR, ENABLE);       
        /* Wait until last write operation on RTC registers has finished */
        RTC_WaitForLastTask();       
        /* Set RTC prescaler: set RTC period to 1sec */
        RTC_SetPrescaler(40000);       
        /* Wait until last write operation on RTC registers has finished */
        RTC_WaitForLastTask();
               
        //中断配置
        RTC_NVIC_Config();

        //设置运行WORK_TIMES
        RTC_SetAlarm(RTC_GetCounter() + WORK_TIMES);
        RTC_WaitForLastTask();
}

//设置闹钟时长并进入待机
//s为中断秒数
void RTC_Enter_StandbyMode(u32 s)
{

    RTC_SetAlarm(RTC_GetCounter() + s);
    RTC_WaitForLastTask();
    // 进入待机模式, 此时所有1.8V域的时钟都关闭,HIS和HSE的振荡器关闭, 电压调节器关闭.
    // 只有WKUP引脚上升沿,RTC警告事件,NRST引脚的外部复位,IWDG复位.
        /* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */
    PWR_EnterSTANDBYMode();
}

//中断服务函数
void RTC_IRQHandler(void)
{
if(RTC_GetITStatus(RTC_IT_ALR)!= RESET)//闹钟中断
{
          RTC_ClearITPendingBit(RTC_IT_ALR);  //清闹钟中断

        RTC_Enter_StandbyMode(STANDBY_TIMES);//进入待机
}                 
}



使用特权

评论回复
6
xiaoyu19| | 2016-6-16 14:32 | 只看该作者
598330983 发表于 2016-3-22 11:33
#ifndef __RTC_Alarm_H
#define __RTC_Alarm_H

能问下你,那个stm32是怎么进行闹钟中断的?怎么设置它的counter值和Alarm值

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

282

主题

2404

帖子

2

粉丝