cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H747 RTC weird behaviour: the display appears with abnormal characters

davidedigesualdo
Associate II

Hi everyone!

I'm using an Arduino Portenta H7 (STM32H747) board mounted on a custom carrier board.

I'm using STM32CubeIDE as a development environment, with HAL libraries for peripheral initialization.
I'm only using the Portenta's M7 core.

Portenta interfaces via GPIO to a parallel bus that drives both a display and other peripherals. I'm also using the RTC module for the system clock only, initialized at startup via HAL.

Everything works fine until I try to set the RTC datetime using this function:

void tm_wr(struct tm *_tm) {
RTC_DateTypeDef sDate;
RTC_TimeTypeDef sTime;

if (_tm->tm_wday == 0) {
sDate.WeekDay = 7;
} else {
sDate.WeekDay = _tm->tm_wday;
}

sDate.Month = (uint8_t)_tm->tm_mon + 1;
sDate.Date = (uint8_t)_tm->tm_mday;
sDate.Year = (uint16_t)(_tm->tm_year-100);
HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN);

sTime.Hours = (uint8_t)_tm->tm_hour;
sTime.Minutes = (uint8_t)_tm->tm_min;
sTime.Seconds = (uint8_t)_tm->tm_sec;
HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN);
}

 

After this setting, any string on the display appears with abnormal characters. This happens even when I reboot the MCU or remove power from the system while leaving the VBAT power supply on. If I also remove the VBAT, everything starts working again.

The RTC peripheral clock is an external bypass clock at 32768Hz on pin PC14 (OSC IN), while PC15 (OSC OUT) is used on the bus.

What could be causing this behavior?

Thanks everyone, any suggestion is really appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
waclawek.jan
Super User

PC13 = data bit 7 on the LCD is stuck high. Look at the character set of your LCD.

The reason is the same as in the more usual "RTC runs in am/pm mode which I did not set" issue - you don't initialize the local RTC_TimeTypeDef struct so it has fields set to "random" values before calling HAL_RTC_SetTime(), resulting in unexpected changes in RTC_CR. In your case, RTC_CR.OSEL/COE/POL are set to nonzero, resulting in PC13 being overriden by RTC and 1 being output onto it, depending on the particular setting of above RTC_CR fields. You can read out and check RTC_CR to see this.

The remedy is simple,

RTC_DateTypeDef sDate = {0};
RTC_TimeTypeDef sTime = {0};

(or fill in all fields of those structs explicitly)

JW

View solution in original post

9 REPLIES 9
mƎALLEm
ST Employee

Hello @davidedigesualdo and welcome to the ST community,

What do you mean by display here: "After this setting, any string on the display appears with abnormal characters. " ?

IDE Live expression? LCD display?

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Hello @mƎALLEm ,

thank you for your reply!

The display has a Hitachi HD44780 controller. After the startup, the strings the MCU sends to the display are correctly displayed. After date&time setting if the MCU sends a string with 5 ASCII characters (latin alphabet), the display displays 5 characters but they are not the correct ones ("HELLO" becomes something like "δπДДψ").

waclawek.jan
Super User

Which pins are connected to the LCD?

 

JW

TDK
Super User

The RTC can work independently of any communication protocol. Changing the time and date shouldn't affect anything.

sTime has other fields which you do not initialize and are left at random values. That should be fixed, but I don't think that will cause issues.

You haven't given us much else to work with. Perhaps a pin is misconfigured, perhaps LSE isn't set up as bypass, perhaps some other cross talk is happening which gives a spurious edge.

If you feel a post has answered your question, please click "Accept as Solution".

Did you check the values in the Live Expression?

I suspect an issue in your LCD display implementation not related to the RTC.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

The parallel bus is connected as follows (left is the MCU, right is the peripherals side)

davidedigesualdo_0-1768383742484.png

RDB0..7 are the data bus, BA10..12 are connected to a multiplexer used to select the CS for the LCD or other peripherals, PE7 is the CS (strobe of the multiplexer), BIOWR-BIORD are connected to logic ports (they implements the logic for LCD R/W pin). 

Two more pins are connected to the LCD: PH13 and PH8

davidedigesualdo_1-1768384688319.png

 

I know the RTC can work independently of any communication protocol or bus configuration, this issue is really strange to me.

The only thing I see is that the LCD works fine since the startup (I can navigate the menu of the instrument and all the strings are correctly drawn), but as soon as I set the RTC date and time the issue comes, and the LCD starts to display like this:

WhatsApp Image 2026-01-14 at 11.04.23.jpeg

 The string in the second line should be "Start".

I've double checked, and the LSE is set as BYPASS.

waclawek.jan
Super User

PC13 = data bit 7 on the LCD is stuck high. Look at the character set of your LCD.

The reason is the same as in the more usual "RTC runs in am/pm mode which I did not set" issue - you don't initialize the local RTC_TimeTypeDef struct so it has fields set to "random" values before calling HAL_RTC_SetTime(), resulting in unexpected changes in RTC_CR. In your case, RTC_CR.OSEL/COE/POL are set to nonzero, resulting in PC13 being overriden by RTC and 1 being output onto it, depending on the particular setting of above RTC_CR fields. You can read out and check RTC_CR to see this.

The remedy is simple,

RTC_DateTypeDef sDate = {0};
RTC_TimeTypeDef sTime = {0};

(or fill in all fields of those structs explicitly)

JW

@waclawek.jan you made my day!

I've added the initialization of the date/time structures, it seems to work fine.

Thank you, the issue is solved.