cancel
Showing results for 
Search instead for 
Did you mean: 

Uart buffer is not resetting to receive new data?

NHing.1
Associate III

Hello guys,

I previously asked the question about the UART interrupt but not get any reply.

Currently am able to receive data from uart interrupt but not able to clear the buffer to get new data.

please help.

my code is

void USART1_IRQHandler(void)
{
  /* USER CODE BEGIN USART1_IRQn 0 */
	char temp;
  /* USER CODE END USART1_IRQn 0 */
  HAL_UART_IRQHandler(&huart1);
 
  /* USER CODE BEGIN USART1_IRQn 1 */
 if(USART1->ISR & USART_ISR_RXNE)       //UART read data register not empty
 {
	 temp = USART1->RDR;                     //fetching data register
 
	 RX_buffer[m++] = temp;                  //storing data in buffer    
 
	 while(!(USART1->ISR & USART_ISR_TC));
 
 }
 
 
 
 }

When I send first AT command I receive data in the RX_buffer. when I send next AT+ command the incoming data get append to the previous output.

2 REPLIES 2
Piranha
Chief II

It does exactly what you have implemented. If you want it to reset the buffer, then implement it!

Anyway, joggling around without understanding is a dead-end. If you actually want to learn, then start with the basics:

  1. Learn the C: https://www.tutorialspoint.com/cprogramming/
  2. Learn the microcontrollers: https://www.embeddedrelated.com/showarticle/453.php
  3. Learn the UART: https://github.com/MaJerle/stm32-usart-uart-dma-rx-tx

No bounds checking on the buffer.

Doesn't reset the counter.

Hard loops randomly in the middle of the IRQHandler against an unrelated interrupt source, ie receiving, and blocking on transmit complete.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..