UART_HandleTypeDef huart2;
/* USER CODE BEGIN PV */
char rx_buffer[50] , tx_buffer[50] ;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART2_UART_Init(void);
/ USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------/
/ USER CODE BEGIN 0 */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_5);
if(huart==&huart2)
{
HAL_UART_Receive_IT(&huart2, (uint8_t *)rx_buffer, 50);
}
}
/* USER CODE END 0 */
/**
- @brief The application entry point.
-
@retval int
/
int main(void)
{
/ USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
__HAL_UART_ENABLE_IT(&huart2, UART_IT_RXNE);
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals /
MX_GPIO_Init();
MX_USART2_UART_Init();
/ USER CODE BEGIN 2 */
HAL_UART_Receive_IT(&huart2, (uint8_t *)rx_buffer, 50);
/* USER CODE END 2 */
/* Boot CPU2 */
HAL_PWREx_ReleaseCore(PWR_CORE_CPU2);
/* Infinite loop /
/ USER CODE BEGIN WHILE */
while (1)
{
if(rx_buffer[0] == ‘l’ && rx_buffer[1] == ‘e’ && rx_buffer[2] == ‘d’ && rx_buffer[3] == ‘1’ && rx_buffer[4] == ‘o’ && rx_buffer[5] == ‘n’)
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET);
HAL_UART_Receive_IT(&huart2,(uint8_t*) “LED ON\r\n”, 50);
}
else if(rx_buffer[0] == ‘l’ && rx_buffer[1] == ‘e’ && rx_buffer[2] == ‘d’ && rx_buffer[3] == ‘1’ && rx_buffer[4] == ‘o’ && rx_buffer[5] == ‘f’ && rx_buffer[6] == ‘f’)
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_RESET);
HAL_UART_Receive_IT(&huart2,(uint8_t*) “LED OFF\r\n”, 50);
}
I am using Lora E5 Dev Board. This is how I code in uart communication using interrupt but I couldn’t. I will be glad if you help.