Skip to main content
Visitor II
July 24, 2020
Question

LL_USART_ClearFlag_RXNE(USART3) doesn't work properly but it worked normally when i use USART3->SR &= ~USART_SR_RXNE

  • July 24, 2020
  • 2 replies
  • 1692 views

i use stm32f407vgt chip with my own board design

and working on STM32CubeIDE_1.3.0

void USART3_IRQHandler(void)
{
 /* USER CODE BEGIN USART3_IRQn 0 */
 
	//USART3->SR &= ~USART_SR_RXNE;
	LL_USART_ClearFlag_RXNE(USART3);
 
	static unsigned char iteration,buffer[4],validation;
	unsigned char data;
 
	data = USART3->DR; // the character from the USART1 data register is saved in t
 
	dat3 = data;
	dat6 = validation;
 
	if(data == 'Z')
	{
		validation = 1;
		iteration = 0;
 
	}
 
	else if(validation == 1)
	{
 
		if(data == 'Y')
		{
			validation = 2;
 
		}
 
		else validation = 0;
	}
 
	else if(validation == 2)
	{
		buffer[iteration]=data;
		iteration++;
 
		if(iteration == 4)
		{
			//move to global variable
			acc_y = buffer[0];
			acc_x = buffer[1];
			gyro_p = buffer[2];
			gyro_r = buffer[3];
 
			//convert to signed integer
			if(acc_y >= 128) acc_y -= 256;
			if(acc_x >= 128) acc_x -= 256;
			if(gyro_p >= 128) gyro_p -= 256;
			if(gyro_r >= 128) gyro_r -= 256;
 
			//to get value 0 at default pose
			acc_x -= acc_x_offset;
			acc_y -= acc_y_offset;
			gyro_p -= gyro_p_offset;
			gyro_r -= gyro_r_offset;
 
			iteration = 0;
			validation = 0;
		}
	}
 
 
 /* USER CODE END USART3_IRQn 0 */
 /* USER CODE BEGIN USART3_IRQn 1 */
 
 /* USER CODE END USART3_IRQn 1 */
}

I prefer as much as possible using the default function in LL driver for good regeneration

    This topic has been closed for replies.

    2 replies

    Graduate II
    July 24, 2020

    Why do you even need to explicitly clear it? Reading UART->DR auto clears it, if it sets again there's new data.

    TZikr.1Author
    Visitor II
    July 24, 2020

    somehow I can't get out from the irq handler even if USART-> DR has been read

    Graduate II
    July 24, 2020

    Yeah, then something else is enabled and not satiated by your code. Perhaps TXE interrupt is enabled. Or some error status is flagged, and does need clearing.

    Normally you'd inspect the SR, not really providing sufficient info here to understand the cause of the problem, just the symptoms.

    TZikr.1Author
    Visitor II
    July 24, 2020

    Thank you very much for spending your time

    this is quite strange to me, it doesn't work on USART3 but it works well on UART5