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.

CC2530: Interrupts and Sleep Mode

Other Parts Discussed in Thread: CC2530

 

I am concerned about the potential for a race condition between enabling global interrupts and putting the CC2530 to sleep.

As in:

    EA = 1;                                    // Enable global interrupts

    PCON = PCON_IDLE;        // Enter sleep mode

Is there a chance that an ISR could be invoked, before the device enters sleep mode?

 

Thanks,

Steve

 

  • Yes there is. You can handle this race condition as follows:

    Assign a variable (unsigned char) in data memory. First set this variable to 1, then enable interrupts, then set PCON equal to this variable (assigning an SFR to a variable in data memory is an atomic operation in an 8051). In all ISRs that can wake up the chip, you set the variable to 0. This way, if the interrupt is called before going to sleep, PCON will be set to 0, which has no effect.

    The attached files implements this, and also ensures that the alignment of the PCON operation in program memory is correct (cf. Section 4.2 of the user guide). Include the assembly file PowerMode.s51 in your project, and add #include "PowerMode.h" in the C file from which you go to sleep. Use the function EnterSleepModeProcessInterruptsOnWakeupUsingFlag() to enter sleep mode after having set EnterSleepModeFlag to 1, and set EnterSleepModeFlag to 0 in ISRs that can wake you up. If you want to wake up with interrupts disabled (to have common wake-up processing), use the function EnterSleepModeDisableInterruptsOnWakeupUsingFlag(). There are also two functions that do not use this flag.

    4353.PowerMode.zip