Help with clearing UART interrupt

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

I have an external interrupt attached to the SCB UART2 (PSOC 4200)

   

The interrupt is external and using the buffer size of 8.

   

The only interrupt flag I have enabled in the component is RX FIFO NOT EMPTY 

   

I am having trouble understanding the correct syntax to clear the interrupt when it is fired.

   

I want to interupt on each incoming byte an dpop it into a buffer (the code method works fine on PSOC 5LP).

   

Here is my interrupt routine, once triggered, I get correct data in the buffer but the interrupt flag never cxlears and program stays inside the int routine forever.

   

Any help much appreciated. Once again, variables are volatile and I have looked at several posts on Cypress but cannot understand how to clear the int. If there are more than 1 byte in buffer, do I need to explicitly read them all out or can the Clear FIFO API do this???

   

 

   

CY_ISR(RF_INT){
  uint16 rec_data;
  uint32 intsrc;

   

  rec_data = Uart2_UartGetByte();

   

   intsrc = Uart2_GetInterruptCause();

   

   if(rec_data < 0x0100){  //no errors if MSB = 0

   

     switch(RF.Mode){

   

        case state_IDLE : 

   

                  RF.Mode = state_RECEIVING;

   

  RF.DataBytes = 0;

   

        case state_RECEIVING : 

   

  RF.Buf[RF.DataBytes++] = (uint8) rec_data;

   

  if(RF.DataBytes > (RF_MAXPACKETSIZE-1)) RF.Mode = state_IDLE;

   

        }

   

    }

   

    Uart2_CLEAR_RX_FIFO;

   

    Uart2_ClearRxInterruptSource(intsrc);

   

 }

0 Likes
4 Replies
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 OK, got I needed to used the 'Masked" source to clear the intterupt. Finally 🙂

   

intsrc = Uart2_GetRxInterruptSourceMasked();

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

This should not be the cause of a non-working interrupt reset. In your first case you get every interrupt that has occured and clear it (them), in the second case you only get the interrupt allowed (unmasked) which you clear later. Since the masked-off interrupts (rather: states) do not fire an interrupt you just reset the states that have been flagged.

   

 

   

Bob

0 Likes
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 I am not sure what "should" be but can report what happend, changing that one line of code to obtain the source for masked rx interrupt fixed the issue. The routine now exits fine and it entered again when new data arrives.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I dwelt a bit deeper: We both are right.

   

Your call to GetInterruptCause() is wrong, it returns completely different status flags than GetRxInterruptSource() or GetRxInterruptSourceMasked() will. Clearing the interrupts with the wrong flags will not work, but using GetRxInterruptSource() will work.

   

 

   

Bob

0 Likes