仿真调试时发现写入的 WeekDay 的值为 0xD8,显然是一个不合理的值,因为在 HAL 库中星期的取值范围是1~7。 void hal_calender_write(struct calender *cld) { RTC_DateTypeDef date; RTC_TimeTypeDef time; hal_enter_critical(); date.Year = (unsigned char)(cld->year - 2000); date.Month = cld-...
*/typedef struct{uint8_t WeekDay;/*!< Specifies the RTC Date WeekDay. This parameter can be a value of @ref RTC_WeekDay_Definitions */uint8_t Month;/*!< Specifies the RTC Date Month (in BCD format). This parameter can be a value of @ref RTC_Month_Date_Definitions */uint8_t D...
DateToUpdate.WeekDay=RTC_WEEKDAY_WEDNESDAY; DateToUpdate.Month=RTC_MONTH_MAY; DateToUpdate.Date=0x31; DateToUpdate.Year=0x23; void MX_RTC_Init(void):图二 /*RTC init function*/voidMX_RTC_Init(void) {/*USER CODE BEGIN RTC_Init 0*//*USER CODE END RTC_Init 0*/RTC_TimeTypeDef sTime...
RTC_DateTypeDef dates_t; RTC_GetDate(RTC_Format_BIN,&dates_t); printf("rtc_get_date:Y:%02d,M:%02d,D:%02d,WeekDay:%02d\r\n",dates_t.RTC_Year,dates_t.RTC_Month,dates_t.RTC_Date,dates_t.RTC_WeekDay); delay_ms(1000); } }...
return &dateAndTime; } #ifndef RTC_H_ #define RTC_H_ #include "stm32f4xx.h" #include "stdio.h" #include "string.h" typedef struct { u8 hour; u8 minute; u8 second; u8 year; u8 month; u8 day; u8 week; u8 ampm; }TIME_DATA; ...
RTC_DateStr.RTC_WeekDay=RTC_Weekday_Tuesday; RTC_DateStr.RTC_Date=2; RTC_DateStr.RTC_Month=RTC_Month_February; RTC_DateStr.RTC_Year=16; RTC_SetDate(RTC_Format_BIN,&RTC_DateStr); } voidrtc_get_time(char*buf) { RTC_TimeTypeDefRTC_TimeStr; ...
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(); } /** Enable the WakeUp
//返回值:SUCEE(1),成功 // ERROR(0),进入初始化模式失败 ErrorStatus RTC_Set_Date(u8 year,u8 month,u8 date,u8 week) { RTC_DateTypeDef RTC_DateTypeInitStructure; RTC_DateTypeInitStructure.RTC_Date=date; RTC_DateTypeInitStructure.RTC_Month=month; RTC_DateTypeInitStructure.RTC_WeekDay=week; RT...
Init(&RTC_InitStructure);//3-设置日期RTC_DateStructure.RTC_Year = 0x21;//21年RTC_DateStructure.RTC_Month = 0x09;//9月RTC_DateStructure.RTC_Date = 0x14;//14号RTC_DateStructure.RTC_WeekDay = 0x02;//周二RTC_SetDate(RTC_Format_BCD, &RTC_DateStructure);//4-时间设置 时分秒 16:06:00...
RTC_DateTypeDef RTC_DateStructure; RTC_InitTypeDef RTC_InitStructure; RTC_AlarmTypeDef RTC_AlarmStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE); PWR_BackupAccessCmd(ENABLE); RCC_BackupResetCmd(ENABLE); RCC_BackupResetCmd(DISABLE); ...