Docs

Micro-controllers, wireless transmission and database

Head

Nextion Display to STM32 Nucleo with STM32F446RE using STM32CubeIDE

Prerequisites

This project assumes you have already installed STM32CubeIDE. You need to have previously done a basic blink sketch with Nucleo STM32F446RE using STM32CubeIDE. I have made a complete video from installing STM32CubeIDE to LED blink program. You can watch it by clicking this link. https://www.youtube.com/watch?v=oAwZ0cjlmN8

Wiring Diagram

Diagram

STM32CubeIDE Settings

Enable UART4 asynchronous

Parameter Settings --> Basic Parameters --> Baud rate 9600

NVIC Settings --> USART4 global interrupt --> (Tick)

Additional code on top of STM32CubeIDE generated code

/* USER CODE BEGIN Includes */
#include "string.h"
/* USER CODE END Includes */
/* USER CODE BEGIN 0 */
uint8_t rxBuffer[20] = {0};
uint8_t rxIndex = 0;
uint8_t rxData;
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
  if(huart->Instance==UART4)
  {
  // if the character received is other than hex FF, store the data in rxBuffer
  if(rxData!=255) // Check if Hex ff
  {
    if(rxIndex==0)
    {
      memset(rxBuffer,0,sizeof(rxBuffer));
    }
    rxBuffer[rxIndex++]=rxData;
  }
  else
  {
    rxIndex=0;
  }
  HAL_UART_Receive_IT(&huart4,&rxData,1); // Enabling interrupt receive again
  }
}
/* USER CODE END 0 */
/* USER CODE BEGIN 2 */
HAL_UART_Receive_IT(&huart4,&rxData,1);
/* USER CODE END 2 */