STM32f4 RTC Alarm with LCD
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-06-19 8:40 AM
HI, i want to configure the RTC alarm with LCD, to goal is to display the time in a LCD. I set the LCD and RTC but I do not know commant display the time on the LCD
This is my code to configure the RTC alarm- void RTC_Config(void)
- {
- RTC_TimeTypeDef RTC_TimeStructure;
- RTC_InitTypeDef RTC_InitStructure;
- /* Enable the PWR clock */
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
- /* Allow access to RTC */
- //PWR_BackupAccessCmd(ENABLE);
- /* Reset RTC Domain */
- RCC_BackupResetCmd(ENABLE);
- RCC_BackupResetCmd(DISABLE);
- /* Enable the LSE OSC */
- RCC_LSEConfig(RCC_LSE_ON);
- /* Wait till LSE is ready */
- while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
- {
- }
- /* Select the RTC Clock Source */
- RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
- /* Define the RCC with hours */
- RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
- RTC_InitStructure.RTC_SynchPrediv = 0xFF;
- RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
- RTC_Init(&RTC_InitStructure);
- /* Define time to 00h 00mn 00s AM */
- RTC_TimeStructure.RTC_H12 = RTC_H12_AM;
- RTC_TimeStructure.RTC_Hours = 0x00; //0 h
- RTC_TimeStructure.RTC_Minutes = 0x00; //0 Minutes
- RTC_TimeStructure.RTC_Seconds = 0x00; // Secands
- RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
- }
- void RTC_AlarmConfig(void)
- {
- EXTI_InitTypeDef EXTI_InitStructure;
- RTC_AlarmTypeDef RTC_AlarmStructure;
- NVIC_InitTypeDef NVIC_InitStructure;
- /* EXTI configuration */
- EXTI_ClearITPendingBit(EXTI_Line17);
- EXTI_InitStructure.EXTI_Line = EXTI_Line17;
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStructure);
- /* Enable the RTC Alarm Interrupt */
- NVIC_InitStructure.NVIC_IRQChannel = RTC_Alarm_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- /* Set the alarmA Masks */
- RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_All;
- RTC_SetAlarm(RTC_Format_BCD, RTC_Alarm_A, &RTC_AlarmStructure);
- /* Set AlarmA subseconds and enable SubSec Alarm : generate 8 interripts per Second */
- RTC_AlarmSubSecondConfig(RTC_Alarm_A, 0xFF, RTC_AlarmSubSecondMask_SS14_5);
- /* Enable AlarmA interrupt */
- RTC_ITConfig(RTC_IT_ALRA, ENABLE);
- }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-06-19 8:52 AM
Perhaps you can use
http://www.cplusplus.com/reference/cstdio/sprintf/
to compose a string in the format you want, and then print the string to the LCD.Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-06-19 9:16 AM
Thank you , i have a problem with ''
PWR_BackupAccessCmd(ENABLE);'' than keil give me this erreur ''.\TIM_PWM_Output\TIM_PWM_Output.axf: Error: L6218E: Undefined symbol PWR_BackupAccessCmd (referred from main.o).'' i use the stm32f4 discovery library
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-06-19 9:57 AM
Make sure you have the library file stm32f4xx_pwr.c in your project
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-06-21 10:21 AM
- void RTC_Config(void)
- {
- RTC_TimeTypeDef RTC_TimeStructure;
- RTC_InitTypeDef RTC_InitStructure;
- /* Enable the PWR clock */
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
- /* Allow access to RTC */
- PWR_BackupAccessCmd(ENABLE);
- /* Reset RTC Domain */
- RCC_BackupResetCmd(ENABLE);
- RCC_BackupResetCmd(DISABLE);
- /* Enable the LSE OSC */
- RCC_LSEConfig(RCC_LSE_ON);
- /* Wait till LSE is ready */
- /* while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
- {
- }*/
- /* Select the RTC Clock Source */
- RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
- /* Define the RCC with hours */
- RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
- RTC_InitStructure.RTC_SynchPrediv = 0xFF;
- RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
- RTC_Init(&RTC_InitStructure);
- /* Define time to 00h 00mn 00s AM */
- RTC_TimeStructure.RTC_H12 = RTC_H12_AM;
- RTC_TimeStructure.RTC_Hours = 0x00; //0 h
- RTC_TimeStructure.RTC_Minutes = 0x00; //0 Minutes
- RTC_TimeStructure.RTC_Seconds = 0x00; // Secands
- RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
- }
- void time_config(void)
- {
- RTC_AlarmTypeDef RTC_AlarmStructure;
- RTC_AlarmCmd(RTC_Alarm_A, DISABLE); /* disable before setting or cann't write */
- /* set alarm time 8:30:0 everyday */
- RTC_AlarmStructure.RTC_AlarmTime.RTC_H12 = RTC_H12_AM;
- RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours = 0x08;
- RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = 0x30;
- RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = 0x0;
- RTC_AlarmStructure.RTC_AlarmDateWeekDay = 0x31; // Nonspecific
- RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;
- RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay; // Everyday
- RTC_SetAlarm(RTC_Format_BCD, RTC_Alarm_A, &RTC_AlarmStructure);
- /* Enable Alarm */
- RTC_ITConfig(RTC_IT_ALRA, ENABLE);
- RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
- RTC_ClearFlag(RTC_FLAG_ALRAF);
- }
- void RTC_AlarmConfig(void)
- {
- EXTI_InitTypeDef EXTI_InitStructure;
- RTC_AlarmTypeDef RTC_AlarmStructure;
- NVIC_InitTypeDef NVIC_InitStructure;
- /* EXTI configuration */
- EXTI_ClearITPendingBit(EXTI_Line17);
- EXTI_InitStructure.EXTI_Line = EXTI_Line17;
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStructure);
- /* Enable the RTC Alarm Interrupt */
- NVIC_InitStructure.NVIC_IRQChannel = RTC_Alarm_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- /* Set the alarmA Masks */
- RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_All;
- RTC_SetAlarm(RTC_Format_BCD, RTC_Alarm_A, &RTC_AlarmStructure);
- /* Set AlarmA subseconds and enable SubSec Alarm : generate 8 interripts per Second */
- RTC_AlarmSubSecondConfig(RTC_Alarm_A, 0xFF, RTC_AlarmSubSecondMask_SS14_5);
- /* Enable AlarmA interrupt */
- RTC_ITConfig(RTC_IT_ALRA, ENABLE);
- }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-06-21 1:37 PM
And what Board and LCD are we talking about? Are there no demos/examples for your board using the LCD? STemWin, etc?
STM32F4xx_DSP_StdPeriph_Lib_V1.0.0\Project\STM32F4xx_StdPeriph_Examples\RTC\RTC_StopWatch\main.c/* Get the Curent time */
RTC_GetTime(RTC_Format_BCD, &RTC_TimeStruct);
/* Display the curent time and the sub second on the LCD */
RTC_Time_display(Line2, Black , RTC_Get_Time(Secondfraction , &RTC_TimeStruct));
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-06-21 3:49 PM
I work with keil ARM bord, i was connected an LCD 16*2 to my stm32f4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-06-21 4:43 PM
Ok, and can you output characters and strings to your display?
And can you use sprintf() to create a string to send to the display from the time structure read from the RTC?Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-06-21 6:57 PM
To write in LCD i use this function, but that is no work with RTC
- void LCD_Print(char* str){ // Print a null terminated string.
- struct TASK Task;
- int strPtr;
- strPtr = 0;
- //LCD_WaitNotBusy(); // Wait until we are not busy first
- while(*(str + strPtr) != 0){
- Task.Command = WriteData;
- Task.Data = WriteData | *(str + strPtr);
- Task.Iter = 0;
- LCD_PushTask(Task);
- strPtr++;
- }
- return;
- }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-06-21 7:21 PM
Wouldn't something like this suffice?
{
char String[16];
RTC_TimeTypeDef RTC_TimeStruct;
/* Get the Curent time */
RTC_GetTime(RTC_Format_BCD, &RTC_TimeStruct);
sprintf(String,''%02X:%02X:%02X'',
RTC_TimeStruct.RTC_Hours,
RTC_TimeStruct.RTC_Minutes,
RTC_TimeStruct.RTC_Seconds);
LCD_Print(String);
}
Up vote any posts that you find helpful, it shows what's working..
