Of course, you will have to initialize the LCD controller itself. GUI_DispStringInRect(text,&gui_rect,GUI_TA_HCENTER|GUI_TA_VCENTER) Given rtc_data_t* rtc_data, here is a Segger-GUI code for displaying HH:MM:SS on the LCD: char text = In addition to the initialization of the I2C controller, you will also need to implement the read/write routines. I2c_polling_write(SENSOR_ADDRESS,0x00,sizeof(raw_data),(char*)&raw_data) Raw_data.weekday = RTC_Weekday_Monday // or calculate the exact day Raw_data.year = DEC_2_HEX(rtc_data->year ) Raw_data.month = DEC_2_HEX(rtc_data->month ) Raw_data.day = DEC_2_HEX(rtc_data->day ) Raw_data.hour = DEC_2_HEX(rtc_data->hour ) Raw_data.minute = DEC_2_HEX(rtc_data->minute) Rtc_data->year = HEX_2_DEC(raw_data.year ) Rtc_data->month = HEX_2_DEC(raw_data.month ) Rtc_data->day = HEX_2_DEC(raw_data.day ) Rtc_data->hour = HEX_2_DEC(raw_data.hour ) Rtc_data->minute = HEX_2_DEC(raw_data.minute) I2c_polling_read(SENSOR_ADDRESS,0x00,sizeof(raw_data),(char*)&raw_data) In the source file: #define SENSOR_ADDRESS 0xD0 // or set this according to your HW configuration RTC_SetTime(RTC_Format_BCD,&RTC_TimeStruct) Īnd here is how you can get/set the date and the time on the RTC, excluding day-of-the-week: RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24 RTC_InitStructure.RTC_SynchPrediv = 0xFF RTC_InitStructure.RTC_AsynchPrediv = 0x7F * Configure the RTC data register and RTC prescaler */ While (RCC_GetFlagStatus(RCC_FLAG_LSERDY) = RESET) RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE) Here is how you can initialize the RTC controller: void rtc_init() In any case, the RTC is typically connected to the STM32 through an I2C bus, so you will need to initialize both controllers (RTC and I2C) before you can get/set the date and the time on the RTC. I'm not sure what exactly you mean by 'display' (i.e., is it an LCD screen, a serial output-terminal, etc?).
0 Comments
Leave a Reply. |