EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Interrupt after UART RX

Started by gusgl2001 February 9, 2008
Hello,

I am trying to change the flow of my program by receiving a character
on UART. The UART interrupt is successful.

My code:

_BIS_SR(LPM0_bits + GIE);

if(mode != 1)
{

return 0; // Exits function
}

Now the interrupt routine:

#pragma vector=UART0RX_VECTOR
__interrupt void usart0_rx (void)
{
mode = 0
}

Then what should happen is that the MSP430 should wait at the setting
of LPM0 and then the interrupt occurs. After that it should start at
the if(mode != 1) line and execute it, causing the function to return.
But, what happens (by following using debugging) is that the system
actually goes to sleep on the if(mode != 1) line. This I know because
I run the program with F5 and press on break and it breaks on that
line(which means it is the next one to execute). The problem is that
the interrupt occurs and mode the variable changes and then the red
line jumps to the if condition but the if condition is never executed.
Normally when I've debugged programs it would stop on the line setting
the power mode and the next line couldn't be executed.

I've tried in the interrupt exiting from LPM0 by _BIS_SR_IRQ(LPM0_bits);
I've also tried clearing the flag for the UART RX.

Why is the microcontroller not executing the line code and just
ignoring it as if it should go to LPM0 again? Am I missing something?

Thank you

Beginning Microcontrollers with the MSP430

--- In m..., "gusgl2001" wrote:
>
> Hello,
>
> I am trying to change the flow of my program by receiving
> a character on UART. The UART interrupt is successful.
>
> My code:
>
> _BIS_SR(LPM0_bits + GIE);
>
> if(mode != 1)
> {
>
> return 0; // Exits function
> }
>
> Now the interrupt routine:
>
> #pragma vector=UART0RX_VECTOR
> __interrupt void usart0_rx (void)
> {
> mode = 0
> }
>
> Then what should happen is that the MSP430 should wait at
> the setting of LPM0 and then the interrupt occurs. After
> that it should start at the if(mode != 1) line and execute
> it, causing the function to return.
> But, what happens (by following using debugging) is that
> the system actually goes to sleep on the if(mode != 1)
> line. This I know because I run the program with F5 and
> press on break and it breaks on that line(which means
> it is the next one to execute). The problem is that
> the interrupt occurs and mode the variable changes and
> then the red line jumps to the if condition but the if
> condition is never executed. Normally when I've debugged
> programs it would stop on the line setting
> the power mode and the next line couldn't be executed.
>
> I've tried in the interrupt exiting from LPM0 by
> _BIS_SR_IRQ(LPM0_bits);

*** You should have used _BIC_SR_IRQ(LPM0_bits); ***

> I've also tried clearing the flag for the UART RX.
>
> Why is the microcontroller not executing the line code and
> just ignoring it as if it should go to LPM0 again? Am I
> missing something?

*** Yes, returning from the interrupt will restore the SR to its
original value which was stored in the stack. This puts the CPU back
to LPM0 again. That is why you need to clear the "LPM0_bits" in the
copy of the SR stored in the stack. You should have used "BIC" instead
of "BIS" as shown earlier.

*** By the way "LPM0_bits" is actually just a single bit (not bits)
aka CPUOFF. ***
Thanks a lot.
I used to use the commands exit lpm3 or something similar.
For some reason I switched to using _BIS and I didn't realize there
was a _BIC( for clear).

