Interrupt problem

Help
pusher462
2006-11-23
2013-03-06
  • pusher462

    pusher462 - 2006-11-23

    Hi all,

    I've got a problem with my MSP430F437.
    Given a simple while loop:

    ...
    while (var==0)
    {
       _BIS_SR(LPM3_bits);   // enter LPM3 mode
    }
    ...

    Inside a port ISR, I set the variable "var" to 1, if a button is pressed:

    ...
    interrupt (PORT2_VECTOR) port2_handler()
    {
      var = 1;                            
      _BIC_SR_IRQ(LPM3_bits);                 // Exit LPM3 on ISR exit
    }
    ...

    So in my opininon, the while loop should be left if a button is pressed, because "var" doesn't have any longer the value 0. Unfortunately, this doesn't happen! When I debug the program step-by-step, the program execution always stays in the while loop after exiting the port ISR, and the MSP falls into LPM3 again.

    Has anybody an idea why this doesn't work correctly? Thanks in advance!

    Regards
    Thorsten

     
    • Peter Kernebone

      Peter Kernebone - 2006-11-23

      var would have to declared as volatile for your code to work.

      eg:
      volatile int var;

       
      • pusher462

        pusher462 - 2006-11-24

        Thanks a lot, Peter! Now my code does exactly what it is supposed to do.

        Greets
        Thorsten

         

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks