cancel
Showing results for 
Search instead for 
Did you mean: 

Nucleo-G070RB prints garbage via UART

BSerb
Associate II

I've programmed this board to print out some data via the onboard serial interface (using UART2). But all I get is garbage characters, and I can't figure out why. I checked the baud rate of both the Nucleo and the terminal, I've tried different terminal apps, even swapped cables, but it still acts like the baut rate is mismatched between the two.

0693W00000GZtokQAD.pngThe UART is initialized by default, the only code that I added is in the while loop:

	  strcpy((char*)buf, "serial test\r\n");
	  HAL_UART_Transmit(&huart2, buf, strlen((char*)buf), HAL_MAX_DELAY);
	  HAL_GPIO_TogglePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin);
	  HAL_Delay(1000);

buf is defined as:

uint8_t buf[15];

Here's the code Cube generated for huart2:

  huart2.Instance = USART2;
  huart2.Init.BaudRate = 115200;
  huart2.Init.WordLength = UART_WORDLENGTH_7B;
  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;
  huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1;
  huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

2 REPLIES 2

7-bit, really?

For clock mismatch check HSE_VALUE define.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
LKett.1
Associate II

The default for a new project, targeted at a NUCLEO_G070RB board, (still) seems to be to use "7 Bits (including Parity)" as a default for the "Word Length", at least for USART2 (on pins PA2 and PA3, commented, via soldered jumpers to the RX and TX pins for the ST-LINK, on top of the board).

I just made a new project, in STM32CubeIDE V1.12.0 (Build: 14980_20230301_1550 (UTC)) and "7 Bits (including Parity)" is still present as a default (for some reason).

Has anyone ever come across any good reason for using 7-bit or 9-bit words on a UART?