Serial Transmission in Stm32
As the title says, today I am going to show you 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.
CubeMX Setup
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.
Some Insight into the Code
uint8_t data[] = "HELLO WORLD!\n"; int main(void) { HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); MX_USART2_UART_Init(); while (1) { HAL_UART_Transmit (&huart2, data, 14, 50); HAL_Delay (1000); // wait for 1 sec } }
Here we are transferring the data every 1 second
Result

. . . . . DOWNLOAD . . . . .
You can buy me a
controllerstechcoffeeSensor by clicking DONATE OR Just click DOWNLOAD to download the code
100%
Recent Posts
- STM32F103 Clock Setup using Registers March 3, 2021
- STM32 I2C Configuration using Registers February 26, 2021
- EEPROM and STM32 February 24, 2021
- FreeRTOS Tutorials #8 -> Software Timers February 14, 2021
- WavePlayer using STM32 Discovery January 16, 2021
- How to use SPI in LPC2148 December 26, 2020