查看: 2712|回复: 0

STM32L432KC nucleo32 开发板RTC不能使用

[复制链接]
  • TA的每日心情
    开心
    2017-9-5 22:21
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]初来乍到

    发表于 2016-8-19 08:38:02 | 显示全部楼层 |阅读模式
    分享到:
    通过STM32CubeMX 生成RTC后发现RTC时钟没有运行
    rtc.h的内容如下
    RTC_HandleTypeDef hrtc;

    /* RTC init function */
    void MX_RTC_Init(void)
    {
      RTC_TimeTypeDef sTime;
      RTC_DateTypeDef sDate;
      RTC_AlarmTypeDef sAlarm;

        /**Initialize RTC and set the Time and Date
        */
      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();
      }

      sTime.Hours = 0x12;
      sTime.Minutes = 0x34;
      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_FRIDAY;
      sDate.Month = RTC_MONTH_AUGUST;
      sDate.Date = 0x19;
      sDate.Year = 0x16;

      if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)
      {
        Error_Handler();
      }

        /**Enable the Alarm A
        */
      sAlarm.AlarmTime.Hours = 0x12;
      sAlarm.AlarmTime.Minutes = 0x36;
      sAlarm.AlarmTime.Seconds = 0x0;
      sAlarm.AlarmTime.SubSeconds = 0x0;
      sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
      sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
      sAlarm.AlarmMask = RTC_ALARMMASK_NONE;
      sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
      sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
      sAlarm.AlarmDateWeekDay = 1;
      sAlarm.Alarm = RTC_ALARM_A;
      if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD) != HAL_OK)
      {
        Error_Handler();
      }

    }

    void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle)
    {

      if(rtcHandle->Instance==RTC)
      {
      /* USER CODE BEGIN RTC_MspInit 0 */

      /* USER CODE END RTC_MspInit 0 */
        /* Peripheral clock enable */
        __HAL_RCC_RTC_ENABLE();
      /* USER CODE BEGIN RTC_MspInit 1 */

      /* USER CODE END RTC_MspInit 1 */
      }
    }

    void HAL_RTC_MspDeInit(RTC_HandleTypeDef* rtcHandle)
    {

      if(rtcHandle->Instance==RTC)
      {
      /* USER CODE BEGIN RTC_MspDeInit 0 */

      /* USER CODE END RTC_MspDeInit 0 */
        /* Peripheral clock disable */
        __HAL_RCC_RTC_DISABLE();

        /* Peripheral interrupt Deinit*/
        HAL_NVIC_DisableIRQ(RTC_Alarm_IRQn);

      }
      /* USER CODE BEGIN RTC_MspDeInit 1 */

      /* USER CODE END RTC_MspDeInit 1 */
    }


    main.c 函数
    int main(void)
    {

      /* USER CODE BEGIN 1 */
       uint8_t i=0;
      /* USER CODE END 1 */

      /* MCU Configuration----------------------------------------------------------*/

      /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
      HAL_Init();

      /* Configure the system clock */
      SystemClock_Config();

      /* Initialize all configured peripherals */
      MX_GPIO_Init();
      MX_ADC1_Init();
      MX_USART1_UART_Init();
      MX_TIM1_Init();
      MX_RTC_Init();

      /* Initialize interrupts */
      MX_NVIC_Init();

    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条



    手机版|小黑屋|与非网

    GMT+8, 2024-11-25 06:35 , Processed in 0.115798 second(s), 15 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.