We have 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.
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.
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. 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
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
You can buy me a
coffee sensor 🙂
download the CODE below