/* USER CODE BEGIN 0 */ uint8_t receiveBuffer[6]; uint8_t cmdReceived = 0; /* USER CODE END 0 */ ............... MX_USART1_UART_Init(); MX_TIM1_Init(); /* USER CODE BEGIN 2 */ LL_USART_EnableIT_RXNE(USART1); LL_USART_EnableIT_ERROR(USART1); /* USER CODE END 2 */ /* USER CODE BEGIN 4 */ void USART_CharReception_Callback(void){ static int bytes = 0; uint8_t received_char; received_char = LL_USART_ReceiveData8(USART1); if(received_char == '@'){ bytes = 0; cmdReceived = 1; } else{ receiveBuffer[bytes] = received_char; bytes++; } if (bytes == sizeof(receiveBuffer)){ bytes = 0; cmdReceived = 1; } } /* USER CODE END 4 */
In stm32g0xx_it.c:
/** * @brief This function handles USART1 global interrupt / USART1 wake-up interrupt through EXTI line 25. */ void USART1_IRQHandler(void) { /* USER CODE BEGIN USART1_IRQn 0 */ USART_CharReception_Callback(); /* USER CODE END USART1_IRQn 0 */ /* USER CODE BEGIN USART1_IRQn 1 */ /* USER CODE END USART1_IRQn 1 */ }