cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f4 RTC Alarm with LCD

haythem
Associate II
Posted on June 19, 2014 at 17:40

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

  1. void RTC_Config(void)
  2. {
  3. RTC_TimeTypeDef RTC_TimeStructure;
  4. RTC_InitTypeDef RTC_InitStructure;
  5.   /* Enable the PWR clock */
  6.   RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
  7.   /* Allow access to RTC */
  8.   //PWR_BackupAccessCmd(ENABLE);
  9.   /* Reset RTC Domain */
  10.   RCC_BackupResetCmd(ENABLE);
  11.   RCC_BackupResetCmd(DISABLE);
  12.   /* Enable the LSE OSC */
  13.   RCC_LSEConfig(RCC_LSE_ON);
  14.   /* Wait till LSE is ready */  
  15.   while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
  16.   {
  17.   }
  18.   /* Select the RTC Clock Source */
  19.   RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
  20.   /* Define the RCC with hours */
  21.   RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
  22.   RTC_InitStructure.RTC_SynchPrediv  = 0xFF;
  23.   RTC_InitStructure.RTC_HourFormat   = RTC_HourFormat_24;
  24.   RTC_Init(&RTC_InitStructure);
  25.   
  26.   /* Define time to 00h 00mn 00s AM */
  27.   RTC_TimeStructure.RTC_H12     = RTC_H12_AM;
  28.   RTC_TimeStructure.RTC_Hours   = 0x00;  //0 h
  29.   RTC_TimeStructure.RTC_Minutes = 0x00;  //0 Minutes
  30.   RTC_TimeStructure.RTC_Seconds = 0x00;  // Secands
  31.   RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
  32.   
  33. }
  34. void RTC_AlarmConfig(void)
  35. {
  36.   EXTI_InitTypeDef EXTI_InitStructure;
  37.   RTC_AlarmTypeDef RTC_AlarmStructure;
  38.   NVIC_InitTypeDef NVIC_InitStructure;
  39.   
  40.   /* EXTI configuration */
  41.   EXTI_ClearITPendingBit(EXTI_Line17);
  42.   EXTI_InitStructure.EXTI_Line = EXTI_Line17;
  43.   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  44.   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  45.   EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  46.   EXTI_Init(&EXTI_InitStructure);
  47.   
  48.   /* Enable the RTC Alarm Interrupt */
  49.   NVIC_InitStructure.NVIC_IRQChannel = RTC_Alarm_IRQn;
  50.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  51.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  52.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  53.   NVIC_Init(&NVIC_InitStructure);
  54.  
  55.   /* Set the alarmA Masks */
  56.   RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_All;
  57.   RTC_SetAlarm(RTC_Format_BCD, RTC_Alarm_A, &RTC_AlarmStructure);
  58.   
  59.   /* Set AlarmA subseconds and enable SubSec Alarm : generate 8 interripts per Second */
  60.   RTC_AlarmSubSecondConfig(RTC_Alarm_A, 0xFF, RTC_AlarmSubSecondMask_SS14_5);
  61.   /* Enable AlarmA interrupt */
  62.   RTC_ITConfig(RTC_IT_ALRA, ENABLE);
  63. }

13 REPLIES 13
haythem
Associate II
Posted on June 22, 2014 at 17:34

Thank you for your help it was very useful. 

haythem
Associate II
Posted on June 24, 2014 at 03:50

Naw I want to display a float that I calculated from the time, but the problem is that 16 * 2 LCD displays nothing

  1. float total;
  2. int S=0x00;
  3. int M=0x00;
  4. int H=0x00;
  5. char totallcd[16];
  6. void read_time(void)
  7. {
  8.   RTC_GetTime(RTC_Format_BCD, &RTC_TimeStructure);
  9.  
  10.    H=RTC_TimeStructure.RTC_Hours;
  11.    M=RTC_TimeStructure.RTC_Minutes;
  12.    S=RTC_TimeStructure.RTC_Seconds;
  13. }
  14. void total_reac(void)
  15. { read_time();
  16. total=S*0.0012+M*0.072+H*4.32;
  17. sprintf(totallcd,''%d'',total);
  18. }
  19.  
  20. float total;
  21. int S=0x00;
  22. int M=0x00;
  23. int H=0x00;
  24. char totallcd[16];
  25.  
  26. void read_time(void)
  27. {
  28.   RTC_GetTime(RTC_Format_BCD, &RTC_TimeStructure);
  29.  
  30.    H=RTC_TimeStructure.RTC_Hours;
  31.    M=RTC_TimeStructure.RTC_Minutes;
  32.    S=RTC_TimeStructure.RTC_Seconds;  
  33.                
  34. }
  35. void total_reac(void)
  36. {              read_time();
  37.                 total=S*0.0012+M*0.072+H*4.32;
  38.                 

    sprintf(totallcd,''%d'',total);

  39.                
  40. }
  41.  
  42.  
  43. float total;
  44. int S=0x00;
  45. int M=0x00;
  46. int H=0x00;
  47. char totallcd[16];
  48.  
  49. void read_time(void)
  50. {
  51.   RTC_GetTime(RTC_Format_BCD, &RTC_TimeStructure);
  52.  
  53.    H=RTC_TimeStructure.RTC_Hours;
  54.    M=RTC_TimeStructure.RTC_Minutes;
  55.    S=RTC_TimeStructure.RTC_Seconds;  
  56.                
  57. }
  58. void total_reac(void)
  59. {              read_time();
  60.                 total=S*0.0012+M*0.072+H*4.32;
  61.                 

    sprintf(totallcd,''%d'',total);

  62.                
  63. }

Posted on June 24, 2014 at 05:31

Now I want to display a float that I calculated from the time, but the problem is that 16 * 2 LCD displays nothing

And you're sending it to the display where exactly?

LCD_Print()

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Trev
Associate II
Posted on June 24, 2014 at 10:17

Surely instead of

sprintf(totallcd,''%d'',total);

you should be using

sprintf(totallcd,''%f'',total);

for a float.

Clives question also applies.