cancel
Showing results for 
Search instead for 
Did you mean: 

UART example code in STM32F1 HAL library function not transmitting

Kmax18
Senior II

I attempt to use the ST example code 'UART_TwoBoards_ComPolling' that comes with the STM32CubeF1 library. (All ST examples are very helpful, thank you.)

Development environment used:

* Library: STM32Cube_FW_F1_V1.8.5.

* Hardware: two NUVLEO-F103RB boards (one for UART1_TX, one for UART1_RX).

* IDE: STM32CubeIDE Version: 1.12.1.

The example code is built two times, both for the TX Nucleo and for the RX Nucleo. That means, the UART1 peripherals on both boards are configured the same.

Problem:

The UART1_TX function does not seem to work in the function HAL_UART_Transmit():

/*##-2- Start the transmission process ######### */ 
if(HAL_UART_Transmit(&UartHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE, 5000)!= HAL_OK)
{
   Error_Handler();   
}

In particular, the IDE debugger shows that the UART data register (DR) does not change during the following char assignment, as the DR value is always shown as 0. See the Debugger screenshot at the bottom.

else
{
   huart->Instance->DR = (uint8_t)(*pdata8bits & 0xFFU);
   pdata8bits++;
}
huart->TxXferCount--;

Increasing the TX-buffer pointer (pdata8bits++) and the counter (TxXferCount++) works, so the correct characters should be written to the UART1->DR.

Question:

* How to confirm that DR is actually being updated?

* Should this work in Debug mode?

* Is the DR cleared immediately after transmitting the data?

Thank you!


_legacyfs_online_stmicro_images_0693W00000bl8yuQAA.png

1 ACCEPTED SOLUTION

Accepted Solutions
MOhamed_Mehery
Associate III

to troubleshoot the problem with the UART example code in the STM32F1 HAL library.

  • Make sure that the baud rate is correct. The baud rate is the speed at which data is transmitted over the UART. If the baud rate is not correct, the data will not be transmitted correctly.
  • Make sure that the data format is correct. The data format includes the number of bits per byte, the stop bits, and the parity bit. If the data format is not correct, the data will not be transmitted correctly.
  • Make sure that the UART is enabled. The UART can be enabled or disabled using the HAL_UART_Init() function. If the UART is not enabled, it will not transmit data.
  • Make sure that the UART is not in a fault state. The UART can enter a fault state if there is a problem with the hardware or the software. If the UART is in a fault state, it will not transmit data.

If you have checked all of these things and the UART is still not transmitting data, you may need to contact the manufacturer of the STM32F1 HAL library for further assistance.

Here are some additional things you can check:

  • Make sure that the UART pins are connected correctly. The UART pins are typically connected to the TXD and RXD pins on the target board.
  • Make sure that the UART is configured correctly in the target board's firmware. The UART configuration may need to be changed to match the settings in the STM32F1 HAL library.
  • Make sure that the UART is not being used by another application. If the UART is being used by another application, it may not be available for use by the STM32F1 HAL library.

View solution in original post

4 REPLIES 4
MOhamed_Mehery
Associate III

to troubleshoot the problem with the UART example code in the STM32F1 HAL library.

  • Make sure that the baud rate is correct. The baud rate is the speed at which data is transmitted over the UART. If the baud rate is not correct, the data will not be transmitted correctly.
  • Make sure that the data format is correct. The data format includes the number of bits per byte, the stop bits, and the parity bit. If the data format is not correct, the data will not be transmitted correctly.
  • Make sure that the UART is enabled. The UART can be enabled or disabled using the HAL_UART_Init() function. If the UART is not enabled, it will not transmit data.
  • Make sure that the UART is not in a fault state. The UART can enter a fault state if there is a problem with the hardware or the software. If the UART is in a fault state, it will not transmit data.

If you have checked all of these things and the UART is still not transmitting data, you may need to contact the manufacturer of the STM32F1 HAL library for further assistance.

Here are some additional things you can check:

  • Make sure that the UART pins are connected correctly. The UART pins are typically connected to the TXD and RXD pins on the target board.
  • Make sure that the UART is configured correctly in the target board's firmware. The UART configuration may need to be changed to match the settings in the STM32F1 HAL library.
  • Make sure that the UART is not being used by another application. If the UART is being used by another application, it may not be available for use by the STM32F1 HAL library.

Kmax18
Senior II

@MOhamed_Mehery​ thank you for your response. How to check if the UART is in a fault state?

Check the registers

The DR register is NOT a memory, it is a window on the logic of the UART.

A write to DR goes into a buffer and shift register for transmission.

What you read from DR is a similar arrangement on the RECEIVE side, so you're not looking at the data you wrote unless the pins externally loop back.

Also looking at DR in the Debugger will clear and change bit settings in SR, which reflect that received data has been read, and to now reflect that new data is available, or not.

You can read error and fault states, like framing, parity and noise, by inspecting SR. It is recommended that you have your code read this into a variable, and you then inspect the variable, in RAM

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