Time clock using built in RTC of STM32 bluebill

199 Views Asked by At

I am new in STM32 development and trying to built RTC clock that display's time on oled display.
But on screen some random unidentified symbols are displaying by the below code.

 while(1){
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
        HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BIN);
        HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BIN);
        uint8_t *a = sTime.Hours;
         char* buffer2;
          int i;

          buffer2 = malloc(9);
          if (!buffer2)
                 break;

          buffer2[8] = 0;
          for (i = 0; i <= 7; i++)
            buffer2[7 - i] = (((*a) >> i) & (0x01)) + '0';

          puts(buffer2);

//      sprintf(date,"Date: %02d.%02d.%02d\t",sDate.Date,sDate.Month,sDate.Year);
//      sprintf(time,"Time: %02d.%02d.%02d\r\n",sTime.Hours,sTime.Minutes,sTime.Seconds);
               SSD1306_GotoXY (0,0);
                   SSD1306_Puts (buffer2, &Font_11x18, 1);
                   SSD1306_GotoXY (0, 30);
                   SSD1306_Puts ("CLOCK", &Font_11x18, 1);
                   SSD1306_UpdateScreen();
                   HAL_Delay (1000);


     }

Here is my clock configuration

enter image description here

0

There are 0 best solutions below