Search code examples
cstm32uartusartnucleo

No data signal on USART_Tx pin on my STM32-Nucleo


I have some issues trying to transmit data with my USART pins.

I use STM32-Nucleo-L476RG board with USART2 enabled. I generated the code with CubeMX and in my main() function, i call HAL_UART_Transmit() function to send data as the following :

while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
      uint8_t Test[] = "Hello World !!!\r\n"; //Data to send
      HAL_UART_Transmit(&huart2,Test,sizeof(Test),1000);// Sending in normal mode
      HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
      HAL_Delay(500);
  }

(Note : PA5 is my LED, USART2_Tx is on PA2)

Using the command screen on my Linux Terminal to monitor the UART signal, I receive "Hello World !!!" multiple times, so i was thinking UART communication was working.

BUT.

Pinning a scope on the USART_Tx pin corresponding to USART2, i cannot see any signal transmitted (the line is always at 0V). So i receive my USART signal on my computer via USB, but I can't send any data to another Nucleo (for example).

Anyone has an idea of what could be the problem? Any function to call to instantiate something? I can send more details about my code/pin configs via cubeMX if needed.

PS : I also tested with STM32-Nucleo-F401RE and the result is the same so I think the problem definitely comes from me.

Thanks.

To solve the problem, I tried to use other UART/USART available (from 1 to 3), without results. I also tried to closed-loop my Tx/Rx pins to Receive data from the Tx pin. Also without results.

Concerning the clock/pin init :

PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2;
PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
  Error_Handler();
}

/* Peripheral clock enable */
__HAL_RCC_USART2_CLK_ENABLE();

__HAL_RCC_GPIOA_CLK_ENABLE();
/**USART2 GPIO Configuration
PA2     ------> USART2_TX
PA3     ------> USART2_RX
*/
GPIO_InitStruct.Pin = USART_TX_Pin|USART_RX_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

This function is called in my main() function before the main loop.

From what I see on my board, SB62 & SB63 do not have the connector on top of them, and SB13 & SB14 both have the connector on top of them. I think it could be the issue. Updating the post when I can test it.


Solution

  • From section 6.8 of the user manual for the STM32-Nucleo-L476RG:

    The USART2 interface available on PA2 and PA3 of the STM32 microcontroller can be connected to ST-LINK MCU, ST morpho connector, or to ARDUINO® connector. The choice can be changed by setting the related solder bridges. By default, the USART2 communication between the target STM32 and ST-LINK MCU is enabled, in order to support virtual COM port for Mbed™ (SB13 and SB14 ON, SB62 and SB63 OFF). If the communication between the target STM32 PA2 (D1) or PA3 (D0) and shield or extension board is required, SB62 and SB63 must be ON, while SB13 and SB14 must be OFF.

    Therefore your board is configured to route the UART2 signals to the ST-Link rather than to the pin connectors, which is why you can receive the data over USB, but not see anything on the pins.

    You will need to fit SB62 and SB63, and remove SB13 and SB14, if you want to use UART2 to talk to another board.