STM32 Nucleo H7A3ZI board UART Issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-26 2:02 PM - last edited on ‎2024-08-27 8:49 AM by mƎALLEm
Hi Community,
I am facing very basic issue. My UART in H7A3ZI Nucleo 144 board is not displaying correctly on terminal.
My UART Setting:
huart3.Instance = USART3;
huart3.Init.BaudRate = 115200;
huart3.Init.WordLength = UART_WORDLENGTH_8B;
huart3.Init.StopBits = UART_STOPBITS_1;
huart3.Init.Parity = UART_PARITY_NONE;
huart3.Init.Mode = UART_MODE_TX_RX;
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart3.Init.OverSampling = UART_OVERSAMPLING_16;
huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart3.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart3) != HAL_OK)
My Code:
int _write(int file, char *ptr, int len)
{
HAL_UART_Transmit(&huart3, (uint8_t*)ptr, len, HAL_MAX_DELAY);
return len;
}
//and
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
printf("current number is %d\r\n", counter++);
HAL_Delay(500);
}
My Buad rate is 115200
This is basic code to get UART output data on ST link virtual serial port that is connected to Laptop.
Solved! Go to Solution.
- Labels:
-
STM32H7 Series
-
UART-USART
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-27 9:59 AM - edited ‎2024-08-27 10:05 AM
@mahmanish wrote:Can you please explain why it is so
A fundamental requirement of asynchronous serial comms - ie, UART comms, as here - is that the sender and receiver must be working at the same baud rate.
If the baud rates differ, the receiver will not be able to correctly recognise what was sent.
For reliable comms, the baud rate error should not exceed about 2%.
The above is all entirely general - not specific to ST or STM32.
The sending baud rate on your STM32 is derived from the clock; so, if your clock is not what you think, then the baud rate will be wrong - and you will get corrupted comms:
This is why I always suggest that people use an oscilloscope or logic analyser to look at the signal on the wire - and verify the actual baud rate.
#BaudRateError #SerialGarbage #BaudRate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-26 2:24 PM
Watch what value HSE_VALUE is using, against the MCO frequency the ST-LINK/V3 is actually generating.
25 MHz / 3 = 8.333333 MHz, not 8.000 MHz
The firmware update tool should provide some clocking options.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-27 8:43 AM
Hi,
It is indeed 25 MHz, which i never changed it.
#if !defined (HSE_VALUE)
#define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
Do i need to make change in this for UART to work properly? Because I have Nucleo F446RE board where i never changed anything and that worked.
Is it because of my nucleo board H7A3ZI which require some special settings?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-27 9:00 AM
Hello,
Could you please share your ioc file? What clock source you set? HSE or HSI?
If you are using HSE in Bypass mode you need to check the Clock source frequency generated by the ST-LINK over MCO.
Could you please check this information using ST-Link Upgrade tool and see what MCO output is set?
By default it's set to HSE/3 = 8.33MHz.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-27 9:41 AM - edited ‎2024-08-27 9:49 AM
 Thank you SofLit,
You have pointed me in correct direction, earlier it was put up in PLL. Now i have changed it to HSI and it is coming correctly.
Can you please explain why it is so or some link where i can get more details about it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-27 9:59 AM - edited ‎2024-08-27 10:05 AM
@mahmanish wrote:Can you please explain why it is so
A fundamental requirement of asynchronous serial comms - ie, UART comms, as here - is that the sender and receiver must be working at the same baud rate.
If the baud rates differ, the receiver will not be able to correctly recognise what was sent.
For reliable comms, the baud rate error should not exceed about 2%.
The above is all entirely general - not specific to ST or STM32.
The sending baud rate on your STM32 is derived from the clock; so, if your clock is not what you think, then the baud rate will be wrong - and you will get corrupted comms:
This is why I always suggest that people use an oscilloscope or logic analyser to look at the signal on the wire - and verify the actual baud rate.
#BaudRateError #SerialGarbage #BaudRate
