2021-12-06 11:28 AM
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();
}
Solved! Go to Solution.
2021-12-06 11:37 AM
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.
2021-12-06 11:37 AM
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.
2021-12-06 01:35 PM
Thank you for the info!
It works and complies with no warnings now.
Appreciate the help.