Serial data reception using UART
We already discussed data transmission using UART where we sent the data from microcontroller to the computer. Today I will show you how to receive data using UART and display it on LCD.
Here I will connect LCD with PCF8574 using I2C. You can check my previous tutorial here if you haven't did it yet.
Basically what I am going to do is, i will send data using a serial monitor from the computer and that data will be displayed on the LCD. We can do this using two ways:-
1.) We continuously check for incoming data and when data is received, display it on the lcd.
2.) Use interrupt. Microcontroller does it's normal operations, and whenever the data receiving completes, an interrupt is generated and ISR is executed, after completing ISR, control returns back to normal operation.
1.) We continuously check for incoming data and when data is received, display it on the lcd.
2.) Use interrupt. Microcontroller does it's normal operations, and whenever the data receiving completes, an interrupt is generated and ISR is executed, after completing ISR, control returns back to normal operation.
Some insight into the code:-
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
is a receive complete callback function. When the data is received via UART, this function is called. So in order to display data on LCD, we have to write our code inside this function.
UART_HandleTypeDef *huart is the handletype of UART we are using
uint8_t *pData is the pointer to the variable, where data need to be stored
uint16_t Size is the size in bytes
CODE IS AT THE END OF THE POST
I am going to use I2C to connect LCD with the Nucleo using PCF8574. Also I will use COMPIM in proteus to communicate with Nucleo. Here is my proteus setup
NOTE:- To go to next line on LCD, simply type goto2 and to clear the whole screen type clear.
This is it guys, Hope you understood the process. Feel free to comment in case of any doubt.
TO DOWNLOAD FULL CODE, VISIT
http://controllerstech.com/receiving-serial-data-in-stm32/
CHECK OUT THE VIDEO BELOW
if (huart->Instance == USART2)
checks whether the data received is from UART2 ?HAL_UART_Receive_IT (&huart2, Rx_data, 1)
enables the interrupt receive function. Whenever the data is received, an interrupt will be generated and ISR will be served. This function takes the following arguments:-UART_HandleTypeDef *huart is the handletype of UART we are using
uint8_t *pData is the pointer to the variable, where data need to be stored
uint16_t Size is the size in bytes
CODE IS AT THE END OF THE POST
I am going to use I2C to connect LCD with the Nucleo using PCF8574. Also I will use COMPIM in proteus to communicate with Nucleo. Here is my proteus setup
NOTE:- To go to next line on LCD, simply type goto2 and to clear the whole screen type clear.
This is it guys, Hope you understood the process. Feel free to comment in case of any doubt.
TO DOWNLOAD FULL CODE, VISIT
http://controllerstech.com/receiving-serial-data-in-stm32/
CHECK OUT THE VIDEO BELOW
Serial data reception using UART
Reviewed by Controllerstech
on
July 17, 2017
Rating:
No comments: