RTC

设置RTC闹钟,无法进入中断

初始化代码是工具自动生成的,请大神帮忙看一下是哪里出了问题。

static void MX_RTC_Init(void)

{


  /* USER CODE BEGIN RTC_Init 0 */


  /* USER CODE END RTC_Init 0 */


  RTC_TimeTypeDef sTime = {0};

  RTC_DateTypeDef sDate = {0};

  RTC_AlarmTypeDef sAlarm = {0};


  /* USER CODE BEGIN RTC_Init 1 */


  /* USER CODE END RTC_Init 1 */

  /**Initialize RTC Only 

  */

  hrtc.Instance = RTC;

  hrtc.Init.HourFormat = RTC_HOURFORMAT_24;

  hrtc.Init.AsynchPrediv = 127;

  hrtc.Init.SynchPrediv = 255;

  hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;

  hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;

  hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;

  hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;

  if (HAL_RTC_Init(&hrtc) != HAL_OK)

  {

    Error_Handler();

  }


  /* USER CODE BEGIN Check_RTC_BKUP */

    

  /* USER CODE END Check_RTC_BKUP */


  /**Initialize RTC and set the Time and Date 

  */

  sTime.Hours = 0x0;

  sTime.Minutes = 0x0;

  sTime.Seconds = 0x0;

  sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;

  sTime.StoreOperation = RTC_STOREOPERATION_RESET;

  if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)

  {

    Error_Handler();

  }

  sDate.WeekDay = RTC_WEEKDAY_TUESDAY;

  sDate.Month = RTC_MONTH_JANUARY;

  sDate.Date = 0x1;

  sDate.Year = 0x19;


  if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)

  {

    Error_Handler();

  }

  /**Enable the Alarm A 

  */

  sAlarm.AlarmTime.Hours = 0x0;

  sAlarm.AlarmTime.Minutes = 0x0;

  sAlarm.AlarmTime.Seconds = 0x10;

  sAlarm.AlarmTime.SubSeconds = 0x0;

  sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;

  sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;

  sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY|RTC_ALARMMASK_HOURS

                              |RTC_ALARMMASK_MINUTES;

  sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE;

  sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;

  sAlarm.AlarmDateWeekDay = 0x1;

  sAlarm.Alarm = RTC_ALARM_A;

  if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD) != HAL_OK)

  {

    Error_Handler();

  }

  /* USER CODE BEGIN RTC_Init 2 */

    HAL_NVIC_SetPriority(RTC_IRQn, 0, 0);

    HAL_NVIC_EnableIRQ(RTC_IRQn);

  /* USER CODE END RTC_Init 2 */


}


已邀请:

joytomato

赞同来自:

之前已经实现RTC闹钟的功能了,之前用的是STM32F103,这次用的是STML011F4U6,cube的界面就差别很大,代码不能完全复用,结果竟然无法中断,不知道是哪个细节遗漏了。

joytomato

赞同来自:

有没有大神帮忙解答下

joytomato

赞同来自:

我通过HAL_RTC_GetTime来获取时间,发现没有变化,也就是说时钟没走,所以闹钟不会中断,继续找问题。

joytomato

赞同来自:

浪费了我两天时间,太坑了,竟然是时钟问题。

ytmxuexi2012 - 一句话介绍

赞同来自:

亲,可以说的详细点吗?或者把工程发一下,谢谢

要回复问题请先登录注册