Skip to main content
CUluw.1
Visitor II
April 1, 2022
Question

How can I send an array of bytes using UART?

  • April 1, 2022
  • 4 replies
  • 2723 views

I need to send 4 bytes of data (array of 4 bytes) to the PC using UART. How to do this?

Thank you

This topic has been closed for replies.

4 replies

mƎALLEm
Technical Moderator
April 1, 2022

Hello,

Refer to one of the examples provided in CubeF/H.

For example fir STM32F4 product, download CubeF4 and refer to the examples provided under \Projects\STM32469I_EVAL\Examples\UART, There are at least two examples one using interrupt and the other using DMA.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
raptorhal2
Lead
April 1, 2022

And use for example a USB to UART adapter cable. You may have to make your own connection to the MCU.

And use for example a serial terminal program such as Termite to receive the data in hex or character format.

Cheers, Hal

Guenael Cadier
ST Employee
April 1, 2022

Hello @CUluw.1​ 

First you need to identify which U(S)ART instance you will be using (if you use a STM32 boards as Nucleo, there's usually one UART/USART or LPUART instance dedicated to communication between the target STM32 and the ST-LINK, to support the Virtual COM port.

You could use STM32CubeMx to generate code for UART instance initialisation (that will generate call to HAL_UART_Init API, according to settings you defined, as baudrate, parity, wordlength, ...)

Once initialized, you could use HAL_UART_Transmit (in polling mode), HAL_UART_Transmit_IT (in interrupt mode) or HAL_UART_Transmit_DMA (in DMA mode) to transmit your data using the selected UART.

Please check available code examples delivered in STM32Cube FW packages. even if not available for your specific board, you could have a look at user application code (which should be board independent).

For instance, you could have a look here where several examples of transmission over UART using interrupts or DMA are shown.

Hope this helps.

Regards

S.Ma
Principal
April 2, 2022

More context, is it an ST board or a custom one? Which STM32?