Hello All I am implementing a simple application using STM32F205 and UART. I have enabled UART as global interrupt. I want the program to detect \r or \n in a string that is received continuously.
I wish to print "String recieved" if /r or /n is detecetd
otherwise i wish to print "Error" .The problem is after detecting the first string i receive an output "String Received" After which i also receive error message. I have doubt if i have implemented the __HAL_UART_ENABLE_IT(&huart3, UART_IT_RXNE) and enabled the HAL_UART_IRQ handler correctly,
I have used __HAL_UART_ENABLE_IT(&huart3, UART_IT_RXNE) function after initialising all the configured peripherals in CubeMx
<
/* USER CODE BEGIN PV */
uint8_t g_rx_receive_complete=0;
uint8_t g_rx_received_bytes=0;
char g_rx_buffer [10]={0};
char rx_buffer [10]={0};
/* USER CODE END PV */
/* USER CODE BEGIN PFP */
void check (void)
{
g_rx_buffer[g_rx_received_bytes]=(uint8_t)USART3->DR;
if((g_rx_buffer[g_rx_received_bytes]=='\n')||(g_rx_buffer[g_rx_received_bytes]=='\r'))
{
g_rx_buffer[g_rx_received_bytes]=='\0';
g_rx_receive_complete= 1;
}
else
{
if(g_rx_received_bytes<10)
g_rx_received_bytes++;
}
}
/* USER CODE END PFP */
while (1)
{
if (g_rx_receive_complete)
{
memcpy(rx_buffer, g_rx_buffer,sizeof(rx_buffer));
g_rx_receive_complete=0;
runCommand(rx_buffer);
/* USER CODE END WHILE */
}
>
In STM32f2xx_it.c I am calling the check function
<
void USART3_IRQHandler(void)
{
/* USER CODE BEGIN USART3_IRQn 0 */
check();
/* USER CODE END USART3_IRQn 0 */
HAL_UART_IRQHandler(&huart3);
/* USER CODE BEGIN USART3_IRQn 1 */
/* USER CODE END USART3_IRQn 1 */
}
>