2022-04-01 07:06 AM
I need to send 4 bytes of data (array of 4 bytes) to the PC using UART. How to do this?
Thank you
2022-04-01 07:28 AM
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.
2022-04-01 07:34 AM
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
2022-04-01 07:38 AM
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
2022-04-02 11:50 AM
More context, is it an ST board or a custom one? Which STM32?