初级会员
- 积分
- 148
- 金钱
- 148
- 注册时间
- 2017-9-18
- 在线时间
- 40 小时
|
3金钱
各位大牛,我又来叨扰各位了。最近在调试RTC。但是STM32的RTC有四个中断,我有点分不清。
原话是这样的: All RTC events(Alarm,wakeup,TimesTamp or Tamper)can generate an interrupt and wakeup the device from the low-power modes.
我想产生一个秒中断,根据描述,应该是配置一个 TimesTamp的时间戳中断。于是找到了例程。
static void RTC_TimeStampConfig(void)
{
RTC_DateTypeDef sdatestructure;
RTC_TimeTypeDef stimestructure;
/*##-1- Configure the Time Stamp peripheral ################################*/
/* RTC TimeStamp generation: TimeStamp Rising Edge on PC.13 Pin */
HAL_RTCEx_SetTimeStamp_IT(&RtcHandle, RTC_TIMESTAMPEDGE_RISING, RTC_TIMESTAMPPIN_DEFAULT);
/*##-2- Configure the Date #################################################*/
/* Set Date: Monday April 14th 2014 */
sdatestructure.Year = 0x14;
sdatestructure.Month = RTC_MONTH_APRIL;
sdatestructure.Date = 0x14;
sdatestructure.WeekDay = RTC_WEEKDAY_MONDAY;
if(HAL_RTC_SetDate(&RtcHandle,&sdatestructure,RTC_FORMAT_BCD) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-3- Configure the Time #################################################*/
/* Set Time: 08:10:00 */
stimestructure.Hours = 0x08;
stimestructure.Minutes = 0x10;
stimestructure.Seconds = 0x00;
stimestructure.SubSeconds = 0x00;
stimestructure.TimeFormat = RTC_HOURFORMAT12_AM;
stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ;
stimestructure.StoreOperation = RTC_STOREOPERATION_RESET;
if(HAL_RTC_SetTime(&RtcHandle,&stimestructure,RTC_FORMAT_BCD) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
}
以上是例程给的代码。
-----------------------------------------------------------------------------------------------分割线--------------------------------------------------------------------------------------------------------------------------------
RTC_HandleTypeDef hrtc;
/* RTC init function */
static void MX_RTC_Init(void)
{
RTC_DateTypeDef sdatestructure;
RTC_TimeTypeDef stimestructure;
HAL_RTCEx_SetTimeStamp_IT(&hrtc, RTC_TIMESTAMPEDGE_RISING, RTC_TIMESTAMPPIN_DEFAULT);
sdatestructure.Year = 0x14;
sdatestructure.Month = RTC_MONTH_APRIL;
sdatestructure.Date = 0x14;
sdatestructure.WeekDay = RTC_WEEKDAY_MONDAY;
if(HAL_RTC_SetDate(&hrtc,&sdatestructure,RTC_FORMAT_BCD) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
stimestructure.Hours = 0x08;
stimestructure.Minutes = 0x10;
stimestructure.Seconds = 0x00;
stimestructure.SubSeconds = 0x00;
stimestructure.TimeFormat = RTC_HOURFORMAT12_AM;
stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ;
stimestructure.StoreOperation = RTC_STOREOPERATION_RESET;
/**Initialize RTC Only
*/
if(HAL_RTC_SetTime(&hrtc,&stimestructure,RTC_FORMAT_BCD) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
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(__FILE__, __LINE__);
}
//TAMP_STAMP_IRQHandler
HAL_NVIC_SetPriority(TAMP_STAMP_IRQn, 0, 0);
NVIC_EnableIRQ(TAMP_STAMP_IRQn);
}
我结合cubemx生成的代码,添加在我的工程,但是rtc的中断进不去。
-----------------------------------------------------------------------------------------------------------分割线----------------------------------------------------------------------------------------------------------------------
void TAMP_STAMP_IRQHandler(void)
{
HAL_RTCEx_TamperTimeStampIRQHandler(&RtcHandle);
}
用的都是hal库,现在有点迷茫,倒是哪里出了问题。
还有就是,是不是cubemx生成的工程,中断都要自己配置?不然都是进不去的
HAL_NVIC_SetPriority(TAMP_STAMP_IRQn, 0, 0);
NVIC_EnableIRQ(TAMP_STAMP_IRQn);
类似这样的中断配置语句。
|
-
RTC中断
|