--- In m..., "old_cow_yellow"
wrote:
>
> --- In m..., "gusgl2001" wrote:
> >
> > Hello,
> >
> > I am trying to change the flow of my program by receiving
> > a character on UART. The UART interrupt is successful.
> >
> > My code:
> >
> > _BIS_SR(LPM0_bits + GIE);
> >
> > if(mode != 1)
> > {
> >
> > return 0; // Exits function
> > }
> >
> > Now the interrupt routine:
> >
> > #pragma vector=UART0RX_VECTOR
> > __interrupt void usart0_rx (void)
> > {
> > mode = 0
> > }
> >
> > Then what should happen is that the MSP430 should wait at
> > the setting of LPM0 and then the interrupt occurs. After
> > that it should start at the if(mode != 1) line and execute
> > it, causing the function to return.
> > But, what happens (by following using debugging) is that
> > the system actually goes to sleep on the if(mode != 1)
> > line. This I know because I run the program with F5 and
> > press on break and it breaks on that line(which means
> > it is the next one to execute). The problem is that
> > the interrupt occurs and mode the variable changes and
> > then the red line jumps to the if condition but the if
> > condition is never executed. Normally when I've debugged
> > programs it would stop on the line setting
> > the power mode and the next line couldn't be executed.
> >
> > I've tried in the interrupt exiting from LPM0 by
> > _BIS_SR_IRQ(LPM0_bits);
>
> *** You should have used _BIC_SR_IRQ(LPM0_bits); ***
>
> > I've also tried clearing the flag for the UART RX.
> >
> > Why is the microcontroller not executing the line code and
> > just ignoring it as if it should go to LPM0 again? Am I
> > missing something?
>
> *** Yes, returning from the interrupt will restore the SR to its
> original value which was stored in the stack. This puts the CPU back
> to LPM0 again. That is why you need to clear the "LPM0_bits" in the
> copy of the SR stored in the stack. You should have used "BIC" instead
> of "BIS" as shown earlier.
>
> *** By the way "LPM0_bits" is actually just a single bit (not bits)
> aka CPUOFF. ***
>
Actually, the header file says:

#define LPM0_EXIT _BIC_SR_IRQ(LPM0_bits)

--- In m..., "gusgl2001" wrote:
>
> Thanks a lot.
> I used to use the commands exit lpm3 or something similar.
> For some reason I switched to using _BIS and I didn't realize there
> was a _BIC( for clear).
> --- In m..., "old_cow_yellow"
> wrote:
> >
> > --- In m..., "gusgl2001" wrote:
> > >
> > > Hello,
> > >
> > > I am trying to change the flow of my program by receiving
> > > a character on UART. The UART interrupt is successful.
> > >
> > > My code:
> > >
> > > _BIS_SR(LPM0_bits + GIE);
> > >
> > > if(mode != 1)
> > > {
> > >
> > > return 0; // Exits function
> > > }
> > >
> > > Now the interrupt routine:
> > >
> > > #pragma vector=UART0RX_VECTOR
> > > __interrupt void usart0_rx (void)
> > > {
> > > mode = 0
> > > }
> > >
> > > Then what should happen is that the MSP430 should wait at
> > > the setting of LPM0 and then the interrupt occurs. After
> > > that it should start at the if(mode != 1) line and execute
> > > it, causing the function to return.
> > > But, what happens (by following using debugging) is that
> > > the system actually goes to sleep on the if(mode != 1)
> > > line. This I know because I run the program with F5 and
> > > press on break and it breaks on that line(which means
> > > it is the next one to execute). The problem is that
> > > the interrupt occurs and mode the variable changes and
> > > then the red line jumps to the if condition but the if
> > > condition is never executed. Normally when I've debugged
> > > programs it would stop on the line setting
> > > the power mode and the next line couldn't be executed.
> > >
> > > I've tried in the interrupt exiting from LPM0 by
> > > _BIS_SR_IRQ(LPM0_bits);
> >
> > *** You should have used _BIC_SR_IRQ(LPM0_bits); ***
> >
> > > I've also tried clearing the flag for the UART RX.
> > >
> > > Why is the microcontroller not executing the line code and
> > > just ignoring it as if it should go to LPM0 again? Am I
> > > missing something?
> >
> > *** Yes, returning from the interrupt will restore the SR to its
> > original value which was stored in the stack. This puts the CPU back
> > to LPM0 again. That is why you need to clear the "LPM0_bits" in the
> > copy of the SR stored in the stack. You should have used "BIC" instead
> > of "BIS" as shown earlier.
> >
> > *** By the way "LPM0_bits" is actually just a single bit (not bits)
> > aka CPUOFF. ***
>

The 2024 Embedded Online Conference