cancel
Showing results for 
Search instead for 
Did you mean: 

UART Transmit Interrupt disable while keeping the Receive Interrupt alive

phkloth
Associate II

Hi all,

I have a question regarding the control of the UART interrupt on the STM32F4.

First let me describe the application:

int main(void)
{
 
SystemInit();
 
//Stream out Data via Uart via DMA
HAL_UART_Transmit_DMA(&huart2, (uint8_t *)UARTMessage_out, MSGLENGTH);	
//Enable UART Rx interrupt in order to receive messages over Terminal
HAL_UART_Receive_IT(&huart2, dataRx, 1);									
 
  /* Infinite loop */
  while (1)
  {
 
    ADCRead();
    Computations();
    DACWrite();
   
   //In this section the transmit Interrupt is allowed to fire
    HAL_NVIC_EnableIRQ(DMA1_Stream6_IRQn);
    if(DMAReady == 1)
   {
    GenerateUARTMsg();
    DMAReady=0;
    UART_DMA_Transmit()
   }
    //here the UART transmit interrupt again disabled
    HAL_NVIC_DisableIRQ(DMA1_Stream6_IRQn);
 
    }
 
}
 
//Callback when MCUout/PCin Message is done
//Here the time between two Messages is measured
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
 	timer = __HAL_TIM_GetCounter(&htim2);			
	__HAL_TIM_DISABLE(&htim2);
	__HAL_TIM_SetCounter(&htim2,0);					//reset counter back to zero
 	DMAReady = 0;								/
 	__HAL_TIM_ENABLE(&htim2);
 }
 
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
 ProcessInput();
HAL_UART_Receive_IT(&huart2, dataRx, 1);
 }

Somehow the disable of the DMA interrupt (HAL_NVIC_DisableIRQ(DMA1_Stream6_IRQn);) does not work.

When I disable the whole uart interrupt via HAL_NVIC_EnableIRQ(USART2_IRQn) it works. But then also the receive interrupt is disabled. But the receive interrupt is allowed to fire all the time.

Background:

Uart transmit interrupt is for monitoring the adc values. This process shall not interrupt the ADC->Compute->DAC routine.

UART receive changes compute parameters. For this, the Data cycle is allowed to be interrupted.

Thanks in advance for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
phkloth
Associate II

Ok I found the solution for this problem.

I use the macros:

 __HAL_UART_ENABLE_IT(&huart2,UART_IT_TC);

and the

 __HAL_UART_DISABLE_IT(&huart2,UART_IT_TC);

Here the arg UART_IT_TC:  Transmission complete interrupt.

It works in this context. I dont know however if this is the best solution.

View solution in original post

2 REPLIES 2
phkloth
Associate II

Ahh stupid.

Of course in the transmit callback the flag must be

DMAReady=1;

Somehow I cannot edit the first post?

phkloth
Associate II

Ok I found the solution for this problem.

I use the macros:

 __HAL_UART_ENABLE_IT(&huart2,UART_IT_TC);

and the

 __HAL_UART_DISABLE_IT(&huart2,UART_IT_TC);

Here the arg UART_IT_TC:  Transmission complete interrupt.

It works in this context. I dont know however if this is the best solution.