This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2541: Simple BLE peripheral example false interrupt trigger

Part Number: CC2541

Hi,I have an rising edge interrupt  on P0.5.  I wake up the system on P0.5  and insdie the Port 0 ISr handler I clear the (port 0.5) P0IEN bit to disable the interrupt and I re-enable the interrupt when I go to sleep again. But there seems to be a false trigger when I reanable the interrupt  i.e. setting P0IEN for P0.5. I see the ISR being called again due to a trigger as soon as I re-enable the interrupt. Am I missing something here? Is there a trigger supposed to happen after enabling the interrupt register?? I also see P0IF flag being set in IRCON indicating that interrupt is pending, which is not supposed to happen?

Please let me know.

Thanks,

Venkat

  • Hi,

    Could you post a code snippet of what you are actually doing? More context would help.

  • Hello,

    You need to clear the interrupt flag P0IFG, before you re-enable the interrupt.

    Please refer to the User's Guide (SWRU191F):

    When an interrupt condition occurs on one of the I/O pins, the interrupt status flag in the corresponding
    P0–P2 interrupt flag register, P0IFG, P1IFG, or P2IFG, is set to 1. The interrupt status flag is set
    regardless of whether the pin has its interrupt enable set. When an interrupt is serviced, the interrupt
    status flag is cleared by writing a 0 to that flag. This flag must be cleared prior to clearing the CPU port
    interrupt flag (PxIF). This is illustrated in Figure 2-4: There is an edge detect between the input line and
    PxIFG, but no edge detect or one-shot between PxIFG and PxINT. The practical impact of this is what is
    written in Section 2.5.1

  • Here is my code once an interrupt is triggered I enter the ISR clear the interrupt status flag and CPU port flag and disable interrupt for P.5 using P0IEN &= ~0x20; in my event handler. 

    //ISR handler

    HAL_ENTER_ISR();
    P0IFG &= ~0x20;
    IRCON &= ~0x20;

    //Call an event that disables the interrupt

    HAL_EXIT_ISR();

    And I reenable the interrupt from a seperate task event before the system goes to sleep.

    P0IEN |= 0x20; // interupt enable

    So after enabling the interrupt I was receiving an interrupt immediately even though there is nothing active in that pin.    

    ===================================

    Thanks Eirik,

    Clearing the interrupt flag P0IFG, just before re-enabling the interrupt(in my task event)  worked. But as mentioned earlier I am already clearing P0IFG in my ISR handler. May I Know why is that not enough ?? and why do I have to clear the P0IFG just before renabling P0IEN. 

    Is it possible that I recieved a bounce on the interrupt line and I received another interrupt between the time when I cleared my P0IFG in my ISR handler

    and the time when I re-enabled P0IEN??

    Please let me know.

    Thanks again,

    Venkat

  • Thank you Severin. 

    Here is my code once an interrupt is triggered I enter the ISR clear the interrupt status flag and CPU port flag and disable interrupt for P.5 using P0IEN &= ~0x20; in my event handler. 

    //ISR handler

    HAL_ENTER_ISR();
    P0IFG &= ~0x20;
    IRCON &= ~0x20;

    //Call an event that disables the interrupt

    HAL_EXIT_ISR();

    And I reenable the interrupt from a seperate task event before the system goes to sleep.

    P0IEN |= 0x20; // interupt enable

    So after enabling the interrupt I was receiving an interrupt immediately even though there is nothing active in that pin.    

    But Eirik's suggestion fixed it. Thanks anyways. Appreciate it.