Serial Transmission in Stm32
As the title says, today we will see how to use UART for serial communication in STM32 devices. I am going to use STM32CubeMx to generate necessary code and than edit the code in Keil uvision 5.
UART is widely used for serial communication between two devices. It is easy to use protocol, because the clock sync is not involved. All you have to do is take care of BAUD RATE. BAUD RATE must be same for both devices, amongst which communication is done. I am going to use 9600 as it is standard.
1.) Select the UART you want to use for communication. I am using UART2.
2.) In the ‘configuration’ tab, make sure USART settings are as follows.
- Here we will use HAL_UART_Transmit to transmit the given data every second.
- The parameters of this function are :-
- The pointer to the handle of the UART i.e huart2
- Pointer to the data that you want to send i.e data
- The size of the data i.e 14 bytes
- And finally the timeout (in ms) in case of any errors i.e 50 ms