Skip to main content
JWire.1
Associate III
December 6, 2021
Solved

I am trying to display the time on a OLED display using the RTC and I can get it to work but I keep getting a warning. I know there is a better way and was hoping someone could enlighten me as to what I should be doing.

  • December 6, 2021
  • 2 replies
  • 1338 views

Hello I am very new to c programming and embedded design. I know there is a right way to do what I am trying to accomplish. I seem to be doing it the wrong way even though my code still "works"

I am getting warnings on a couple lines of code. Line 51 and 53 of this code snippet.

the warning is "pointer targets in passing argument 1 of 'SSD1306_Puts' differ in signedness [-Wpointer-sign]

I can't include all my code because it is saying my post is too long so I have tried to include all the relevant information.

I

/* USER CODE BEGIN PTD */
 
/* Buffers used to display Time and Date */
uint8_t aShowTime[50] = {0};
uint8_t aShowDate[50] = {0};
 
 
 
 
 
 
/**
 * @brief Display the current time and date.
 * @param showtime : pointer to buffer
 * @param showdate : pointer to buffer
 * @retval None
 */
static void RTC_CalendarUpdate(uint8_t *showtime, uint8_t *showdate)
{
 
 RTC_DateTypeDef sdatestructureget;
 RTC_TimeTypeDef stimestructureget;
 
 /* Get the RTC current Time */
 if (HAL_RTC_GetTime(&hrtc, &stimestructureget, RTC_FORMAT_BIN) != HAL_OK)
 {
 /* HAL Error */
 Error_Handler();
 }
 
 /* Get the RTC current Date */
 if (HAL_RTC_GetDate(&hrtc, &sdatestructureget, RTC_FORMAT_BIN) != HAL_OK)
 {
 /* HAL Error */
 Error_Handler();
 }
 
 /* Display time Format : hh:mm:ss */
 sprintf((char *)showtime, "%02d:%02d:%02d", stimestructureget.Hours, stimestructureget.Minutes, stimestructureget.Seconds);
 /* Display date Format : mm-dd-yy */
 sprintf((char *)showdate, "%02d-%02d-%02d", sdatestructureget.Month, sdatestructureget.Date, 2000 + sdatestructureget.Year);
}
 
 
 
void display_time (void)
{
	 RTC_CalendarUpdate(aShowTime, aShowDate);
 
	 SSD1306_GotoXY(20, 0);
	 SSD1306_Puts(aShowTime, &Font_11x18, 1);
	 SSD1306_GotoXY(10, 30);
	 SSD1306_Puts(aShowDate, &Font_11x18, 1);
	 SSD1306_UpdateScreen();
 
 
 
}

This topic has been closed for replies.
Best answer by TDK

You can convert your pointers to unsigned bytes to pointers to signed bytes like this:

	 SSD1306_Puts((char *) aShowTime, &Font_11x18, 1);
	 SSD1306_GotoXY(10, 30);
	 SSD1306_Puts((char *) aShowDate, &Font_11x18, 1);

> I can't include all my code because it is saying my post is too long so I have tried to include all the relevant information.

For future reference, you can attach a file to your post if you want to include the code. No need to do so here.

2 replies

TDK
TDKBest answer
December 6, 2021

You can convert your pointers to unsigned bytes to pointers to signed bytes like this:

	 SSD1306_Puts((char *) aShowTime, &Font_11x18, 1);
	 SSD1306_GotoXY(10, 30);
	 SSD1306_Puts((char *) aShowDate, &Font_11x18, 1);

> I can't include all my code because it is saying my post is too long so I have tried to include all the relevant information.

For future reference, you can attach a file to your post if you want to include the code. No need to do so here.

"If you feel a post has answered your question, please click ""Accept as Solution""."
JWire.1
JWire.1Author
Associate III
December 6, 2021

Thank you for the info!

It works and complies with no warnings now.

Appreciate the help.