Skip to main content
JJoy.1
Associate III
June 9, 2021
Question

Hi I am using STM32H7A3 Nucleo board. I am using uart receive in interrupt mode by enabling global interrupt.

  • June 9, 2021
  • 5 replies
  • 2640 views

After receiving some data through interrupt, Is there any way to disable interrupt mechanism and go back to blocking mode for receiving remaining data.

I tried NVIC_DisableIRQ(0 to disable interrupt.

After that when i tried to receive through blocking mode, it fails. I just need to know whether its possible in stm32?

This topic has been closed for replies.

5 replies

Pavel A.
Super User
June 9, 2021

Yes, blocking mode should work after using any of interrupt functions unless you've left the interrupt function unfinished

(not completed or canceled).

Also, disable RX overrun detection in UART initialization. It can cause problems.

But it is better to not use any HAL functions for UART, rather make your own.

--pa

JJoy.1
JJoy.1Author
Associate III
June 9, 2021
Hi,
Thanks for your response.
Please find attached code. What i am trying is read 5 characters from teraterm using UART interrupt method and stop interrupt after that. Then read 2 char by polling method.
But what i noticed is that after receiving 5 character through interrupt, the code is getting exited. It is not waiting for receiving 2 char. It would be great if you can help in this matter
Pavel A.
Super User
June 9, 2021

Attached code not found.

JJoy.1
JJoy.1Author
Associate III
June 10, 2021

Hi Pavel,

Can you please provide some solution for the attached code. I am using STM32H&A3 Nucleo board.

Thanks,

Jestina

JJoy.1
JJoy.1Author
Associate III
June 10, 2021

Any update?

Pavel A.
Super User
June 10, 2021

Hi @JJoy.1​ 

Your code unfortunately has so many mistakes that IMHO it's hardly workable and beyond easy fix.

Calling HAL_UART_Receive_IT in the IRQ handler is very strange.

HAL_UART_RxCpltCallback looks strange too.

If this is a student assignment, request better documentation or examples from your teachers.

void USART3_IRQHandler(void)
{
 /* USER CODE BEGIN USART3_IRQn 0 */
 
 /* USER CODE END USART3_IRQn 0 */
 HAL_UART_IRQHandler(&huart3);
 /* USER CODE BEGIN USART3_IRQn 1 */
 HAL_UART_Receive_IT(&huart3, status, 5);
 /* USER CODE END USART3_IRQn 1 */
}
 
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
 int j;
 for(j =0; j <5; j++)
 {
	 Serial_PutByte(status[j]);
	 resp =1;
 
 }
 NVIC_DisableIRQ(USART3_IRQn);
 __HAL_UART_DISABLE_IT(&huart3,UART_IT_RXNE);
}

In any case I'd recommend disabling RX overflow. Change in MX_USART3_UART_Init

the line with huart3.AdvancedInit.AdvFeatureInit and add the next one:

static void MX_USART3_UART_Init(void)
{
.......
 huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_RXOVERRUNDISABLE_INIT;
 huart3.AdvancedInit.OverrunDisable = UART_ADVFEATURE_OVERRUN_DISABLE;
 if (HAL_UART_Init(&huart3) != HAL_OK)
....................

Good luck.

-- pa

JJoy.1
JJoy.1Author
Associate III
June 10, 2021

Hi Pavel,

From where can i call the disabling function - NVIC_DisableIRQ(USART3_IRQn);

Jestina

Pavel A.
Super User
June 10, 2021

NVIC_DisableIRQ can be called anywhere.

But AFAIK there's no need to call NVIC_DisableIRQ(USART3_IRQn).

The UART interrupt handler in the HAL library (HAL_UART_IRQHandler) masks the UART RX interrupt at end of transfer.

JJoy.1
JJoy.1Author
Associate III
June 11, 2021

Thanks a lot Pavel for your valuable support. It was really helpful...