Skip to main content
idrissmc
Associate III
February 5, 2020
Question

DigitalClock STM32F746G-Disco

  • February 5, 2020
  • 1 reply
  • 550 views

hi everyone,

I want to make the digital clock work, how can I do that?

This topic has been closed for replies.

1 reply

O. Mz. - 7
Associate
February 5, 2020

I use this code to display time and date. It works. In the Pinout&Configuration the "Activate Clock Source" and "Activate Calendar" are checked in the "Timers" section.

It just displays the time and the date on the OLED screen. The board is Nucleo F767ZI. Connecting the OLED is a separate topic, but your STM32F746G-Disco has the inbuilt display.

 RTC_TimeTypeDef stimestructureget;
 
		RTC_DateTypeDef sdatestructureget;
 
		HAL_RTC_GetTime(&hrtc, &stimestructureget, RTC_FORMAT_BIN);
		HAL_RTC_GetDate(&hrtc, &sdatestructureget, RTC_FORMAT_BIN);
 
		char timeBuff[12] = "";
		char dateBuff[16] = "";
 
		sprintf(timeBuff, "%u:%u:%u", stimestructureget.Hours,
				stimestructureget.Minutes, stimestructureget.Seconds);
 
		sprintf(dateBuff, "%u.%u.%u", sdatestructureget.Date,
				sdatestructureget.Month, 2000 + sdatestructureget.Year);
  
 //displaying time and date on the OLED screen
		SSD1306_GotoXY(0, 50); // x, y
 
		strcat(timeBuff, " ");
 
		strcat(timeBuff, dateBuff);
 
		SSD1306_Puts(timeBuff, &Font_7x10, 1);
 
		SSD1306_UpdateScreen(); // update screen