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

“hello World!” is transmitted from microcontroller to the computer and is being displayed on a serial window.
Check out the VIDEO Below


. . . . . DOWNLOAD . . . . .

You can buy me a coffee Sensor by clicking DONATE OR Just click DOWNLOAD to download the code

controllerstech
100%
100%
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Menu