1

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.

Adriaan
  • 17,741
  • 7
  • 42
  • 75
  • If you are receiving the bytes correctly, that makes it seem like it is working fine. You might be missing the signal on the scope. Does it have a capture feature? – Jason May 09 '23 at 15:38
  • @Jason Unfortunately, my scope doesn't have a capture feature. That's why i used a LED to know when I'm supposed to see the bytes, and i also tried a closed-loop between my Rx and Tx but my Rx doesn't seem to see anything (HAL_UART_Receive() goes HAL_TIMEOUT everytime). – codeurdudimanche May 09 '23 at 16:25
  • "*i cannot see any signal transmitted (the line is always at 0V)*" -- Then you have a bigger problem than you realize. A TTL transmit pin would idle at a logic high voltage, e.g. 3.3 volts. Zero volts means that the pin you're probing is not connected to the UART transmit output. "*my scope doesn't have a capture feature*" -- Are you using a CRT 'scope? Otherwise you misunderstand the question? – sawdust May 09 '23 at 21:21
  • Welcome to Stack Overflow! Please do not add answers to the question body itself. Instead, you should add it as an answer. [Answering your own question is allowed and even encouraged](https://stackoverflow.com/help/self-answer). Neither add "solved" to your question title or body. See [what should I do when someone answers](https://stackoverflow.com/help/someone-answers) on how to show you've solved your problem. – Adriaan May 10 '23 at 08:31

3 Answers3

2

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.

pmacfarlane
  • 3,057
  • 1
  • 7
  • 24
  • This information correlates with the "*i cannot see any signal transmitted (the line is always at 0V)*" symptom. – sawdust May 09 '23 at 21:17
0
  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.
0___________
  • 60,014
  • 4
  • 34
  • 74
0

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.

  • You really need to rephrase it. I read it 3 times and I have still no idea what you meant. Draw a diagram of electrical connections for every scenario, clearly indicate what works and what doesn't. What do you mean you tried to use USB and not Tx pin? Please, write 3 more sentences explaining what exactly that phrase means. – Ilya May 10 '23 at 11:41