cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 F767Zi RS485 interrupt code blocks main() loop

KMale.1
Associate II

I am using STM32 F767zi MC and I want to communicate with RS485 encoder.

This is my code which has written in stm32f7xx_it.c. When executing this code, it can be seen that encoder and MC communicating continuously (observed using oscilloscope). But my problem is when executing this code, infinity loop inside my main loop is blocked. Could you please help me to solve this matter?

Thank you.

void USART2_IRQHandler(void)

{

 /* USER CODE BEGIN USART2_IRQn 0 */

 /* USER CODE END USART2_IRQn 0 */

 HAL_UART_IRQHandler(&huart2);

 /* USER CODE BEGIN USART2_IRQn 1 */

 HAL_RS485Ex_Init(&huart2, UART_DE_POLARITY_HIGH, 1/16, 1/16);

 if(__HAL_UART_GET_IT(&huart2, UART_IT_TXE)==SET){

 HAL_GPIO_WritePin(GPIOD, GPIO_PIN_4, 1); //DE ON

   USART2->TDR = TxBuf[0];

  __HAL_UART_ENABLE_IT(&huart2, UART_IT_TC);

__HAL_UART_DISABLE_IT(&huart2, UART_IT_TXE);

while(__HAL_UART_GET_IT(&huart2, UART_IT_TC)!=SET)

;

HAL_GPIO_WritePin(GPIOD, GPIO_PIN_4, 0); //DE OFF

int j=0;

while(j<3){

if(__HAL_UART_GET_IT(&huart2, UART_IT_RXNE)==SET){

RxBuf[j] = USART2->RDR;

j++;

}

}

__HAL_UART_DISABLE_IT(&huart2, UART_IT_TC);

__HAL_UART_CLEAR_FLAG(&huart2, UART_FLAG_TC);

__HAL_UART_DISABLE_IT(&huart2, UART_IT_RXNE);

 

 }

 /* USER CODE END USART2_IRQn 1 */

}

3 REPLIES 3
TDK
Guru

You're performing blocking operations from within the interrupt, preventing the mcu from making any progress in the main loop.

If you feel a post has answered your question, please click "Accept as Solution".

Thank you for the reply. Is it because of the while loops that the blocking mode perform?

Anything that prevents the IRQHandler from completing is considered blocking. In this case, it's the while loop and what you're doing inside.
If you feel a post has answered your question, please click "Accept as Solution".