Skip to main content
Iatik.1
Associate II
August 3, 2020
Question

uart interrupt repeat

  • August 3, 2020
  • 1 reply
  • 612 views

Hello friends

I'm communicating with uart.

finishing operations on interrupt and while going back

but does not go back to interrupt

my codes

while (1)
 {
 /* USER CODE END WHILE */
 
 /* USER CODE BEGIN 3 */
		for(int i=0; i<7; i++)
		{
			rx_buffer[i]='\0';
		}
 
	 HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_RESET);
	 HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_RESET);
	 HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_RESET);
	 HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_RESET);
 
	 HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_SET);
	 HAL_Delay(1000);
	 HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_RESET);
	 HAL_Delay(1000);
 }
 /* USER CODE END 3 */
}

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
	if(huart->Instance==USART2)
	{
		reg_CTS = __HAL_UART_GET_FLAG(&huart2,UART_FLAG_CTS);
		reg_LBD = __HAL_UART_GET_FLAG(&huart2,UART_FLAG_LBD);
		reg_TXE = __HAL_UART_GET_FLAG(&huart2,UART_FLAG_TXE);
		reg_TC = __HAL_UART_GET_FLAG(&huart2,UART_FLAG_TC);
		reg_RXNE = __HAL_UART_GET_FLAG(&huart2,UART_FLAG_RXNE);
		reg_IDLE = __HAL_UART_GET_FLAG(&huart2,UART_FLAG_IDLE);
		reg_ORE = __HAL_UART_GET_FLAG(&huart2,UART_FLAG_ORE);
		reg_NE = __HAL_UART_GET_FLAG(&huart2,UART_FLAG_NE);
		reg_FE = __HAL_UART_GET_FLAG(&huart2,UART_FLAG_FE);
		reg_PE = __HAL_UART_GET_FLAG(&huart2,UART_FLAG_PE);
 
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);
 
		if(rx_buffer[0]==0x65 && rx_buffer[1]==0x00 && rx_buffer[2]==0x01 && rx_buffer[3]==0x01 &&
		 rx_buffer[4]==0xFF && rx_buffer[5]==0xFF && rx_buffer[6]==0xFF)
			{
			 count++;
			}
 
		if(rx_buffer[0]==0x65 && rx_buffer[1]==0x00 && rx_buffer[2]==0x02 && rx_buffer[3]==0x01 &&
		 rx_buffer[4]==0xFF && rx_buffer[5]==0xFF && rx_buffer[6]==0xFF)
			{
			 count++;
			}
 
//		for(int i=0; i<7; i++)
//		{
//			rx_buffer[i]='\0';
//		}
 
		HAL_GPIO_WritePin(GPIOD, GPIO_PIN_13, GPIO_PIN_SET);
	}
	HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_SET);
}

and register

https://linkpicture.com/q/LPic5f2786346b1af1499878664.jpg

This topic has been closed for replies.

1 reply

KnarfB
Super User
August 4, 2020

I don't see HAL_UART_Receive_IT in your code. For each HAL_UART_Receive_IT, HAL_UART_RxCpltCallback is called once when the specified number of bytes were read.