No data signal on USART_Tx pin on my STM32-Nucleo

924 Views Asked by At

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.

3

There are 3 best solutions below

1
pmacfarlane On BEST ANSWER

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.

0
0___________ On
  1. You need to enable clocks on GPIO ports used by UART
  2. You need to set their mode to the correct alternate mode.
  3. You need to enable UART clock
  4. You need to initialize and setup the UART registers
  5. Then you can transmit the data.
1
codeurdudimanche On

My goal was to transmit data from Nucleo 1 to Nucleo 2 with UART, here is what i tried :

1st scenario

  • Nucleo 1 USART2_Tx pinned on Nucleo 2 USART2_Rx

  • Nucleo 1 USART2_Rx pinned on Nucleo 2 USART2_Tx

  • Nucleo 1 sends data with UART2 to Nucleo 2

Issue : USART2_Rx IT is never triggered. Pinning my scope on Nucleo 1 USART2_Tx showed permanent 0V line.

Explanation : Solder bridge were configured to transmit UART2 data with USB. That's why I managed to see "Hello World" on my console. But I still wanted to send data with my Nucleo 1 and receive it with my Nucleo 2.

2nd scenario

  • Nucleo 1 USART1_Tx pinned on Nucleo 2 USART2_Rx

  • Nucleo 1 USART1_Rx pinned on Nucleo 2 USART2_Tx

  • Nucleo 1 sends data with UART1 to Nucleo 2

Issue :

I still didn't manage to see the Nucleo 2 UART2 IT triggered. I also can't see any signal with my scope on my Nucleo 1 UART1_Tx pin.

Explanation :

I still used UART2 on my Nucleo 2, which is connected to USB. So it is normal I couldn't see any data on my UART2_Rx data buffer. Still, can't explain why I didn't see any signal on the pin.

3rd scenario

  • Nucleo 1 USART1_Tx pinned on Nucleo 2 USART1_Rx

  • Nucleo 1 USART1_Rx pinned on Nucleo 2 USART1_Tx

  • Nucleo 1 sends data with UART1 to Nucleo 2

Using UART1 for both Nucleo, I managed to send data and receive data correctly. I still don't know why I can't see any signal but it might be my scope (kind of old) or the signal going so fast that I can't catch it.