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.

MSP430F5438 & interrupts



Is there some mechanism through which an interrupt service routine can detect that the CPU was in a low power mode at the time of the interrupt?

In my application, the CPU spends as much time as possible in LPM3. Some of my interrupts are simply indicators that an event has occurred that should be processed in active mode; not in the interrupt service routine.   Using IAR 4.20 C++, I use the intrinsic    __low_power_mode_3 () to enter low power mode and within the interrupt service routines I use  __low_power_mode_off_on_exit () when I need to return the CPU to active mode.

The problem is that I should not use __low_power_mode_off_on_exit ()  if the CPU was not in LPM3 when the interrupt occurred.  I can think of no safe way to to make this determination unless the CPU itself sets a flag bit somewhere.

Has anyone worked out a solution to this problem?

  • Matthew,

    See page 23 of the User's Guide. It explains what happens when an interrupt is processed. Specifically what happens to the Status Register contents. The status register contains the bits that determine what operating mode the MSP430 is in.

    When the MSP430 services an interrupt the Status Register bits are pushed onto the stack, so in your ISR you can determine what mode you were in prior to enterring that interrupt service routine.

  • Thank you once again, Brandon.

    I've verified that the SR on the stack does contain the information I need.  Now I just need to work out the IAR stack frame or write my interrupt routines in assembly.

    I appreciate your help!

     

     

  • The IAR compiler guys provide the __get_SR_register_on_exit () intrinsic to manage just this task.

  • I think there is no problem to begin with.

    If the CPU was not in LPM when the interrupt occurred, using __low_power_mode_off_on_exit() does not do any harm.

    What you said you are going to do is: you are going to check if the LMP bits in the stacked SR to make sure that they are not 0 before you attempt to clear them to 0. This is un-necessary. If they are already 0, clearing them does not do any harm.

     

     

  • I think you're right about that.

    As a C++ user, I generally stick with the published interfaces rather than  their actual implementations; that gives the compiler writers the freedom they need to adapt and me the assurance of correctness.

    Thank you for the explanation; You have added to my knowledge base!

**Attention** This is a public forum