AnsweredAssumed Answered

Interrupts - USART corrupted data

Question asked by Omar Suárez on Jul 4, 2017
Latest reply on Jul 6, 2017 by Omar Suárez

Hi everyone,

 

I am designing a system that needs a bunch of interrupts working. By now I have three possible source of interrupts working:

+ USART6

+ SPI2

+ TIM6

The USART6 works sending and receiving data from PC.

When SPI2 and TIM6 are not working the USART works with no problems, I can receive and send data prefectly.

The protocol between the PC and the system is this:

- I constantly send data packets to the PC until I receive an END data frame from it. At this moment I should stop sending packets and change to other state to make other tasks.

The problem is when I am using SPI and TIM interrupts: TIM is a timer to trigger and data over the SPI to another IC, while I need to send data to the PC using USART.

While the system sends data to PC all works OK, but when it tries to receive the END from the PC I go to an overrun error in the USART.

I am trying to configure the priority this way:

 

NVIC_SetPriorityGrouping(4);  

NVIC_SetPriority(USART6_IRQn, 0);
NVIC_SetPriority(TIM6_DAC_IRQn, 1);
NVIC_SetPriority(SPI2_IRQn, 1);

but still the same problem occurs.

 

I also tried to disable all the interrupt when entering the USART interrupt handler:

void USART6_IRQHandler(void)
{
    __set_BASEPRI(1 << (8 - __NVIC_PRIO_BITS));

  hal_uart_handle_interrupt(&uartHandle);
    
    __set_BASEPRI(0U); // remove the BASEPRI masking
}

but also the same problem.

 

I am not sure whether I need to configure anything else in the MCU to control the interrupts so I am stuck.

I need to say that I am not using the HAL from ST. I am using my own USART, SPI and TIM6 drivers.

 

Thanks in advanced,

Omar

Outcomes