本文整理汇总了C++中HAL_RTC_SetDate函数的典型用法代码示例。如果您正苦于以下问题:C++ HAL_RTC_SetDate函数的具体用法?C++ HAL_RTC_SetDate怎么用?C++ HAL_RTC_SetDate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HAL_RTC_SetDate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MX_RTC_BACKUP_Init
void MX_RTC_BACKUP_Init(void){
RTC_TimeTypeDef sTime;
RTC_DateTypeDef sDate;
if(HAL_RTCEx_BKUPRead(&hrtc,RTC_BKP_DR1) != TSTWORD){
HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR1, TSTWORD);
sTime.Hours = 22;
sTime.Minutes = 02;
sTime.Seconds = 00;
sTime.
HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN);
sDate.WeekDay = RTC_WEEKDAY_FRIDAY;
sDate.Month = RTC_MONTH_APRIL;
sDate.Date = 23;
sDate.Year = 16;
HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN);
HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR2,sDate.Month);
HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR3,sDate.Date);
HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR4,sDate.Year);
} else {
sDate.Month = HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR2);
sDate.Date = HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR3);
sDate.Year = HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR4);
HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN);
}
}
示例2: RTC_TimeStampConfig
/**
* @brief Configures the current time and date.
* @param None
* @retval None
*/
static void RTC_TimeStampConfig(void)
{
RTC_DateTypeDef sdatestructure;
RTC_TimeTypeDef stimestructure;
/*##-3- Configure the Date #################################################*/
/* Set Date: Tuesday February 18th 2014 */
sdatestructure.Year = 0x14;
sdatestructure.Month = RTC_MONTH_FEBRUARY;
sdatestructure.Date = 0x18;
sdatestructure.WeekDay = RTC_WEEKDAY_TUESDAY;
if(HAL_RTC_SetDate(&RtcHandle,&sdatestructure,FORMAT_BCD) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-4- Configure the Time #################################################*/
/* Set Time: 08:10:00 */
stimestructure.Hours = 0x08;
stimestructure.Minutes = 0x10;
stimestructure.Seconds = 0x00;
stimestructure.TimeFormat = RTC_HOURFORMAT12_AM;
stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ;
stimestructure.StoreOperation = RTC_STOREOPERATION_RESET;
if(HAL_RTC_SetTime(&RtcHandle,&stimestructure,FORMAT_BCD) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
}
示例3: BSP_RTC_Init
/**
* @brief RTC Initialization function
*/
void BSP_RTC_Init(void)
{
RTC_TimeTypeDef sTime;
RTC_DateTypeDef sDate;
/**Initialize RTC and set the Time and Date
*/
hrtc_bsp.Instance = RTC;
hrtc_bsp.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc_bsp.Init.AsynchPrediv = 127; //LSI clock AsyncPrediv 127 HSE clock AsyncPrediv 124
hrtc_bsp.Init.SynchPrediv = 255; //LSI clock SyncPrediv 255 HSE clock SyncPrediv 7999
hrtc_bsp.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc_bsp.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc_bsp.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
BSP_RTC_MspInit(&hrtc_bsp);
HAL_RTC_Init(&hrtc_bsp);
sTime.Hours = 0;
sTime.Minutes = 0;
sTime.Seconds = 0;
sTime.SubSeconds = 0;
sTime.TimeFormat = RTC_HOURFORMAT12_AM;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
HAL_RTC_SetTime(&hrtc_bsp, &sTime, FORMAT_BIN);
sDate.WeekDay = RTC_WEEKDAY_MONDAY;
sDate.Month = RTC_MONTH_JANUARY;
sDate.Date = 1;
sDate.Year = 00;
HAL_RTC_SetDate(&hrtc_bsp, &sDate, FORMAT_BIN);
}
示例4: rtc_write
void rtc_write(time_t t) {
RTC_DateTypeDef dateStruct;
RTC_TimeTypeDef timeStruct;
RtcHandle.Instance = RTC;
// Convert the time into a tm
struct tm *timeinfo = localtime(&t);
// Fill RTC structures
dateStruct.WeekDay = timeinfo->tm_wday;
dateStruct.Month = timeinfo->tm_mon + 1;
dateStruct.Date = timeinfo->tm_mday;
dateStruct.Year = timeinfo->tm_year - 100;
timeStruct.Hours = timeinfo->tm_hour;
timeStruct.Minutes = timeinfo->tm_min;
timeStruct.Seconds = timeinfo->tm_sec;
timeStruct.TimeFormat = RTC_HOURFORMAT12_PM;
timeStruct.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
timeStruct.StoreOperation = RTC_STOREOPERATION_RESET;
// Change the RTC current date/time
HAL_RTC_SetDate(&RtcHandle, &dateStruct, FORMAT_BIN);
HAL_RTC_SetTime(&RtcHandle, &timeStruct, FORMAT_BIN);
}
示例5: MX_RTC_Init
/* RTC init function */
void MX_RTC_Init(void)
{
RTC_TimeTypeDef sTime;
RTC_DateTypeDef DateToUpdate;
/**Initialize RTC and set the Time and Date
*/
hrtc.Instance = RTC;
hrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
hrtc.Init.OutPut = RTC_OUTPUTSOURCE_NONE;
HAL_RTC_Init(&hrtc);
sTime.Hours = 0x10;
sTime.Minutes = 0x6;
sTime.Seconds = 0x24;
HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD);
DateToUpdate.WeekDay = RTC_WEEKDAY_MONDAY;
DateToUpdate.Month = RTC_MONTH_AUGUST;
DateToUpdate.Date = 0x15;
DateToUpdate.Year = 0x16;
HAL_RTC_SetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BCD);
}
示例6: RTC_CalendarConfig
/**
* @brief Configure the current time and date.
* @param None
* @retval None
*/
static void RTC_CalendarConfig(void)
{
RTC_DateTypeDef sdatestructure;
RTC_TimeTypeDef stimestructure;
/*##-1- Configure the Date #################################################*/
/* Set Date: Tuesday April 14th 2015 */
sdatestructure.Year = 0x14;
sdatestructure.Month = RTC_MONTH_JANUARY;
sdatestructure.Date = 0x01;
sdatestructure.WeekDay = RTC_WEEKDAY_TUESDAY;
if(HAL_RTC_SetDate(&RTCHandle,&sdatestructure,RTC_FORMAT_BCD) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-2- Configure the Time #################################################*/
/* Set Time: 02:00:00 */
stimestructure.Hours = 0x00;
stimestructure.Minutes = 0x00;
stimestructure.Seconds = 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();
}
}
示例7: Clocks_Init
void Clocks_Init(void)
{
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
//TODO: на реальном приборе кварц не 8 а 25 ћ√ц. исправить делитель
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_HSE_DIV8; // RTCCLK = 1MHz
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
__HAL_RCC_RTC_ENABLE();
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 124;
hrtc.Init.SynchPrediv = 7999;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
HAL_RTC_Init(&hrtc);
sTime.Hours = 1;
sTime.Minutes = 1;
sTime.Seconds = 1;
sTime.SubSeconds = 0;
sTime.TimeFormat = RTC_HOURFORMAT_24;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
HAL_RTC_SetTime(&hrtc, &sTime, FORMAT_BCD);
sDate.WeekDay = RTC_WEEKDAY_MONDAY;
sDate.Month = RTC_MONTH_JANUARY;
sDate.Date = 1;
sDate.Year = 0;
HAL_RTC_SetDate(&hrtc, &sDate, FORMAT_BCD);
}
示例8: RTC_CalendarConfig
STATIC void RTC_CalendarConfig(void) {
// set the date to 1st Jan 2015
RTC_DateTypeDef date;
date.Year = 15;
date.Month = 1;
date.Date = 1;
date.WeekDay = RTC_WEEKDAY_THURSDAY;
if(HAL_RTC_SetDate(&RTCHandle, &date, FORMAT_BIN) != HAL_OK) {
// init error
return;
}
// set the time to 00:00:00
RTC_TimeTypeDef time;
time.Hours = 0;
time.Minutes = 0;
time.Seconds = 0;
time.TimeFormat = RTC_HOURFORMAT12_AM;
time.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
time.StoreOperation = RTC_STOREOPERATION_RESET;
if (HAL_RTC_SetTime(&RTCHandle, &time, FORMAT_BIN) != HAL_OK) {
// init error
return;
}
}
示例9: MX_RTC_Init
/* 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.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
HAL_RTC_Init(&hrtc);
sTime.Hours = 0;
sTime.Minutes = 0;
sTime.Seconds = 0;
sTime.SubSeconds = 0;
sTime.TimeFormat = RTC_HOURFORMAT12_AM;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
HAL_RTC_SetTime(&hrtc, &sTime, FORMAT_BIN);
sDate.WeekDay = RTC_WEEKDAY_MONDAY;
sDate.Month = RTC_MONTH_JANUARY;
sDate.Date = 1;
sDate.Year = 0;
HAL_RTC_SetDate(&hrtc, &sDate, FORMAT_BIN);
/**Enable the Alarm A
*/
sAlarm.AlarmTime.Hours = 0;
sAlarm.AlarmTime.Minutes = 0;
sAlarm.AlarmTime.Seconds = 0;
sAlarm.AlarmTime.SubSeconds = 0;
sAlarm.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM;
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;
HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, FORMAT_BIN);
/**Enable the Alarm B
*/
sAlarm.Alarm = RTC_ALARM_B;
HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, FORMAT_BIN);
/**Enable the WakeUp
*/
HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 196, RTC_WAKEUPCLOCK_RTCCLK_DIV2);
}
示例10: RTC_TimeStampConfig
/**
* @brief Configures the current time and date.
* @param None
* @retval None
*/
static void RTC_TimeStampConfig(void)
{
RTC_DateTypeDef sdatestructure;
RTC_TimeTypeDef stimestructure;
RTC_TamperTypeDef stamperstructure;
/*##-1- Configure the Tamper ###############################################*/
/* Configure Tamper registers */
/* RTC Tamper configured as follow:
- Pamper = Tamper1
- Pin selection = PC13
- Trigger = Falling Edge
- TimeStamp On Tamper Detection = Enable */
stamperstructure.Filter = RTC_TAMPERFILTER_DISABLE;
stamperstructure.Tamper = RTC_TAMPER_1;
stamperstructure.PinSelection = RTC_TAMPERPIN_PC13;
stamperstructure.Trigger = RTC_TAMPERTRIGGER_FALLINGEDGE;
stamperstructure.SamplingFrequency = RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV4096;
stamperstructure.PrechargeDuration = RTC_TAMPERPRECHARGEDURATION_1RTCCLK;
stamperstructure.TamperPullUp = RTC_TAMPER_PULLUP_DISABLE;
stamperstructure.TimeStampOnTamperDetection = RTC_TIMESTAMPONTAMPERDETECTION_ENABLE;
HAL_RTCEx_SetTamper(&RtcHandle, &stamperstructure);
/*##-2- Configure the Time Stamp peripheral ################################*/
/* RTC TimeStamp flag Generation: TimeStamp Rising Edge on PC13 Pin */
HAL_RTCEx_SetTimeStamp_IT(&RtcHandle, RTC_TIMESTAMPEDGE_RISING, RTC_TIMESTAMPPIN_PC13);
/* Clear the TIMESTAMP interrupt pending bit */
__HAL_RTC_TIMESTAMP_CLEAR_FLAG(&RtcHandle,RTC_FLAG_TSF);
/*##-3- Configure the Date #################################################*/
/* Set Date: Tuesday February 18th 2014 */
sdatestructure.Year = 0x14;
sdatestructure.Month = RTC_MONTH_FEBRUARY;
sdatestructure.Date = 0x18;
sdatestructure.WeekDay = RTC_WEEKDAY_TUESDAY;
if(HAL_RTC_SetDate(&RtcHandle,&sdatestructure,RTC_FORMAT_BCD) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-4- Configure the Time #################################################*/
/* Set Time: 08:10:00 */
stimestructure.Hours = 0x08;
stimestructure.Minutes = 0x10;
stimestructure.Seconds = 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();
}
}
示例11: MX_RTC_Init
/* 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.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
HAL_RTC_Init(&hrtc);
/* USER CODE BEGIN*/
rtc_backup_init();
if(rtc_check()==0)
{
sTime.Hours = 16;
sTime.Minutes = 52;
sTime.Seconds = 50;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
HAL_RTC_SetTime(&hrtc, &sTime, FORMAT_BIN);
sDate.WeekDay = RTC_WEEKDAY_WEDNESDAY;
sDate.Month = RTC_MONTH_APRIL;
sDate.Date = 20;
sDate.Year = 16;
HAL_RTC_SetDate(&hrtc, &sDate, FORMAT_BIN);
/**Enable the Alarm A
*/
sAlarm.AlarmTime.Hours = 16;
sAlarm.AlarmTime.Minutes = 53;
sAlarm.AlarmTime.Seconds = 1;
sAlarm.AlarmTime.SubSeconds = 0;
sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY;
sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
sAlarm.AlarmDateWeekDay = 1;
sAlarm.Alarm = RTC_ALARM_A;
HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, FORMAT_BIN);
}
/* USER CODE END*/
/**Enable the WakeUp
*/
HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 10240, RTC_WAKEUPCLOCK_RTCCLK_DIV16);
}
示例12: RTC_Set_datetime
//------------------------------------------------------------------
void RTC_Set_datetime(uint8_t * data)
{
uint8_t temp[3];
RTC_DateTypeDef sdatestructure;
RTC_TimeTypeDef stimestructure;
if(data!=NULL)
{
osMutexWait(rtc_mutex, osWaitForever);
sdatestructure.Year =data[0];
sdatestructure.Month = data[1];
sdatestructure.Date = data[2];
sdatestructure.WeekDay= CaculateWeekDay(data[0],data[1],data[2]);
if(HAL_RTC_SetDate(&hrtc,&sdatestructure,RTC_FORMAT_BIN) != HAL_OK)
{
/* Initialization Error */
Error_Handler("set time error");
}
stimestructure.Hours = data[3];
stimestructure.Minutes = data[4];
stimestructure.Seconds = data[5];
stimestructure.TimeFormat = RTC_HOURFORMAT12_AM;
stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
stimestructure.StoreOperation = RTC_STOREOPERATION_RESET;
if(HAL_RTC_SetTime(&hrtc,&stimestructure,RTC_FORMAT_BIN) != HAL_OK)
{
/* Initialization Error */
Error_Handler("set date error");
}
#if 0
//flash lcd
HAL_RTC_GetTime(&hrtc, &stimestructure, RTC_FORMAT_BIN);
temp[0]=stimestructure.Hours;
temp[1]=stimestructure.Minutes;
temp[2]=stimestructure.Seconds;
memcpy(¤t_datetime[3],temp,3);
/* Get the RTC current Date */
HAL_RTC_GetDate(&hrtc, &sdatestructure, RTC_FORMAT_BIN);
data[0]=sdatestructure.Year;
data[1]=sdatestructure.Month;
data[2]=sdatestructure.Date;
current_datetime[6]=sdatestructure.WeekDay;
memcpy(¤t_datetime[0],data,3);
#endif
if(disp_sort==0)
send_message(4);
osMutexRelease(rtc_mutex);
}//data=null
}
示例13: RTC_AlarmConfig
/**
* @brief Configure the current time and date.
* @param None
* @retval None
*/
static void RTC_AlarmConfig(void)
{
RTC_DateTypeDef sdatestructure;
RTC_TimeTypeDef stimestructure;
RTC_AlarmTypeDef salarmstructure;
/*##-1- Configure the Date #################################################*/
/* Set Date: Tuesday February 18th 2014 */
sdatestructure.Year = 0x14;
sdatestructure.Month = RTC_MONTH_FEBRUARY;
sdatestructure.Date = 0x18;
sdatestructure.WeekDay = RTC_WEEKDAY_TUESDAY;
if(HAL_RTC_SetDate(&RtcHandle,&sdatestructure,RTC_FORMAT_BCD) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
/*##-2- Configure the Time #################################################*/
/* Set Time: 02:20:00 */
stimestructure.Hours = 0x02;
stimestructure.Minutes = 0x20;
stimestructure.Seconds = 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();
}
/*##-3- Configure the RTC Alarm peripheral #################################*/
/* Set Alarm to 02:20:30
RTC Alarm Generation: Alarm on Hours, Minutes and Seconds */
salarmstructure.Alarm = RTC_ALARM_A;
salarmstructure.AlarmDateWeekDay = RTC_WEEKDAY_MONDAY;
salarmstructure.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
salarmstructure.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY;
salarmstructure.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_NONE;
salarmstructure.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM;
salarmstructure.AlarmTime.Hours = 0x02;
salarmstructure.AlarmTime.Minutes = 0x20;
salarmstructure.AlarmTime.Seconds = 0x30;
salarmstructure.AlarmTime.SubSeconds = 0x56;
if(HAL_RTC_SetAlarm_IT(&RtcHandle,&salarmstructure,RTC_FORMAT_BCD) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
}
示例14: RtcSetConfig
static void RtcSetConfig( void )
{
RTC_TimeTypeDef RTC_TimeStruct;
RTC_DateTypeDef RTC_DateStruct;
//RTC_AlarmTypeDef salarmstructure;
/* Enable Ultra low power mode */
HAL_PWREx_EnableUltraLowPower();
/* Enable the fast wake up from Ultra low power mode */
HAL_PWREx_EnableFastWakeUp();
/* Select HSI as system clock source after Wake Up from Stop mode */
__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_StopWakeUpClock_HSI);
/*##-1- Configure the RTC peripheral #######################################*/
/* Configure RTC prescaler and RTC data registers */
/* RTC configured as follow:
- Hour Format = Format 24
- Asynch Prediv = Value according to source clock
- Synch Prediv = Value according to source clock
- OutPut = Output Disable
- OutPutPolarity = High Polarity
- OutPutType = Open Drain */
RTCHandle.Instance = RTC;
RTCHandle.Init.HourFormat = RTC_HOURFORMAT_24;
RTCHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
RTCHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV;
RTCHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
RTCHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
RTCHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
HAL_RTC_Init(&RTCHandle);
//Initiate data and time
RTC_TimeStruct.TimeFormat = RTC_HOURFORMAT12_AM;
RTC_TimeStruct.Hours = 0x00;
RTC_TimeStruct.Minutes = 0x00;
RTC_TimeStruct.Seconds = 0x00;
RTC_TimeStruct.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ;
RTC_TimeStruct.StoreOperation = RTC_STOREOPERATION_RESET;
HAL_RTC_SetTime(&RTCHandle,&RTC_TimeStruct,FORMAT_BIN);
// RTC_TimeStructInit( &RTC_TimeStruct );
RTC_DateStruct.WeekDay = RTC_WEEKDAY_SATURDAY;
RTC_DateStruct.Date = 0x01;
RTC_DateStruct.Month = RTC_MONTH_JANUARY;
RTC_DateStruct.Year = 0x01;
HAL_RTC_SetDate(&RTCHandle,&RTC_DateStruct,FORMAT_BIN);
}
示例15: MX_RTC_Init
/* RTC init function */
void MX_RTC_Init(void)
{
RTC_TimeTypeDef sTime;
RTC_DateTypeDef sDate;
/**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(__FILE__, __LINE__);
}
/**Initialize RTC and set the Time and Date
*/
if(HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR0) != 0x32F2){
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(__FILE__, __LINE__);
}
sDate.WeekDay = RTC_WEEKDAY_MONDAY;
sDate.Month = RTC_MONTH_JANUARY;
sDate.Date = 0x1;
sDate.Year = 0x0;
if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR0,0x32F2);
}
/**Enable the WakeUp
*/
if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 5, RTC_WAKEUPCLOCK_CK_SPRE_16BITS) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}