cancel
Showing results for 
Search instead for 
Did you mean: 

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

JJoy.1
Associate III

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?

11 REPLIES 11
Pavel A.
Evangelist III

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

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

Attached code not found.

PFA

PFA

JJoy.1
Associate III

Hi Pavel,

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

Thanks,

Jestina

JJoy.1
Associate III

Any update?

Pavel A.
Evangelist III

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
Associate III

Hi Pavel,

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

Jestina