Skip to main content
Associate II
November 1, 2024
Question

NUCLEO-F103RB UART baudrate Error

  • November 1, 2024
  • 2 replies
  • 1321 views

I used NUCLEO-F103RB (MB1136 Rev C) and X-NUCLEO-NFC03A1 to run the example program in X-CUBE-NFC3. I received data from the serial port using 115200-8N1 and received the following:

 

okcykkykkhht	nkgkkkkfkca{sytcki{s{on	qskkqcnsg

 

Then I used a logic analyzer to detect the speed of the serial port, and after calculation, the actual baud rate was 90909. I received the correct content using the calculated baud rate:

 

Welcome to X-NUCLEO-NFC03A1
Use the User button to cycle among the different modes:
1. Tap a tag to read its content
2. Present a tag to write a Text record
3. Present a tag to write a URI record and an Android Application record
4. Present an ST tag 
to format
In Write or Format mode (menu 2, 3 or 4), the demo returns to Read mode (menu 1) if no tag detected after 10 seconds

1. Tap a tag to read its content

 

 However, the serial port configuration in the example code is 115200:

 

static void MX_USART2_UART_Init(void)
{

 /* USER CODE BEGIN USART2_Init 0 */

 /* USER CODE END USART2_Init 0 */

 /* USER CODE BEGIN USART2_Init 1 */

 /* USER CODE END USART2_Init 1 */
 huart2.Instance = USART2;
 huart2.Init.BaudRate = 115200;
 huart2.Init.WordLength = UART_WORDLENGTH_8B;
 huart2.Init.StopBits = UART_STOPBITS_1;
 huart2.Init.Parity = UART_PARITY_NONE;
 huart2.Init.Mode = UART_MODE_TX_RX;
 huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
 huart2.Init.OverSampling = UART_OVERSAMPLING_16;
 if (HAL_UART_Init(&huart2) != HAL_OK)
 {
 _Error_Handler(__FILE__, __LINE__);
 }
 /* USER CODE BEGIN USART2_Init 2 */

 /* USER CODE END USART2_Init 2 */

}

 

I have checked the clock output (MCO) and all jumper resistors from the onboard ST Link and everything is normal. I have also modified the clock configuration, but this issue has persisted. Can someone tell me how to solve the problem of baud rate error.

2 replies

PGump.1
Senior II
November 1, 2024

Hi,

For the information you have given, it suggests your usart clock is not right...

Kind regards
Pedro

AI = Artificial Intelligence, NI = No Intelligence, RI = Real Intelligence.
EZHON.1
ST Employee
November 4, 2024

MCO is only from STLINK MCU side. you need to check F103RB itself by PA8 on pin CN9.8,

vgegokAuthor
Associate II
November 4, 2024

Yes, I detected the actual baud rate of STM32F103RB through PA8 and PA9, and it is 90909bps.

gbm
Principal
November 4, 2024

So the clock configuration is wrong. Why don't you fix it?

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice