I am using SPI communication to get the ADC values. I am using timer A for
writing data into SPI TX buffer (UCA0TXBUF). After every 100mS, data is
written into SPI buffer & read the values from SPI RX buffer. Note: Using
SMCLK, for SPI communication.
I am trying to go in LPM3 modes based on some ADC values in the while loop
of the main function. Then exit from LPM3 mode in TimerB.
Using following method for LPM3.
Method (1)
__bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable interrupts
__bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bits from 0(SR)
Method (2)
LPM3 // Enter LPM3,
LPM3_EXIT // Clear LPM3
The problem is after enter or exit of LPM3 mode(I am not too sure about),
the code does not go to while loop in main function. I have checked with
breakpoint that only ISR routine is getting executed but not the main
function.
Could anyone help how to enter & exit from LPM3 mode? How the program
restore it back to main function. Does any one have some literature about
LPM modes in MSP430F2xx?
Regards,
Dipti
--
LPM in MSP430F2xx
Started by ●August 4, 2009
Reply by ●August 4, 20092009-08-04
Hi,
You can code like this:
main()
{
while(1)
{
LPM3();
if(sem)
{
// do something;
}
}
}
and the "sem" is set in ISR:
// ADC10 interrupt service routine
#pragma vectorC10_VECTOR
__interrupt void ADC10_ISR(void)
{
sem = true;
__low_power_mode_off_on_exit();
}
the instruction "__low_power_mode_off_on_exit()" can go to while in main
when exit ISR.
You can code like this:
main()
{
while(1)
{
LPM3();
if(sem)
{
// do something;
}
}
}
and the "sem" is set in ISR:
// ADC10 interrupt service routine
#pragma vectorC10_VECTOR
__interrupt void ADC10_ISR(void)
{
sem = true;
__low_power_mode_off_on_exit();
}
the instruction "__low_power_mode_off_on_exit()" can go to while in main
when exit ISR.
Reply by ●August 4, 20092009-08-04
Those statements in your Method (1) and Method (2) are probably macros defined
in a header file.
Depend on how they are defined, they may or may not be suitable for your situation.
Even when they are suitable, the debugger you use may not be able to handle low power mode.
--- In m..., diptipanchal wrote:
.
> I am using SPI communication to get the ADC values. I am using timer A for
> writing data into SPI TX buffer (UCA0TXBUF). After every 100mS, data is
> written into SPI buffer & read the values from SPI RX buffer. Note: Using
> SMCLK, for SPI communication.
>
> I am trying to go in LPM3 modes based on some ADC values in the while loop
> of the main function. Then exit from LPM3 mode in TimerB.
>
> Using following method for LPM3.
> Method (1)
> __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable interrupts
>
> __bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bits from 0(SR)
>
> Method (2)
>
> LPM3 // Enter LPM3,
> LPM3_EXIT // Clear LPM3
>
> The problem is after enter or exit of LPM3 mode(I am not too sure about),
> the code does not go to while loop in main function. I have checked with
> breakpoint that only ISR routine is getting executed but not the main
> function.
>
> Could anyone help how to enter & exit from LPM3 mode? How the program
> restore it back to main function. Does any one have some literature about
> LPM modes in MSP430F2xx?
>
> Regards,
>
> Dipti
> --
>
>
Depend on how they are defined, they may or may not be suitable for your situation.
Even when they are suitable, the debugger you use may not be able to handle low power mode.
--- In m..., diptipanchal wrote:
.
> I am using SPI communication to get the ADC values. I am using timer A for
> writing data into SPI TX buffer (UCA0TXBUF). After every 100mS, data is
> written into SPI buffer & read the values from SPI RX buffer. Note: Using
> SMCLK, for SPI communication.
>
> I am trying to go in LPM3 modes based on some ADC values in the while loop
> of the main function. Then exit from LPM3 mode in TimerB.
>
> Using following method for LPM3.
> Method (1)
> __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable interrupts
>
> __bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bits from 0(SR)
>
> Method (2)
>
> LPM3 // Enter LPM3,
> LPM3_EXIT // Clear LPM3
>
> The problem is after enter or exit of LPM3 mode(I am not too sure about),
> the code does not go to while loop in main function. I have checked with
> breakpoint that only ISR routine is getting executed but not the main
> function.
>
> Could anyone help how to enter & exit from LPM3 mode? How the program
> restore it back to main function. Does any one have some literature about
> LPM modes in MSP430F2xx?
>
> Regards,
>
> Dipti
> --
>
>
Reply by ●August 4, 20092009-08-04
I think you do not need to have a sem. You do not need to test it in main and
you do not need to set it in ISR.
--- In m..., wrote:
>
> Hi,
> You can code like this:
>
> main()
> {
> while(1)
> {
> LPM3();
> if(sem)
> {
> // do something;
> }
> }
> }
>
> and the "sem" is set in ISR:
>
> // ADC10 interrupt service routine
> #pragma vector=ADC10_VECTOR
> __interrupt void ADC10_ISR(void)
> {
> sem = true;
> __low_power_mode_off_on_exit();
> }
>
> the instruction "__low_power_mode_off_on_exit()" can go to while in main
> when exit ISR.
>
>
>
>
--- In m..., wrote:
>
> Hi,
> You can code like this:
>
> main()
> {
> while(1)
> {
> LPM3();
> if(sem)
> {
> // do something;
> }
> }
> }
>
> and the "sem" is set in ISR:
>
> // ADC10 interrupt service routine
> #pragma vector=ADC10_VECTOR
> __interrupt void ADC10_ISR(void)
> {
> sem = true;
> __low_power_mode_off_on_exit();
> }
>
> the instruction "__low_power_mode_off_on_exit()" can go to while in main
> when exit ISR.
>
>
>
>
Reply by ●August 5, 20092009-08-05
--- In m..., "old_cow_yellow" wrote:
>
> Those statements in your Method (1) and Method (2) are probably macros defined in a header file.
>
> Depend on how they are defined, they may or may not be suitable for your situation.
>
> Even when they are suitable, the debugger you use may not be able to handle low power mode.
>
> --- In m..., diptipanchal wrote:
> .
> > I am using SPI communication to get the ADC values. I am using timer A for
> > writing data into SPI TX buffer (UCA0TXBUF). After every 100mS, data is
> > written into SPI buffer & read the values from SPI RX buffer. Note: Using
> > SMCLK, for SPI communication.
> >
> > I am trying to go in LPM3 modes based on some ADC values in the while loop
> > of the main function. Then exit from LPM3 mode in TimerB.
> >
> > Using following method for LPM3.
> > Method (1)
> > __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable interrupts
> >
> > __bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bits from 0(SR)
> >
> > Method (2)
> >
> > LPM3 // Enter LPM3,
> > LPM3_EXIT // Clear LPM3
> >
> > The problem is after enter or exit of LPM3 mode(I am not too sure about),
> > the code does not go to while loop in main function. I have checked with
> > breakpoint that only ISR routine is getting executed but not the main
> > function.
> >
> > Could anyone help how to enter & exit from LPM3 mode? How the program
> > restore it back to main function. Does any one have some literature about
> > LPM modes in MSP430F2xx?
> >
> > Regards,
> >
> > Dipti
> >
> >
> > --
> >
>
what's the bit rate of your SPI, if less than 32kbps,why not use ACLK as spi clock source?
If you use XT2: In LPM3, the current maybe >1mA,if you do not set the XT2OFF bit of BCSCTL1.
>
> Those statements in your Method (1) and Method (2) are probably macros defined in a header file.
>
> Depend on how they are defined, they may or may not be suitable for your situation.
>
> Even when they are suitable, the debugger you use may not be able to handle low power mode.
>
> --- In m..., diptipanchal wrote:
> .
> > I am using SPI communication to get the ADC values. I am using timer A for
> > writing data into SPI TX buffer (UCA0TXBUF). After every 100mS, data is
> > written into SPI buffer & read the values from SPI RX buffer. Note: Using
> > SMCLK, for SPI communication.
> >
> > I am trying to go in LPM3 modes based on some ADC values in the while loop
> > of the main function. Then exit from LPM3 mode in TimerB.
> >
> > Using following method for LPM3.
> > Method (1)
> > __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable interrupts
> >
> > __bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bits from 0(SR)
> >
> > Method (2)
> >
> > LPM3 // Enter LPM3,
> > LPM3_EXIT // Clear LPM3
> >
> > The problem is after enter or exit of LPM3 mode(I am not too sure about),
> > the code does not go to while loop in main function. I have checked with
> > breakpoint that only ISR routine is getting executed but not the main
> > function.
> >
> > Could anyone help how to enter & exit from LPM3 mode? How the program
> > restore it back to main function. Does any one have some literature about
> > LPM modes in MSP430F2xx?
> >
> > Regards,
> >
> > Dipti
> >
> >
> > --
> >
>
what's the bit rate of your SPI, if less than 32kbps,why not use ACLK as spi clock source?
If you use XT2: In LPM3, the current maybe >1mA,if you do not set the XT2OFF bit of BCSCTL1.
Reply by ●August 6, 20092009-08-06
I am using IAR debugger tool Version 4.20
In the header file of "msp430x23x0.h" LPMx defined as below
-----------------------
#define LPM0_bits (CPUOFF)
#define LPM1_bits (SCG0+CPUOFF)
#define LPM2_bits (SCG1+CPUOFF)
#define LPM3_bits (SCG1+SCG0+CPUOFF)
#define LPM4_bits (SCG1+SCG0+OSCOFF+CPUOFF)
#include
#define LPM0 _BIS_SR(LPM0_bits) /* Enter Low Power Mode 0 */
#define LPM0_EXIT _BIC_SR_IRQ(LPM0_bits) /* Exit Low Power Mode 0 */
#define LPM1 _BIS_SR(LPM1_bits) /* Enter Low Power Mode 1 */
#define LPM1_EXIT _BIC_SR_IRQ(LPM1_bits) /* Exit Low Power Mode 1 */
#define LPM2 _BIS_SR(LPM2_bits) /* Enter Low Power Mode 2 */
#define LPM2_EXIT _BIC_SR_IRQ(LPM2_bits) /* Exit Low Power Mode 2 */
#define LPM3 _BIS_SR(LPM3_bits) /* Enter Low Power Mode 3 */
#define LPM3_EXIT _BIC_SR_IRQ(LPM3_bits) /* Exit Low Power Mode 3 */
#define LPM4 _BIS_SR(LPM4_bits) /* Enter Low Power Mode 4 */
#define LPM4_EXIT _BIC_SR_IRQ(LPM4_bits) /* Exit Low Power Mode 4 */
-----------------------
I have defined below registers related to SPI.
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
BCSCTL1 = CALBC1_8MHZ;
DCOCTL = CALDCO_8MHZ;
UCA0CTL0 |= UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
UCA0CTL1 |= UCSSEL_2; // SMCLK = 8MHz / 8 = 1MHz
UCA0BR0 |= 0x08; // /8
UCA0BR1 = 0; //
UCA0MCTL = 0; // No modulation
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state
machine**
IE2 |= UCA0RXIE; // Enable USCI0 RX interrupt
__bis_SR_register(GIE); // CPU off, enable interrupts
Then in the while loop, if the flag is set in "__interrupt void
USCIA0RX_ISR(void) " then it has to enter in the LPM. In the timer B
interrupt [ __interrupt void Timer_B (void) ], if the same flag is set,
it has to exit from LPM.
The program flow is
1. Set the uC SFRS,
2. Initialize timers
3. SPI Communication in ISR routine.
In my code, based on the raw count of ADC, it needs to reset the SPI
clock & restart it again. Hence I thought of resetting the SPI clock by
entering into LPM & exit from LPM. I hope it works like this.
Is there any other method to achieve above.
Regards,
Dipti
________________________________
From: m... [mailto:m...] On Behalf
Of old_cow_yellow
Sent: Tuesday, August 04, 2009 7:35 PM
To: m...
Subject: [msp430] Re: LPM in MSP430F2xx
Those statements in your Method (1) and Method (2) are probably macros
defined in a header file.
Depend on how they are defined, they may or may not be suitable for your
situation.
Even when they are suitable, the debugger you use may not be able to
handle low power mode.
--- In m... ,
diptipanchal wrote:
.
> I am using SPI communication to get the ADC values. I am using timer A
for
> writing data into SPI TX buffer (UCA0TXBUF). After every 100mS, data
is
> written into SPI buffer & read the values from SPI RX buffer. Note:
Using
> SMCLK, for SPI communication.
>
> I am trying to go in LPM3 modes based on some ADC values in the while
loop
> of the main function. Then exit from LPM3 mode in TimerB.
>
> Using following method for LPM3.
> Method (1)
> __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable interrupts
>
> __bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bits from 0(SR)
>
> Method (2)
>
> LPM3 // Enter LPM3,
> LPM3_EXIT // Clear LPM3
>
> The problem is after enter or exit of LPM3 mode(I am not too sure
about),
> the code does not go to while loop in main function. I have checked
with
> breakpoint that only ISR routine is getting executed but not the main
> function.
>
> Could anyone help how to enter & exit from LPM3 mode? How the program
> restore it back to main function. Does any one have some literature
about
> LPM modes in MSP430F2xx?
>
> Regards,
>
> Dipti
> --
>
>
In the header file of "msp430x23x0.h" LPMx defined as below
-----------------------
#define LPM0_bits (CPUOFF)
#define LPM1_bits (SCG0+CPUOFF)
#define LPM2_bits (SCG1+CPUOFF)
#define LPM3_bits (SCG1+SCG0+CPUOFF)
#define LPM4_bits (SCG1+SCG0+OSCOFF+CPUOFF)
#include
#define LPM0 _BIS_SR(LPM0_bits) /* Enter Low Power Mode 0 */
#define LPM0_EXIT _BIC_SR_IRQ(LPM0_bits) /* Exit Low Power Mode 0 */
#define LPM1 _BIS_SR(LPM1_bits) /* Enter Low Power Mode 1 */
#define LPM1_EXIT _BIC_SR_IRQ(LPM1_bits) /* Exit Low Power Mode 1 */
#define LPM2 _BIS_SR(LPM2_bits) /* Enter Low Power Mode 2 */
#define LPM2_EXIT _BIC_SR_IRQ(LPM2_bits) /* Exit Low Power Mode 2 */
#define LPM3 _BIS_SR(LPM3_bits) /* Enter Low Power Mode 3 */
#define LPM3_EXIT _BIC_SR_IRQ(LPM3_bits) /* Exit Low Power Mode 3 */
#define LPM4 _BIS_SR(LPM4_bits) /* Enter Low Power Mode 4 */
#define LPM4_EXIT _BIC_SR_IRQ(LPM4_bits) /* Exit Low Power Mode 4 */
-----------------------
I have defined below registers related to SPI.
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
BCSCTL1 = CALBC1_8MHZ;
DCOCTL = CALDCO_8MHZ;
UCA0CTL0 |= UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
UCA0CTL1 |= UCSSEL_2; // SMCLK = 8MHz / 8 = 1MHz
UCA0BR0 |= 0x08; // /8
UCA0BR1 = 0; //
UCA0MCTL = 0; // No modulation
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state
machine**
IE2 |= UCA0RXIE; // Enable USCI0 RX interrupt
__bis_SR_register(GIE); // CPU off, enable interrupts
Then in the while loop, if the flag is set in "__interrupt void
USCIA0RX_ISR(void) " then it has to enter in the LPM. In the timer B
interrupt [ __interrupt void Timer_B (void) ], if the same flag is set,
it has to exit from LPM.
The program flow is
1. Set the uC SFRS,
2. Initialize timers
3. SPI Communication in ISR routine.
In my code, based on the raw count of ADC, it needs to reset the SPI
clock & restart it again. Hence I thought of resetting the SPI clock by
entering into LPM & exit from LPM. I hope it works like this.
Is there any other method to achieve above.
Regards,
Dipti
________________________________
From: m... [mailto:m...] On Behalf
Of old_cow_yellow
Sent: Tuesday, August 04, 2009 7:35 PM
To: m...
Subject: [msp430] Re: LPM in MSP430F2xx
Those statements in your Method (1) and Method (2) are probably macros
defined in a header file.
Depend on how they are defined, they may or may not be suitable for your
situation.
Even when they are suitable, the debugger you use may not be able to
handle low power mode.
--- In m... ,
diptipanchal wrote:
.
> I am using SPI communication to get the ADC values. I am using timer A
for
> writing data into SPI TX buffer (UCA0TXBUF). After every 100mS, data
is
> written into SPI buffer & read the values from SPI RX buffer. Note:
Using
> SMCLK, for SPI communication.
>
> I am trying to go in LPM3 modes based on some ADC values in the while
loop
> of the main function. Then exit from LPM3 mode in TimerB.
>
> Using following method for LPM3.
> Method (1)
> __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable interrupts
>
> __bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bits from 0(SR)
>
> Method (2)
>
> LPM3 // Enter LPM3,
> LPM3_EXIT // Clear LPM3
>
> The problem is after enter or exit of LPM3 mode(I am not too sure
about),
> the code does not go to while loop in main function. I have checked
with
> breakpoint that only ISR routine is getting executed but not the main
> function.
>
> Could anyone help how to enter & exit from LPM3 mode? How the program
> restore it back to main function. Does any one have some literature
about
> LPM modes in MSP430F2xx?
>
> Regards,
>
> Dipti
> --
>
>
Reply by ●August 6, 20092009-08-06
Now you have explained the macro definitions clearly. But I still do not
understand what you are trying to do.
You seem to have a SMCLK=8MHz and you use SMCLK/8 for the SPI controller to read an external ADC. Obviously, you cannot go to LPM3 when SPI is active. (Because there is no SMCLK in LPM3.) You also want to use TimerB. Are you using ACLK for TimerB? Otherwise you cannot use TimerB to wake up the CPU from LPM3 either. (Because in LPM3, only ACLK is active.)
I understand that you have (a) a while loop in main, (b) an ISR for ISP controller, and (c) an ISR for TimerB. You should not tell CPU to go to LPM in (b) or (c). And you cannot tell CPU to wake up in (a). Can you show where are you going to invoke those macros? (And please show some surrounding codes so that we know the circumstances?)
--- In m..., wrote:
>
> I am using IAR debugger tool Version 4.20
>
>
>
> In the header file of "msp430x23x0.h" LPMx defined as below
>
>
> -----------------------
>
> #define LPM0_bits (CPUOFF)
>
> #define LPM1_bits (SCG0+CPUOFF)
>
> #define LPM2_bits (SCG1+CPUOFF)
>
> #define LPM3_bits (SCG1+SCG0+CPUOFF)
>
> #define LPM4_bits (SCG1+SCG0+OSCOFF+CPUOFF)
>
>
>
> #include
>
> #define LPM0 _BIS_SR(LPM0_bits) /* Enter Low Power Mode 0 */
>
> #define LPM0_EXIT _BIC_SR_IRQ(LPM0_bits) /* Exit Low Power Mode 0 */
>
> #define LPM1 _BIS_SR(LPM1_bits) /* Enter Low Power Mode 1 */
>
> #define LPM1_EXIT _BIC_SR_IRQ(LPM1_bits) /* Exit Low Power Mode 1 */
>
> #define LPM2 _BIS_SR(LPM2_bits) /* Enter Low Power Mode 2 */
>
> #define LPM2_EXIT _BIC_SR_IRQ(LPM2_bits) /* Exit Low Power Mode 2 */
>
> #define LPM3 _BIS_SR(LPM3_bits) /* Enter Low Power Mode 3 */
>
> #define LPM3_EXIT _BIC_SR_IRQ(LPM3_bits) /* Exit Low Power Mode 3 */
>
> #define LPM4 _BIS_SR(LPM4_bits) /* Enter Low Power Mode 4 */
>
> #define LPM4_EXIT _BIC_SR_IRQ(LPM4_bits) /* Exit Low Power Mode 4 */
>
>
> -----------------------
>
>
>
> I have defined below registers related to SPI.
>
>
>
> WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
>
> BCSCTL1 = CALBC1_8MHZ;
>
> DCOCTL = CALDCO_8MHZ;
>
> UCA0CTL0 |= UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
>
> UCA0CTL1 |= UCSSEL_2; // SMCLK = 8MHz / 8 = 1MHz
>
> UCA0BR0 |= 0x08; // /8
>
> UCA0BR1 = 0; //
>
> UCA0MCTL = 0; // No modulation
>
> UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state
> machine**
>
> IE2 |= UCA0RXIE; // Enable USCI0 RX interrupt
>
> __bis_SR_register(GIE); // CPU off, enable interrupts
>
>
>
>
>
> Then in the while loop, if the flag is set in "__interrupt void
> USCIA0RX_ISR(void) " then it has to enter in the LPM. In the timer B
> interrupt [ __interrupt void Timer_B (void) ], if the same flag is set,
> it has to exit from LPM.
>
>
>
> The program flow is
>
> 1. Set the uC SFRS,
> 2. Initialize timers
> 3. SPI Communication in ISR routine.
>
>
>
> In my code, based on the raw count of ADC, it needs to reset the SPI
> clock & restart it again. Hence I thought of resetting the SPI clock by
> entering into LPM & exit from LPM. I hope it works like this.
>
>
>
> Is there any other method to achieve above.
>
>
>
> Regards,
>
>
>
> Dipti
>
>
>
> ________________________________
>
> From: m... [mailto:m...] On Behalf
> Of old_cow_yellow
> Sent: Tuesday, August 04, 2009 7:35 PM
> To: m...
> Subject: [msp430] Re: LPM in MSP430F2xx
>
>
>
>
>
> Those statements in your Method (1) and Method (2) are probably macros
> defined in a header file.
>
> Depend on how they are defined, they may or may not be suitable for your
> situation.
>
> Even when they are suitable, the debugger you use may not be able to
> handle low power mode.
>
> --- In m... ,
> diptipanchal wrote:
> .
> > I am using SPI communication to get the ADC values. I am using timer A
> for
> > writing data into SPI TX buffer (UCA0TXBUF). After every 100mS, data
> is
> > written into SPI buffer & read the values from SPI RX buffer. Note:
> Using
> > SMCLK, for SPI communication.
> >
> > I am trying to go in LPM3 modes based on some ADC values in the while
> loop
> > of the main function. Then exit from LPM3 mode in TimerB.
> >
> > Using following method for LPM3.
> > Method (1)
> > __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable interrupts
> >
> > __bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bits from 0(SR)
> >
> > Method (2)
> >
> > LPM3 // Enter LPM3,
> > LPM3_EXIT // Clear LPM3
> >
> > The problem is after enter or exit of LPM3 mode(I am not too sure
> about),
> > the code does not go to while loop in main function. I have checked
> with
> > breakpoint that only ISR routine is getting executed but not the main
> > function.
> >
> > Could anyone help how to enter & exit from LPM3 mode? How the program
> > restore it back to main function. Does any one have some literature
> about
> > LPM modes in MSP430F2xx?
> >
> > Regards,
> >
> > Dipti
> >
> >
> > --
> >
> >
>
You seem to have a SMCLK=8MHz and you use SMCLK/8 for the SPI controller to read an external ADC. Obviously, you cannot go to LPM3 when SPI is active. (Because there is no SMCLK in LPM3.) You also want to use TimerB. Are you using ACLK for TimerB? Otherwise you cannot use TimerB to wake up the CPU from LPM3 either. (Because in LPM3, only ACLK is active.)
I understand that you have (a) a while loop in main, (b) an ISR for ISP controller, and (c) an ISR for TimerB. You should not tell CPU to go to LPM in (b) or (c). And you cannot tell CPU to wake up in (a). Can you show where are you going to invoke those macros? (And please show some surrounding codes so that we know the circumstances?)
--- In m..., wrote:
>
> I am using IAR debugger tool Version 4.20
>
>
>
> In the header file of "msp430x23x0.h" LPMx defined as below
>
>
> -----------------------
>
> #define LPM0_bits (CPUOFF)
>
> #define LPM1_bits (SCG0+CPUOFF)
>
> #define LPM2_bits (SCG1+CPUOFF)
>
> #define LPM3_bits (SCG1+SCG0+CPUOFF)
>
> #define LPM4_bits (SCG1+SCG0+OSCOFF+CPUOFF)
>
>
>
> #include
>
> #define LPM0 _BIS_SR(LPM0_bits) /* Enter Low Power Mode 0 */
>
> #define LPM0_EXIT _BIC_SR_IRQ(LPM0_bits) /* Exit Low Power Mode 0 */
>
> #define LPM1 _BIS_SR(LPM1_bits) /* Enter Low Power Mode 1 */
>
> #define LPM1_EXIT _BIC_SR_IRQ(LPM1_bits) /* Exit Low Power Mode 1 */
>
> #define LPM2 _BIS_SR(LPM2_bits) /* Enter Low Power Mode 2 */
>
> #define LPM2_EXIT _BIC_SR_IRQ(LPM2_bits) /* Exit Low Power Mode 2 */
>
> #define LPM3 _BIS_SR(LPM3_bits) /* Enter Low Power Mode 3 */
>
> #define LPM3_EXIT _BIC_SR_IRQ(LPM3_bits) /* Exit Low Power Mode 3 */
>
> #define LPM4 _BIS_SR(LPM4_bits) /* Enter Low Power Mode 4 */
>
> #define LPM4_EXIT _BIC_SR_IRQ(LPM4_bits) /* Exit Low Power Mode 4 */
>
>
> -----------------------
>
>
>
> I have defined below registers related to SPI.
>
>
>
> WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
>
> BCSCTL1 = CALBC1_8MHZ;
>
> DCOCTL = CALDCO_8MHZ;
>
> UCA0CTL0 |= UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
>
> UCA0CTL1 |= UCSSEL_2; // SMCLK = 8MHz / 8 = 1MHz
>
> UCA0BR0 |= 0x08; // /8
>
> UCA0BR1 = 0; //
>
> UCA0MCTL = 0; // No modulation
>
> UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state
> machine**
>
> IE2 |= UCA0RXIE; // Enable USCI0 RX interrupt
>
> __bis_SR_register(GIE); // CPU off, enable interrupts
>
>
>
>
>
> Then in the while loop, if the flag is set in "__interrupt void
> USCIA0RX_ISR(void) " then it has to enter in the LPM. In the timer B
> interrupt [ __interrupt void Timer_B (void) ], if the same flag is set,
> it has to exit from LPM.
>
>
>
> The program flow is
>
> 1. Set the uC SFRS,
> 2. Initialize timers
> 3. SPI Communication in ISR routine.
>
>
>
> In my code, based on the raw count of ADC, it needs to reset the SPI
> clock & restart it again. Hence I thought of resetting the SPI clock by
> entering into LPM & exit from LPM. I hope it works like this.
>
>
>
> Is there any other method to achieve above.
>
>
>
> Regards,
>
>
>
> Dipti
>
>
>
> ________________________________
>
> From: m... [mailto:m...] On Behalf
> Of old_cow_yellow
> Sent: Tuesday, August 04, 2009 7:35 PM
> To: m...
> Subject: [msp430] Re: LPM in MSP430F2xx
>
>
>
>
>
> Those statements in your Method (1) and Method (2) are probably macros
> defined in a header file.
>
> Depend on how they are defined, they may or may not be suitable for your
> situation.
>
> Even when they are suitable, the debugger you use may not be able to
> handle low power mode.
>
> --- In m... ,
> diptipanchal wrote:
> .
> > I am using SPI communication to get the ADC values. I am using timer A
> for
> > writing data into SPI TX buffer (UCA0TXBUF). After every 100mS, data
> is
> > written into SPI buffer & read the values from SPI RX buffer. Note:
> Using
> > SMCLK, for SPI communication.
> >
> > I am trying to go in LPM3 modes based on some ADC values in the while
> loop
> > of the main function. Then exit from LPM3 mode in TimerB.
> >
> > Using following method for LPM3.
> > Method (1)
> > __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable interrupts
> >
> > __bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bits from 0(SR)
> >
> > Method (2)
> >
> > LPM3 // Enter LPM3,
> > LPM3_EXIT // Clear LPM3
> >
> > The problem is after enter or exit of LPM3 mode(I am not too sure
> about),
> > the code does not go to while loop in main function. I have checked
> with
> > breakpoint that only ISR routine is getting executed but not the main
> > function.
> >
> > Could anyone help how to enter & exit from LPM3 mode? How the program
> > restore it back to main function. Does any one have some literature
> about
> > LPM modes in MSP430F2xx?
> >
> > Regards,
> >
> > Dipti
> >
> >
> > --
> >
> >
>
Reply by ●August 7, 20092009-08-07
Here is the code snippet
/************************************** CODE
STARTS******************************************************/
unsigned char Flag_Temp = 0, Cnt_Temp = 0, Flag_LPM_Exit = 0;
/******************************************************/
/* main function */
/******************************************************/
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
BCSCTL1 = CALBC1_8MHZ;
DCOCTL = CALDCO_8MHZ;
P1OUT = 0xFF; //
P1DIR |= 0xFF; // P1 for output
P1SEL |= 0X00; // P1 function selected
P2DIR |= 0xC8; // P2.0,P2.1,P2.2,P2.4 & P2.5 as input, P2.3 as
output
// P2DIR |= 0xC4, P2.0,P2.1,P2.3,P2.4 & P2.5 as input, P2.2
as output
P2SEL |= 0XC0; // P2.0 to P2.5 for output, P2.6 XIN,P 2.7 XOUT -
active
P2OUT |= 0x80;
P3DIR |= 0xFF; // P3.7 & P3.6 out
P3SEL |= 0x37; // P3.0,4,5 USCI_A0 option
select
P3OUT = 0xC8; // Set slave reset,gain 128,
PDWN=1
P4DIR |= 0xFF; // P4.0 & P4.1 out
P4SEL |= 0x00; // P3.0,4,5 USCI_A0 option
select
UCA0CTL0 |= UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 |= 0x08; // /8
UCA0BR1 = 0; //
UCA0MCTL = 0; // No modulation
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state
machine**
IE2 |= UCA0RXIE; // Enable USCI0 RX interrupt
P3OUT &= ~0x40; // Now with SPI signals
initialized,
P3OUT |= 0x40; // reset slave
__bis_SR_register(GIE); // CPU off, enable interrupts
TBCTL = TBSSEL_1 + TBCLR; // ACLK, clear TBR, divider=1
TBCCTL0 = CCIE; // TBCCR0 interrupt enabled
TBCCR0 = 0x8F5;
TBCTL = TBSSEL_1 + MC_1; // ACLK, upmode
TACCTL0 = CCIE; // TACCR0 interrupt enabled
TACCR0 = 0x0D16; //100mS,
TACTL = TASSEL_1 + MC_1; // ACLK, upmode,, divider=1
...........................
...........................
...........................
//Code for ADC raw count & display.
...........................
........................
If (Flag_Noscl== 1)
{
...........................
...........................
if (Flag_Temp == 1) {
Flag_Temp = 0; // reset Flag_Temp
to sero so only once it will enter into LPM3 mode.
Flag_LPM_Exit = 1;
__bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable
interrupts
}
}
} // main
/******************************************************/
/* ISR for ADC data */
/* Setting & resetting of the Flag_Noscl */
/*happens in this ISR based on the ADC value */
/*recevied from the ADC. */
/******************************************************/
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCIA0RX_ISR(void)
{
long int adc_data3,adc_data2,adc_data1;
while (!(IFG2 & UCA0RXIFG)); // USCI_A0 TX buffer ready?
adc_data1 = UCA0RXBUF;
adc_data1 = adc_data1 << 16;
...........................
...........................
if (some condition )
{
...........................
...........................
Flag_Noscl = 0;
Flag_Temp = 0;
Cnt_Temp = 0;
...........................
...........................
}
else
{
Flag_Noscl = 1;
Cnt_Temp++;
if ((Flag_Noscl == 1) && (Cnt_Temp==1)) {
Flag_Temp = 1;
Flag_LPM_Exit = 0;
}
if (Cnt_Temp >= 20) {
Cnt_Temp = 0; // Cnt_Temp is reset to 0, so if the
Flag_Noscl is set & Cnt_Temp is reached 20 , then it would again set the
Flag_Temp to enter in LPM mode.
}
...........................
...........................
}
...........................
...........................
}
/******************************************************/
/* ISR for Timer A */
/******************************************************/
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
if (Flag_LPM_Exit == 1) {
__bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bits from
0(SR)
}
Else {
UCA0TXBUF = 0x01; // Transmit first character
UCA0TXBUF = 0x01;
}
}
/************************************** CODE
ENDS******************************************************/
I have tried to execute above code, but it seems the SMCLK is not
disabled as mentioned in LPM3 mode. I have checked by connecting
Oscilloscope at SPI clock pin & see whether it goes off or nor or at new
instance the clock is started or not. I am not too sure whether I am
checking correctly or not.
As I mentioned earlier, I would need to restart the SPI communication
between ADC & uC based on some ADC data received. I thought by
restarting the SMCLK would help.
Could you provide some inputs on how to restart the SPI clock for uC
MSP430F2xx in runtime.
Kindly let me know if you need some more input.
Thanks for you help.
Regards,
Dipti
________________________________
From: m... [mailto:m...] On Behalf
Of old_cow_yellow
Sent: Friday, August 07, 2009 8:26 AM
To: m...
Subject: [msp430] Re: LPM in MSP430F2xx
Now you have explained the macro definitions clearly. But I still do not
understand what you are trying to do.
You seem to have a SMCLK=8MHz and you use SMCLK/8 for the SPI controller
to read an external ADC. Obviously, you cannot go to LPM3 when SPI is
active. (Because there is no SMCLK in LPM3.) You also want to use
TimerB. Are you using ACLK for TimerB? Otherwise you cannot use TimerB
to wake up the CPU from LPM3 either. (Because in LPM3, only ACLK is
active.)
I understand that you have (a) a while loop in main, (b) an ISR for ISP
controller, and (c) an ISR for TimerB. You should not tell CPU to go to
LPM in (b) or (c). And you cannot tell CPU to wake up in (a). Can you
show where are you going to invoke those macros? (And please show some
surrounding codes so that we know the circumstances?)
--- In m... ,
wrote:
>
> I am using IAR debugger tool Version 4.20
>
> In the header file of "msp430x23x0.h" LPMx defined as below
>
> ----------------------
> ----------------------
>
> #define LPM0_bits (CPUOFF)
>
> #define LPM1_bits (SCG0+CPUOFF)
>
> #define LPM2_bits (SCG1+CPUOFF)
>
> #define LPM3_bits (SCG1+SCG0+CPUOFF)
>
> #define LPM4_bits (SCG1+SCG0+OSCOFF+CPUOFF)
>
> #include #define LPM0 _BIS_SR(LPM0_bits) /* Enter Low Power Mode 0 */
>
> #define LPM0_EXIT _BIC_SR_IRQ(LPM0_bits) /* Exit Low Power Mode 0 */
>
> #define LPM1 _BIS_SR(LPM1_bits) /* Enter Low Power Mode 1 */
>
> #define LPM1_EXIT _BIC_SR_IRQ(LPM1_bits) /* Exit Low Power Mode 1 */
>
> #define LPM2 _BIS_SR(LPM2_bits) /* Enter Low Power Mode 2 */
>
> #define LPM2_EXIT _BIC_SR_IRQ(LPM2_bits) /* Exit Low Power Mode 2 */
>
> #define LPM3 _BIS_SR(LPM3_bits) /* Enter Low Power Mode 3 */
>
> #define LPM3_EXIT _BIC_SR_IRQ(LPM3_bits) /* Exit Low Power Mode 3 */
>
> #define LPM4 _BIS_SR(LPM4_bits) /* Enter Low Power Mode 4 */
>
> #define LPM4_EXIT _BIC_SR_IRQ(LPM4_bits) /* Exit Low Power Mode 4 */
>
> ----------------------
> ----------------------
>
> I have defined below registers related to SPI.
>
> WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
>
> BCSCTL1 = CALBC1_8MHZ;
>
> DCOCTL = CALDCO_8MHZ;
>
> UCA0CTL0 |= UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
>
> UCA0CTL1 |= UCSSEL_2; // SMCLK = 8MHz / 8 = 1MHz
>
> UCA0BR0 |= 0x08; // /8
>
> UCA0BR1 = 0; //
>
> UCA0MCTL = 0; // No modulation
>
> UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state
> machine**
>
> IE2 |= UCA0RXIE; // Enable USCI0 RX interrupt
>
> __bis_SR_register(GIE); // CPU off, enable interrupts
>
> Then in the while loop, if the flag is set in "__interrupt void
> USCIA0RX_ISR(void) " then it has to enter in the LPM. In the timer B
> interrupt [ __interrupt void Timer_B (void) ], if the same flag is
set,
> it has to exit from LPM.
>
> The program flow is
>
> 1. Set the uC SFRS,
> 2. Initialize timers
> 3. SPI Communication in ISR routine.
>
> In my code, based on the raw count of ADC, it needs to reset the SPI
> clock & restart it again. Hence I thought of resetting the SPI clock
by
> entering into LPM & exit from LPM. I hope it works like this.
>
> Is there any other method to achieve above.
>
> Regards,
>
> Dipti
>
> ________________________________
>
> From: m...
[mailto:m... ] On
Behalf
> Of old_cow_yellow
> Sent: Tuesday, August 04, 2009 7:35 PM
> To: m...
> Subject: [msp430] Re: LPM in MSP430F2xx
>
> Those statements in your Method (1) and Method (2) are probably macros
> defined in a header file.
>
> Depend on how they are defined, they may or may not be suitable for
your
> situation.
>
> Even when they are suitable, the debugger you use may not be able to
> handle low power mode.
>
> --- In m...
,
> diptipanchal wrote:
> .
> > I am using SPI communication to get the ADC values. I am using timer
A
> for
> > writing data into SPI TX buffer (UCA0TXBUF). After every 100mS, data
> is
> > written into SPI buffer & read the values from SPI RX buffer. Note:
> Using
> > SMCLK, for SPI communication.
> >
> > I am trying to go in LPM3 modes based on some ADC values in the
while
> loop
> > of the main function. Then exit from LPM3 mode in TimerB.
> >
> > Using following method for LPM3.
> > Method (1)
> > __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable interrupts
> >
> > __bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bits from 0(SR)
> >
> > Method (2)
> >
> > LPM3 // Enter LPM3,
> > LPM3_EXIT // Clear LPM3
> >
> > The problem is after enter or exit of LPM3 mode(I am not too sure
> about),
> > the code does not go to while loop in main function. I have checked
> with
> > breakpoint that only ISR routine is getting executed but not the
main
> > function.
> >
> > Could anyone help how to enter & exit from LPM3 mode? How the
program
> > restore it back to main function. Does any one have some literature
> about
> > LPM modes in MSP430F2xx?
> >
> > Regards,
> >
> > Dipti
> >
> >
> > --
> >
> >
>
/************************************** CODE
STARTS******************************************************/
unsigned char Flag_Temp = 0, Cnt_Temp = 0, Flag_LPM_Exit = 0;
/******************************************************/
/* main function */
/******************************************************/
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
BCSCTL1 = CALBC1_8MHZ;
DCOCTL = CALDCO_8MHZ;
P1OUT = 0xFF; //
P1DIR |= 0xFF; // P1 for output
P1SEL |= 0X00; // P1 function selected
P2DIR |= 0xC8; // P2.0,P2.1,P2.2,P2.4 & P2.5 as input, P2.3 as
output
// P2DIR |= 0xC4, P2.0,P2.1,P2.3,P2.4 & P2.5 as input, P2.2
as output
P2SEL |= 0XC0; // P2.0 to P2.5 for output, P2.6 XIN,P 2.7 XOUT -
active
P2OUT |= 0x80;
P3DIR |= 0xFF; // P3.7 & P3.6 out
P3SEL |= 0x37; // P3.0,4,5 USCI_A0 option
select
P3OUT = 0xC8; // Set slave reset,gain 128,
PDWN=1
P4DIR |= 0xFF; // P4.0 & P4.1 out
P4SEL |= 0x00; // P3.0,4,5 USCI_A0 option
select
UCA0CTL0 |= UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 |= 0x08; // /8
UCA0BR1 = 0; //
UCA0MCTL = 0; // No modulation
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state
machine**
IE2 |= UCA0RXIE; // Enable USCI0 RX interrupt
P3OUT &= ~0x40; // Now with SPI signals
initialized,
P3OUT |= 0x40; // reset slave
__bis_SR_register(GIE); // CPU off, enable interrupts
TBCTL = TBSSEL_1 + TBCLR; // ACLK, clear TBR, divider=1
TBCCTL0 = CCIE; // TBCCR0 interrupt enabled
TBCCR0 = 0x8F5;
TBCTL = TBSSEL_1 + MC_1; // ACLK, upmode
TACCTL0 = CCIE; // TACCR0 interrupt enabled
TACCR0 = 0x0D16; //100mS,
TACTL = TASSEL_1 + MC_1; // ACLK, upmode,, divider=1
...........................
...........................
...........................
//Code for ADC raw count & display.
...........................
........................
If (Flag_Noscl== 1)
{
...........................
...........................
if (Flag_Temp == 1) {
Flag_Temp = 0; // reset Flag_Temp
to sero so only once it will enter into LPM3 mode.
Flag_LPM_Exit = 1;
__bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable
interrupts
}
}
} // main
/******************************************************/
/* ISR for ADC data */
/* Setting & resetting of the Flag_Noscl */
/*happens in this ISR based on the ADC value */
/*recevied from the ADC. */
/******************************************************/
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCIA0RX_ISR(void)
{
long int adc_data3,adc_data2,adc_data1;
while (!(IFG2 & UCA0RXIFG)); // USCI_A0 TX buffer ready?
adc_data1 = UCA0RXBUF;
adc_data1 = adc_data1 << 16;
...........................
...........................
if (some condition )
{
...........................
...........................
Flag_Noscl = 0;
Flag_Temp = 0;
Cnt_Temp = 0;
...........................
...........................
}
else
{
Flag_Noscl = 1;
Cnt_Temp++;
if ((Flag_Noscl == 1) && (Cnt_Temp==1)) {
Flag_Temp = 1;
Flag_LPM_Exit = 0;
}
if (Cnt_Temp >= 20) {
Cnt_Temp = 0; // Cnt_Temp is reset to 0, so if the
Flag_Noscl is set & Cnt_Temp is reached 20 , then it would again set the
Flag_Temp to enter in LPM mode.
}
...........................
...........................
}
...........................
...........................
}
/******************************************************/
/* ISR for Timer A */
/******************************************************/
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
if (Flag_LPM_Exit == 1) {
__bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bits from
0(SR)
}
Else {
UCA0TXBUF = 0x01; // Transmit first character
UCA0TXBUF = 0x01;
}
}
/************************************** CODE
ENDS******************************************************/
I have tried to execute above code, but it seems the SMCLK is not
disabled as mentioned in LPM3 mode. I have checked by connecting
Oscilloscope at SPI clock pin & see whether it goes off or nor or at new
instance the clock is started or not. I am not too sure whether I am
checking correctly or not.
As I mentioned earlier, I would need to restart the SPI communication
between ADC & uC based on some ADC data received. I thought by
restarting the SMCLK would help.
Could you provide some inputs on how to restart the SPI clock for uC
MSP430F2xx in runtime.
Kindly let me know if you need some more input.
Thanks for you help.
Regards,
Dipti
________________________________
From: m... [mailto:m...] On Behalf
Of old_cow_yellow
Sent: Friday, August 07, 2009 8:26 AM
To: m...
Subject: [msp430] Re: LPM in MSP430F2xx
Now you have explained the macro definitions clearly. But I still do not
understand what you are trying to do.
You seem to have a SMCLK=8MHz and you use SMCLK/8 for the SPI controller
to read an external ADC. Obviously, you cannot go to LPM3 when SPI is
active. (Because there is no SMCLK in LPM3.) You also want to use
TimerB. Are you using ACLK for TimerB? Otherwise you cannot use TimerB
to wake up the CPU from LPM3 either. (Because in LPM3, only ACLK is
active.)
I understand that you have (a) a while loop in main, (b) an ISR for ISP
controller, and (c) an ISR for TimerB. You should not tell CPU to go to
LPM in (b) or (c). And you cannot tell CPU to wake up in (a). Can you
show where are you going to invoke those macros? (And please show some
surrounding codes so that we know the circumstances?)
--- In m... ,
wrote:
>
> I am using IAR debugger tool Version 4.20
>
> In the header file of "msp430x23x0.h" LPMx defined as below
>
> ----------------------
> ----------------------
>
> #define LPM0_bits (CPUOFF)
>
> #define LPM1_bits (SCG0+CPUOFF)
>
> #define LPM2_bits (SCG1+CPUOFF)
>
> #define LPM3_bits (SCG1+SCG0+CPUOFF)
>
> #define LPM4_bits (SCG1+SCG0+OSCOFF+CPUOFF)
>
> #include #define LPM0 _BIS_SR(LPM0_bits) /* Enter Low Power Mode 0 */
>
> #define LPM0_EXIT _BIC_SR_IRQ(LPM0_bits) /* Exit Low Power Mode 0 */
>
> #define LPM1 _BIS_SR(LPM1_bits) /* Enter Low Power Mode 1 */
>
> #define LPM1_EXIT _BIC_SR_IRQ(LPM1_bits) /* Exit Low Power Mode 1 */
>
> #define LPM2 _BIS_SR(LPM2_bits) /* Enter Low Power Mode 2 */
>
> #define LPM2_EXIT _BIC_SR_IRQ(LPM2_bits) /* Exit Low Power Mode 2 */
>
> #define LPM3 _BIS_SR(LPM3_bits) /* Enter Low Power Mode 3 */
>
> #define LPM3_EXIT _BIC_SR_IRQ(LPM3_bits) /* Exit Low Power Mode 3 */
>
> #define LPM4 _BIS_SR(LPM4_bits) /* Enter Low Power Mode 4 */
>
> #define LPM4_EXIT _BIC_SR_IRQ(LPM4_bits) /* Exit Low Power Mode 4 */
>
> ----------------------
> ----------------------
>
> I have defined below registers related to SPI.
>
> WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
>
> BCSCTL1 = CALBC1_8MHZ;
>
> DCOCTL = CALDCO_8MHZ;
>
> UCA0CTL0 |= UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
>
> UCA0CTL1 |= UCSSEL_2; // SMCLK = 8MHz / 8 = 1MHz
>
> UCA0BR0 |= 0x08; // /8
>
> UCA0BR1 = 0; //
>
> UCA0MCTL = 0; // No modulation
>
> UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state
> machine**
>
> IE2 |= UCA0RXIE; // Enable USCI0 RX interrupt
>
> __bis_SR_register(GIE); // CPU off, enable interrupts
>
> Then in the while loop, if the flag is set in "__interrupt void
> USCIA0RX_ISR(void) " then it has to enter in the LPM. In the timer B
> interrupt [ __interrupt void Timer_B (void) ], if the same flag is
set,
> it has to exit from LPM.
>
> The program flow is
>
> 1. Set the uC SFRS,
> 2. Initialize timers
> 3. SPI Communication in ISR routine.
>
> In my code, based on the raw count of ADC, it needs to reset the SPI
> clock & restart it again. Hence I thought of resetting the SPI clock
by
> entering into LPM & exit from LPM. I hope it works like this.
>
> Is there any other method to achieve above.
>
> Regards,
>
> Dipti
>
> ________________________________
>
> From: m...
[mailto:m... ] On
Behalf
> Of old_cow_yellow
> Sent: Tuesday, August 04, 2009 7:35 PM
> To: m...
> Subject: [msp430] Re: LPM in MSP430F2xx
>
> Those statements in your Method (1) and Method (2) are probably macros
> defined in a header file.
>
> Depend on how they are defined, they may or may not be suitable for
your
> situation.
>
> Even when they are suitable, the debugger you use may not be able to
> handle low power mode.
>
> --- In m...
,
> diptipanchal wrote:
> .
> > I am using SPI communication to get the ADC values. I am using timer
A
> for
> > writing data into SPI TX buffer (UCA0TXBUF). After every 100mS, data
> is
> > written into SPI buffer & read the values from SPI RX buffer. Note:
> Using
> > SMCLK, for SPI communication.
> >
> > I am trying to go in LPM3 modes based on some ADC values in the
while
> loop
> > of the main function. Then exit from LPM3 mode in TimerB.
> >
> > Using following method for LPM3.
> > Method (1)
> > __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable interrupts
> >
> > __bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bits from 0(SR)
> >
> > Method (2)
> >
> > LPM3 // Enter LPM3,
> > LPM3_EXIT // Clear LPM3
> >
> > The problem is after enter or exit of LPM3 mode(I am not too sure
> about),
> > the code does not go to while loop in main function. I have checked
> with
> > breakpoint that only ISR routine is getting executed but not the
main
> > function.
> >
> > Could anyone help how to enter & exit from LPM3 mode? How the
program
> > restore it back to main function. Does any one have some literature
> about
> > LPM modes in MSP430F2xx?
> >
> > Regards,
> >
> > Dipti
> >
> >
> > --
> >
> >
>
Reply by ●August 10, 20092009-08-10
Sorry, I had a hard time following your code. The mail system strips all
indentations and splits some of the lines. (And I do not worship c.) May be you
have already solved your problems. But this is what I think:
The execution fell through the bottom of you main() and end up in the c _exit code, which may be a single machine instruction that jumps to itself. That is, a one-instruction, two-cycle endless loop. If and when an interrupt is requested, the ISR is executed. After that, back to the endless loop doing nothing.
--- In m..., wrote:
>
> Here is the code snippet
>
> /************************************** CODE
> STARTS******************************************************/
>
>
>
> unsigned char Flag_Temp = 0, Cnt_Temp = 0, Flag_LPM_Exit = 0;
>
> /******************************************************/
>
> /* main function */
>
> /******************************************************/
>
> void main(void)
>
> {
>
>
>
> WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
>
> BCSCTL1 = CALBC1_8MHZ;
>
> DCOCTL = CALDCO_8MHZ;
>
>
>
> P1OUT = 0xFF; //
>
> P1DIR |= 0xFF; // P1 for output
>
> P1SEL |= 0X00; // P1 function selected
>
>
>
> P2DIR |= 0xC8; // P2.0,P2.1,P2.2,P2.4 & P2.5 as input, P2.3 as
> output
>
> // P2DIR |= 0xC4, P2.0,P2.1,P2.3,P2.4 & P2.5 as input, P2.2
> as output
>
> P2SEL |= 0XC0; // P2.0 to P2.5 for output, P2.6 XIN,P 2.7 XOUT -
> active
>
> P2OUT |= 0x80;
>
>
>
> P3DIR |= 0xFF; // P3.7 & P3.6 out
>
> P3SEL |= 0x37; // P3.0,4,5 USCI_A0 option
> select
>
> P3OUT = 0xC8; // Set slave reset,gain 128,
> PDWN=1
>
>
>
> P4DIR |= 0xFF; // P4.0 & P4.1 out
>
> P4SEL |= 0x00; // P3.0,4,5 USCI_A0 option
> select
>
>
>
> UCA0CTL0 |= UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
>
> UCA0CTL1 |= UCSSEL_2; // SMCLK
>
> UCA0BR0 |= 0x08; // /8
>
> UCA0BR1 = 0; //
>
> UCA0MCTL = 0; // No modulation
>
> UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state
> machine**
>
> IE2 |= UCA0RXIE; // Enable USCI0 RX interrupt
>
>
>
> P3OUT &= ~0x40; // Now with SPI signals
> initialized,
>
> P3OUT |= 0x40; // reset slave
>
> __bis_SR_register(GIE); // CPU off, enable interrupts
>
>
>
>
>
> TBCTL = TBSSEL_1 + TBCLR; // ACLK, clear TBR, divider=1
>
> TBCCTL0 = CCIE; // TBCCR0 interrupt enabled
>
> TBCCR0 = 0x8F5;
>
> TBCTL = TBSSEL_1 + MC_1; // ACLK, upmode
>
>
>
> TACCTL0 = CCIE; // TACCR0 interrupt enabled
>
> TACCR0 = 0x0D16; //100mS,
>
> TACTL = TASSEL_1 + MC_1; // ACLK, upmode,, divider=1
>
>
>
> ...........................
>
> ...........................
>
> ...........................
>
> //Code for ADC raw count & display.
>
> ...........................
>
> ........................
>
> If (Flag_Noscl== 1)
>
> {
>
> ...........................
>
> ...........................
>
> if (Flag_Temp == 1) {
>
> Flag_Temp = 0; // reset Flag_Temp
> to sero so only once it will enter into LPM3 mode.
>
> Flag_LPM_Exit = 1;
>
> __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable
> interrupts
>
> }
>
> }
>
>
>
> } // main
>
>
>
> /******************************************************/
>
> /* ISR for ADC data */
>
> /* Setting & resetting of the Flag_Noscl */
>
> /*happens in this ISR based on the ADC value */
>
> /*recevied from the ADC. */
>
> /******************************************************/
>
> #pragma vector=USCIAB0RX_VECTOR
>
> __interrupt void USCIA0RX_ISR(void)
>
> {
>
> long int adc_data3,adc_data2,adc_data1;
>
>
>
> while (!(IFG2 & UCA0RXIFG)); // USCI_A0 TX buffer ready?
>
> adc_data1 = UCA0RXBUF;
>
> adc_data1 = adc_data1 << 16;
>
> ...........................
>
> ...........................
>
> if (some condition )
>
> {
>
> ...........................
>
> ...........................
>
>
>
> Flag_Noscl = 0;
>
> Flag_Temp = 0;
>
> Cnt_Temp = 0;
>
> ...........................
>
> ...........................
>
>
>
>
>
> }
>
> else
>
> {
>
> Flag_Noscl = 1;
>
> Cnt_Temp++;
>
> if ((Flag_Noscl == 1) && (Cnt_Temp==1)) {
>
> Flag_Temp = 1;
>
> Flag_LPM_Exit = 0;
>
> }
>
> if (Cnt_Temp >= 20) {
>
> Cnt_Temp = 0; // Cnt_Temp is reset to 0, so if the
> Flag_Noscl is set & Cnt_Temp is reached 20 , then it would again set the
> Flag_Temp to enter in LPM mode.
>
> }
>
> ...........................
>
> ...........................
>
>
>
> }
>
> ...........................
>
> ...........................
>
> }
>
> /******************************************************/
>
> /* ISR for Timer A */
>
> /******************************************************/
>
> #pragma vector=TIMERA0_VECTOR
>
> __interrupt void Timer_A (void)
>
> {
>
> if (Flag_LPM_Exit == 1) {
>
> __bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bits from
> 0(SR)
>
> }
>
> Else {
>
> UCA0TXBUF = 0x01; // Transmit first character
> UCA0TXBUF = 0x01;
>
> }
>
> }
>
>
>
> /************************************** CODE
> ENDS******************************************************/
>
>
>
> I have tried to execute above code, but it seems the SMCLK is not
> disabled as mentioned in LPM3 mode. I have checked by connecting
> Oscilloscope at SPI clock pin & see whether it goes off or nor or at new
> instance the clock is started or not. I am not too sure whether I am
> checking correctly or not.
>
>
>
> As I mentioned earlier, I would need to restart the SPI communication
> between ADC & uC based on some ADC data received. I thought by
> restarting the SMCLK would help.
>
>
>
> Could you provide some inputs on how to restart the SPI clock for uC
> MSP430F2xx in runtime.
>
>
>
> Kindly let me know if you need some more input.
>
> Thanks for you help.
>
>
>
> Regards,
>
>
>
> Dipti
>
>
>
> ________________________________
>
> From: m... [mailto:m...] On Behalf
> Of old_cow_yellow
> Sent: Friday, August 07, 2009 8:26 AM
> To: m...
> Subject: [msp430] Re: LPM in MSP430F2xx
>
>
>
>
>
> Now you have explained the macro definitions clearly. But I still do not
> understand what you are trying to do.
>
> You seem to have a SMCLK=8MHz and you use SMCLK/8 for the SPI controller
> to read an external ADC. Obviously, you cannot go to LPM3 when SPI is
> active. (Because there is no SMCLK in LPM3.) You also want to use
> TimerB. Are you using ACLK for TimerB? Otherwise you cannot use TimerB
> to wake up the CPU from LPM3 either. (Because in LPM3, only ACLK is
> active.)
>
> I understand that you have (a) a while loop in main, (b) an ISR for ISP
> controller, and (c) an ISR for TimerB. You should not tell CPU to go to
> LPM in (b) or (c). And you cannot tell CPU to wake up in (a). Can you
> show where are you going to invoke those macros? (And please show some
> surrounding codes so that we know the circumstances?)
>
> --- In m... ,
> wrote:
> >
> > I am using IAR debugger tool Version 4.20
> >
> >
> >
> > In the header file of "msp430x23x0.h" LPMx defined as below
> >
> > ----------------------
> > ----------------------
> >
> > #define LPM0_bits (CPUOFF)
> >
> > #define LPM1_bits (SCG0+CPUOFF)
> >
> > #define LPM2_bits (SCG1+CPUOFF)
> >
> > #define LPM3_bits (SCG1+SCG0+CPUOFF)
> >
> > #define LPM4_bits (SCG1+SCG0+OSCOFF+CPUOFF)
> >
> >
> >
> > #include
> >
> >
> >
> > #define LPM0 _BIS_SR(LPM0_bits) /* Enter Low Power Mode 0 */
> >
> > #define LPM0_EXIT _BIC_SR_IRQ(LPM0_bits) /* Exit Low Power Mode 0 */
> >
> > #define LPM1 _BIS_SR(LPM1_bits) /* Enter Low Power Mode 1 */
> >
> > #define LPM1_EXIT _BIC_SR_IRQ(LPM1_bits) /* Exit Low Power Mode 1 */
> >
> > #define LPM2 _BIS_SR(LPM2_bits) /* Enter Low Power Mode 2 */
> >
> > #define LPM2_EXIT _BIC_SR_IRQ(LPM2_bits) /* Exit Low Power Mode 2 */
> >
> > #define LPM3 _BIS_SR(LPM3_bits) /* Enter Low Power Mode 3 */
> >
> > #define LPM3_EXIT _BIC_SR_IRQ(LPM3_bits) /* Exit Low Power Mode 3 */
> >
> > #define LPM4 _BIS_SR(LPM4_bits) /* Enter Low Power Mode 4 */
> >
> > #define LPM4_EXIT _BIC_SR_IRQ(LPM4_bits) /* Exit Low Power Mode 4 */
> >
> > ----------------------
> > ----------------------
> >
> >
> >
> > I have defined below registers related to SPI.
> >
> >
> >
> > WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
> >
> > BCSCTL1 = CALBC1_8MHZ;
> >
> > DCOCTL = CALDCO_8MHZ;
> >
> > UCA0CTL0 |= UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
> >
> > UCA0CTL1 |= UCSSEL_2; // SMCLK = 8MHz / 8 = 1MHz
> >
> > UCA0BR0 |= 0x08; // /8
> >
> > UCA0BR1 = 0; //
> >
> > UCA0MCTL = 0; // No modulation
> >
> > UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state
> > machine**
> >
> > IE2 |= UCA0RXIE; // Enable USCI0 RX interrupt
> >
> > __bis_SR_register(GIE); // CPU off, enable interrupts
> >
> >
> >
> >
> >
> > Then in the while loop, if the flag is set in "__interrupt void
> > USCIA0RX_ISR(void) " then it has to enter in the LPM. In the timer B
> > interrupt [ __interrupt void Timer_B (void) ], if the same flag is
> set,
> > it has to exit from LPM.
> >
> >
> >
> > The program flow is
> >
> > 1. Set the uC SFRS,
> > 2. Initialize timers
> > 3. SPI Communication in ISR routine.
> >
> >
> >
> > In my code, based on the raw count of ADC, it needs to reset the SPI
> > clock & restart it again. Hence I thought of resetting the SPI clock
> by
> > entering into LPM & exit from LPM. I hope it works like this.
> >
> >
> >
> > Is there any other method to achieve above.
> >
> >
> >
> > Regards,
> >
> >
> >
> > Dipti
> >
> >
> >
> > ________________________________
> >
> > From: m...
> [mailto:m... ] On
> Behalf
> > Of old_cow_yellow
> > Sent: Tuesday, August 04, 2009 7:35 PM
> > To: m...
> > Subject: [msp430] Re: LPM in MSP430F2xx
> >
> >
> >
> >
> >
> > Those statements in your Method (1) and Method (2) are probably macros
> > defined in a header file.
> >
> > Depend on how they are defined, they may or may not be suitable for
> your
> > situation.
> >
> > Even when they are suitable, the debugger you use may not be able to
> > handle low power mode.
> >
> > --- In m...
> ,
> > diptipanchal wrote:
> > .
> > > I am using SPI communication to get the ADC values. I am using timer
> A
> > for
> > > writing data into SPI TX buffer (UCA0TXBUF). After every 100mS, data
> > is
> > > written into SPI buffer & read the values from SPI RX buffer. Note:
> > Using
> > > SMCLK, for SPI communication.
> > >
> > > I am trying to go in LPM3 modes based on some ADC values in the
> while
> > loop
> > > of the main function. Then exit from LPM3 mode in TimerB.
> > >
> > > Using following method for LPM3.
> > > Method (1)
> > > __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable interrupts
> > >
> > > __bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bits from 0(SR)
> > >
> > > Method (2)
> > >
> > > LPM3 // Enter LPM3,
> > > LPM3_EXIT // Clear LPM3
> > >
> > > The problem is after enter or exit of LPM3 mode(I am not too sure
> > about),
> > > the code does not go to while loop in main function. I have checked
> > with
> > > breakpoint that only ISR routine is getting executed but not the
> main
> > > function.
> > >
> > > Could anyone help how to enter & exit from LPM3 mode? How the
> program
> > > restore it back to main function. Does any one have some literature
> > about
> > > LPM modes in MSP430F2xx?
> > >
> > > Regards,
> > >
> > > Dipti
> > >
> > >
> > > --
> > >
> > >
> >
> >
> >
> >
> >
> >
> >
>
The execution fell through the bottom of you main() and end up in the c _exit code, which may be a single machine instruction that jumps to itself. That is, a one-instruction, two-cycle endless loop. If and when an interrupt is requested, the ISR is executed. After that, back to the endless loop doing nothing.
--- In m..., wrote:
>
> Here is the code snippet
>
> /************************************** CODE
> STARTS******************************************************/
>
>
>
> unsigned char Flag_Temp = 0, Cnt_Temp = 0, Flag_LPM_Exit = 0;
>
> /******************************************************/
>
> /* main function */
>
> /******************************************************/
>
> void main(void)
>
> {
>
>
>
> WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
>
> BCSCTL1 = CALBC1_8MHZ;
>
> DCOCTL = CALDCO_8MHZ;
>
>
>
> P1OUT = 0xFF; //
>
> P1DIR |= 0xFF; // P1 for output
>
> P1SEL |= 0X00; // P1 function selected
>
>
>
> P2DIR |= 0xC8; // P2.0,P2.1,P2.2,P2.4 & P2.5 as input, P2.3 as
> output
>
> // P2DIR |= 0xC4, P2.0,P2.1,P2.3,P2.4 & P2.5 as input, P2.2
> as output
>
> P2SEL |= 0XC0; // P2.0 to P2.5 for output, P2.6 XIN,P 2.7 XOUT -
> active
>
> P2OUT |= 0x80;
>
>
>
> P3DIR |= 0xFF; // P3.7 & P3.6 out
>
> P3SEL |= 0x37; // P3.0,4,5 USCI_A0 option
> select
>
> P3OUT = 0xC8; // Set slave reset,gain 128,
> PDWN=1
>
>
>
> P4DIR |= 0xFF; // P4.0 & P4.1 out
>
> P4SEL |= 0x00; // P3.0,4,5 USCI_A0 option
> select
>
>
>
> UCA0CTL0 |= UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
>
> UCA0CTL1 |= UCSSEL_2; // SMCLK
>
> UCA0BR0 |= 0x08; // /8
>
> UCA0BR1 = 0; //
>
> UCA0MCTL = 0; // No modulation
>
> UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state
> machine**
>
> IE2 |= UCA0RXIE; // Enable USCI0 RX interrupt
>
>
>
> P3OUT &= ~0x40; // Now with SPI signals
> initialized,
>
> P3OUT |= 0x40; // reset slave
>
> __bis_SR_register(GIE); // CPU off, enable interrupts
>
>
>
>
>
> TBCTL = TBSSEL_1 + TBCLR; // ACLK, clear TBR, divider=1
>
> TBCCTL0 = CCIE; // TBCCR0 interrupt enabled
>
> TBCCR0 = 0x8F5;
>
> TBCTL = TBSSEL_1 + MC_1; // ACLK, upmode
>
>
>
> TACCTL0 = CCIE; // TACCR0 interrupt enabled
>
> TACCR0 = 0x0D16; //100mS,
>
> TACTL = TASSEL_1 + MC_1; // ACLK, upmode,, divider=1
>
>
>
> ...........................
>
> ...........................
>
> ...........................
>
> //Code for ADC raw count & display.
>
> ...........................
>
> ........................
>
> If (Flag_Noscl== 1)
>
> {
>
> ...........................
>
> ...........................
>
> if (Flag_Temp == 1) {
>
> Flag_Temp = 0; // reset Flag_Temp
> to sero so only once it will enter into LPM3 mode.
>
> Flag_LPM_Exit = 1;
>
> __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable
> interrupts
>
> }
>
> }
>
>
>
> } // main
>
>
>
> /******************************************************/
>
> /* ISR for ADC data */
>
> /* Setting & resetting of the Flag_Noscl */
>
> /*happens in this ISR based on the ADC value */
>
> /*recevied from the ADC. */
>
> /******************************************************/
>
> #pragma vector=USCIAB0RX_VECTOR
>
> __interrupt void USCIA0RX_ISR(void)
>
> {
>
> long int adc_data3,adc_data2,adc_data1;
>
>
>
> while (!(IFG2 & UCA0RXIFG)); // USCI_A0 TX buffer ready?
>
> adc_data1 = UCA0RXBUF;
>
> adc_data1 = adc_data1 << 16;
>
> ...........................
>
> ...........................
>
> if (some condition )
>
> {
>
> ...........................
>
> ...........................
>
>
>
> Flag_Noscl = 0;
>
> Flag_Temp = 0;
>
> Cnt_Temp = 0;
>
> ...........................
>
> ...........................
>
>
>
>
>
> }
>
> else
>
> {
>
> Flag_Noscl = 1;
>
> Cnt_Temp++;
>
> if ((Flag_Noscl == 1) && (Cnt_Temp==1)) {
>
> Flag_Temp = 1;
>
> Flag_LPM_Exit = 0;
>
> }
>
> if (Cnt_Temp >= 20) {
>
> Cnt_Temp = 0; // Cnt_Temp is reset to 0, so if the
> Flag_Noscl is set & Cnt_Temp is reached 20 , then it would again set the
> Flag_Temp to enter in LPM mode.
>
> }
>
> ...........................
>
> ...........................
>
>
>
> }
>
> ...........................
>
> ...........................
>
> }
>
> /******************************************************/
>
> /* ISR for Timer A */
>
> /******************************************************/
>
> #pragma vector=TIMERA0_VECTOR
>
> __interrupt void Timer_A (void)
>
> {
>
> if (Flag_LPM_Exit == 1) {
>
> __bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bits from
> 0(SR)
>
> }
>
> Else {
>
> UCA0TXBUF = 0x01; // Transmit first character
> UCA0TXBUF = 0x01;
>
> }
>
> }
>
>
>
> /************************************** CODE
> ENDS******************************************************/
>
>
>
> I have tried to execute above code, but it seems the SMCLK is not
> disabled as mentioned in LPM3 mode. I have checked by connecting
> Oscilloscope at SPI clock pin & see whether it goes off or nor or at new
> instance the clock is started or not. I am not too sure whether I am
> checking correctly or not.
>
>
>
> As I mentioned earlier, I would need to restart the SPI communication
> between ADC & uC based on some ADC data received. I thought by
> restarting the SMCLK would help.
>
>
>
> Could you provide some inputs on how to restart the SPI clock for uC
> MSP430F2xx in runtime.
>
>
>
> Kindly let me know if you need some more input.
>
> Thanks for you help.
>
>
>
> Regards,
>
>
>
> Dipti
>
>
>
> ________________________________
>
> From: m... [mailto:m...] On Behalf
> Of old_cow_yellow
> Sent: Friday, August 07, 2009 8:26 AM
> To: m...
> Subject: [msp430] Re: LPM in MSP430F2xx
>
>
>
>
>
> Now you have explained the macro definitions clearly. But I still do not
> understand what you are trying to do.
>
> You seem to have a SMCLK=8MHz and you use SMCLK/8 for the SPI controller
> to read an external ADC. Obviously, you cannot go to LPM3 when SPI is
> active. (Because there is no SMCLK in LPM3.) You also want to use
> TimerB. Are you using ACLK for TimerB? Otherwise you cannot use TimerB
> to wake up the CPU from LPM3 either. (Because in LPM3, only ACLK is
> active.)
>
> I understand that you have (a) a while loop in main, (b) an ISR for ISP
> controller, and (c) an ISR for TimerB. You should not tell CPU to go to
> LPM in (b) or (c). And you cannot tell CPU to wake up in (a). Can you
> show where are you going to invoke those macros? (And please show some
> surrounding codes so that we know the circumstances?)
>
> --- In m... ,
> wrote:
> >
> > I am using IAR debugger tool Version 4.20
> >
> >
> >
> > In the header file of "msp430x23x0.h" LPMx defined as below
> >
> > ----------------------
> > ----------------------
> >
> > #define LPM0_bits (CPUOFF)
> >
> > #define LPM1_bits (SCG0+CPUOFF)
> >
> > #define LPM2_bits (SCG1+CPUOFF)
> >
> > #define LPM3_bits (SCG1+SCG0+CPUOFF)
> >
> > #define LPM4_bits (SCG1+SCG0+OSCOFF+CPUOFF)
> >
> >
> >
> > #include
> >
> >
> >
> > #define LPM0 _BIS_SR(LPM0_bits) /* Enter Low Power Mode 0 */
> >
> > #define LPM0_EXIT _BIC_SR_IRQ(LPM0_bits) /* Exit Low Power Mode 0 */
> >
> > #define LPM1 _BIS_SR(LPM1_bits) /* Enter Low Power Mode 1 */
> >
> > #define LPM1_EXIT _BIC_SR_IRQ(LPM1_bits) /* Exit Low Power Mode 1 */
> >
> > #define LPM2 _BIS_SR(LPM2_bits) /* Enter Low Power Mode 2 */
> >
> > #define LPM2_EXIT _BIC_SR_IRQ(LPM2_bits) /* Exit Low Power Mode 2 */
> >
> > #define LPM3 _BIS_SR(LPM3_bits) /* Enter Low Power Mode 3 */
> >
> > #define LPM3_EXIT _BIC_SR_IRQ(LPM3_bits) /* Exit Low Power Mode 3 */
> >
> > #define LPM4 _BIS_SR(LPM4_bits) /* Enter Low Power Mode 4 */
> >
> > #define LPM4_EXIT _BIC_SR_IRQ(LPM4_bits) /* Exit Low Power Mode 4 */
> >
> > ----------------------
> > ----------------------
> >
> >
> >
> > I have defined below registers related to SPI.
> >
> >
> >
> > WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
> >
> > BCSCTL1 = CALBC1_8MHZ;
> >
> > DCOCTL = CALDCO_8MHZ;
> >
> > UCA0CTL0 |= UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
> >
> > UCA0CTL1 |= UCSSEL_2; // SMCLK = 8MHz / 8 = 1MHz
> >
> > UCA0BR0 |= 0x08; // /8
> >
> > UCA0BR1 = 0; //
> >
> > UCA0MCTL = 0; // No modulation
> >
> > UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state
> > machine**
> >
> > IE2 |= UCA0RXIE; // Enable USCI0 RX interrupt
> >
> > __bis_SR_register(GIE); // CPU off, enable interrupts
> >
> >
> >
> >
> >
> > Then in the while loop, if the flag is set in "__interrupt void
> > USCIA0RX_ISR(void) " then it has to enter in the LPM. In the timer B
> > interrupt [ __interrupt void Timer_B (void) ], if the same flag is
> set,
> > it has to exit from LPM.
> >
> >
> >
> > The program flow is
> >
> > 1. Set the uC SFRS,
> > 2. Initialize timers
> > 3. SPI Communication in ISR routine.
> >
> >
> >
> > In my code, based on the raw count of ADC, it needs to reset the SPI
> > clock & restart it again. Hence I thought of resetting the SPI clock
> by
> > entering into LPM & exit from LPM. I hope it works like this.
> >
> >
> >
> > Is there any other method to achieve above.
> >
> >
> >
> > Regards,
> >
> >
> >
> > Dipti
> >
> >
> >
> > ________________________________
> >
> > From: m...
> [mailto:m... ] On
> Behalf
> > Of old_cow_yellow
> > Sent: Tuesday, August 04, 2009 7:35 PM
> > To: m...
> > Subject: [msp430] Re: LPM in MSP430F2xx
> >
> >
> >
> >
> >
> > Those statements in your Method (1) and Method (2) are probably macros
> > defined in a header file.
> >
> > Depend on how they are defined, they may or may not be suitable for
> your
> > situation.
> >
> > Even when they are suitable, the debugger you use may not be able to
> > handle low power mode.
> >
> > --- In m...
> ,
> > diptipanchal wrote:
> > .
> > > I am using SPI communication to get the ADC values. I am using timer
> A
> > for
> > > writing data into SPI TX buffer (UCA0TXBUF). After every 100mS, data
> > is
> > > written into SPI buffer & read the values from SPI RX buffer. Note:
> > Using
> > > SMCLK, for SPI communication.
> > >
> > > I am trying to go in LPM3 modes based on some ADC values in the
> while
> > loop
> > > of the main function. Then exit from LPM3 mode in TimerB.
> > >
> > > Using following method for LPM3.
> > > Method (1)
> > > __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable interrupts
> > >
> > > __bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bits from 0(SR)
> > >
> > > Method (2)
> > >
> > > LPM3 // Enter LPM3,
> > > LPM3_EXIT // Clear LPM3
> > >
> > > The problem is after enter or exit of LPM3 mode(I am not too sure
> > about),
> > > the code does not go to while loop in main function. I have checked
> > with
> > > breakpoint that only ISR routine is getting executed but not the
> main
> > > function.
> > >
> > > Could anyone help how to enter & exit from LPM3 mode? How the
> program
> > > restore it back to main function. Does any one have some literature
> > about
> > > LPM modes in MSP430F2xx?
> > >
> > > Regards,
> > >
> > > Dipti
> > >
> > >
> > > --
> > >
> > >
> >
> >
> >
> >
> >
> >
> >
>
Reply by ●August 11, 20092009-08-11
No, my problem is not yet resolved.
I need to restart the SMClock since I want to restart SPI communication.
How do I do that?
Is there any method by which I could restart SPI communication between
uC & ADC during runtime?
________________________________
From: m... [mailto:m...] On Behalf
Of old_cow_yellow
Sent: Monday, August 10, 2009 9:38 PM
To: m...
Subject: [msp430] Re: LPM in MSP430F2xx
Sorry, I had a hard time following your code. The mail system strips all
indentations and splits some of the lines. (And I do not worship c.) May
be you have already solved your problems. But this is what I think:
The execution fell through the bottom of you main() and end up in the c
_exit code, which may be a single machine instruction that jumps to
itself. That is, a one-instruction, two-cycle endless loop. If and when
an interrupt is requested, the ISR is executed. After that, back to the
endless loop doing nothing.
--- In m... ,
wrote:
>
> Here is the code snippet
>
> /************************************** CODE
> STARTS******************************************************/
>
> unsigned char Flag_Temp = 0, Cnt_Temp = 0, Flag_LPM_Exit = 0;
>
> /******************************************************/
>
> /* main function */
>
> /******************************************************/
>
> void main(void)
>
> {
>
> WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
>
> BCSCTL1 = CALBC1_8MHZ;
>
> DCOCTL = CALDCO_8MHZ;
>
> P1OUT = 0xFF; //
>
> P1DIR |= 0xFF; // P1 for output
>
> P1SEL |= 0X00; // P1 function selected
>
> P2DIR |= 0xC8; // P2.0,P2.1,P2.2,P2.4 & P2.5 as input, P2.3 as
> output
>
> // P2DIR |= 0xC4, P2.0,P2.1,P2.3,P2.4 & P2.5 as input, P2.2
> as output
>
> P2SEL |= 0XC0; // P2.0 to P2.5 for output, P2.6 XIN,P 2.7 XOUT -
> active
>
> P2OUT |= 0x80;
>
> P3DIR |= 0xFF; // P3.7 & P3.6 out
>
> P3SEL |= 0x37; // P3.0,4,5 USCI_A0 option
> select
>
> P3OUT = 0xC8; // Set slave reset,gain 128,
> PDWN=1
>
> P4DIR |= 0xFF; // P4.0 & P4.1 out
>
> P4SEL |= 0x00; // P3.0,4,5 USCI_A0 option
> select
>
> UCA0CTL0 |= UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
>
> UCA0CTL1 |= UCSSEL_2; // SMCLK
>
> UCA0BR0 |= 0x08; // /8
>
> UCA0BR1 = 0; //
>
> UCA0MCTL = 0; // No modulation
>
> UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state
> machine**
>
> IE2 |= UCA0RXIE; // Enable USCI0 RX interrupt
>
> P3OUT &= ~0x40; // Now with SPI signals
> initialized,
>
> P3OUT |= 0x40; // reset slave
>
> __bis_SR_register(GIE); // CPU off, enable interrupts
>
> TBCTL = TBSSEL_1 + TBCLR; // ACLK, clear TBR, divider=1
>
> TBCCTL0 = CCIE; // TBCCR0 interrupt enabled
>
> TBCCR0 = 0x8F5;
>
> TBCTL = TBSSEL_1 + MC_1; // ACLK, upmode
>
> TACCTL0 = CCIE; // TACCR0 interrupt enabled
>
> TACCR0 = 0x0D16; //100mS,
>
> TACTL = TASSEL_1 + MC_1; // ACLK, upmode,, divider=1
>
> ...........................
>
> ...........................
>
> ...........................
>
> //Code for ADC raw count & display.
>
> ...........................
>
> ........................
>
> If (Flag_Noscl== 1)
>
> {
>
> ...........................
>
> ...........................
>
> if (Flag_Temp == 1) {
>
> Flag_Temp = 0; // reset Flag_Temp
> to sero so only once it will enter into LPM3 mode.
>
> Flag_LPM_Exit = 1;
>
> __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable
> interrupts
>
> }
>
> }
>
> } // main
>
> /******************************************************/
>
> /* ISR for ADC data */
>
> /* Setting & resetting of the Flag_Noscl */
>
> /*happens in this ISR based on the ADC value */
>
> /*recevied from the ADC. */
>
> /******************************************************/
>
> #pragma vector=USCIAB0RX_VECTOR
>
> __interrupt void USCIA0RX_ISR(void)
>
> {
>
> long int adc_data3,adc_data2,adc_data1;
>
> while (!(IFG2 & UCA0RXIFG)); // USCI_A0 TX buffer ready?
>
> adc_data1 = UCA0RXBUF;
>
> adc_data1 = adc_data1 << 16;
>
> ...........................
>
> ...........................
>
> if (some condition )
>
> {
>
> ...........................
>
> ...........................
>
> Flag_Noscl = 0;
>
> Flag_Temp = 0;
>
> Cnt_Temp = 0;
>
> ...........................
>
> ...........................
>
> }
>
> else
>
> {
>
> Flag_Noscl = 1;
>
> Cnt_Temp++;
>
> if ((Flag_Noscl == 1) && (Cnt_Temp==1)) {
>
> Flag_Temp = 1;
>
> Flag_LPM_Exit = 0;
>
> }
>
> if (Cnt_Temp >= 20) {
>
> Cnt_Temp = 0; // Cnt_Temp is reset to 0, so if the
> Flag_Noscl is set & Cnt_Temp is reached 20 , then it would again set
the
> Flag_Temp to enter in LPM mode.
>
> }
>
> ...........................
>
> ...........................
>
> }
>
> ...........................
>
> ...........................
>
> }
>
> /******************************************************/
>
> /* ISR for Timer A */
>
> /******************************************************/
>
> #pragma vector=TIMERA0_VECTOR
>
> __interrupt void Timer_A (void)
>
> {
>
> if (Flag_LPM_Exit == 1) {
>
> __bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bits from
> 0(SR)
>
> }
>
> Else {
>
> UCA0TXBUF = 0x01; // Transmit first character
> UCA0TXBUF = 0x01;
>
> }
>
> }
>
> /************************************** CODE
> ENDS******************************************************/
>
> I have tried to execute above code, but it seems the SMCLK is not
> disabled as mentioned in LPM3 mode. I have checked by connecting
> Oscilloscope at SPI clock pin & see whether it goes off or nor or at
new
> instance the clock is started or not. I am not too sure whether I am
> checking correctly or not.
>
> As I mentioned earlier, I would need to restart the SPI communication
> between ADC & uC based on some ADC data received. I thought by
> restarting the SMCLK would help.
>
> Could you provide some inputs on how to restart the SPI clock for uC
> MSP430F2xx in runtime.
>
> Kindly let me know if you need some more input.
>
> Thanks for you help.
>
> Regards,
>
> Dipti
>
> ________________________________
>
> From: m...
[mailto:m... ] On
Behalf
> Of old_cow_yellow
> Sent: Friday, August 07, 2009 8:26 AM
> To: m...
> Subject: [msp430] Re: LPM in MSP430F2xx
>
> Now you have explained the macro definitions clearly. But I still do
not
> understand what you are trying to do.
>
> You seem to have a SMCLK=8MHz and you use SMCLK/8 for the SPI
controller
> to read an external ADC. Obviously, you cannot go to LPM3 when SPI is
> active. (Because there is no SMCLK in LPM3.) You also want to use
> TimerB. Are you using ACLK for TimerB? Otherwise you cannot use TimerB
> to wake up the CPU from LPM3 either. (Because in LPM3, only ACLK is
> active.)
>
> I understand that you have (a) a while loop in main, (b) an ISR for
ISP
> controller, and (c) an ISR for TimerB. You should not tell CPU to go
to
> LPM in (b) or (c). And you cannot tell CPU to wake up in (a). Can you
> show where are you going to invoke those macros? (And please show some
> surrounding codes so that we know the circumstances?)
>
> --- In m...
,
> wrote:
> >
> > I am using IAR debugger tool Version 4.20
> >
> >
> >
> > In the header file of "msp430x23x0.h" LPMx defined as below
> >
> > ----------------------
> > ----------------------
> >
> > #define LPM0_bits (CPUOFF)
> >
> > #define LPM1_bits (SCG0+CPUOFF)
> >
> > #define LPM2_bits (SCG1+CPUOFF)
> >
> > #define LPM3_bits (SCG1+SCG0+CPUOFF)
> >
> > #define LPM4_bits (SCG1+SCG0+OSCOFF+CPUOFF)
> >
> >
> >
> > #include
> >
> >
> >
> > #define LPM0 _BIS_SR(LPM0_bits) /* Enter Low Power Mode 0 */
> >
> > #define LPM0_EXIT _BIC_SR_IRQ(LPM0_bits) /* Exit Low Power Mode 0 */
> >
> > #define LPM1 _BIS_SR(LPM1_bits) /* Enter Low Power Mode 1 */
> >
> > #define LPM1_EXIT _BIC_SR_IRQ(LPM1_bits) /* Exit Low Power Mode 1 */
> >
> > #define LPM2 _BIS_SR(LPM2_bits) /* Enter Low Power Mode 2 */
> >
> > #define LPM2_EXIT _BIC_SR_IRQ(LPM2_bits) /* Exit Low Power Mode 2 */
> >
> > #define LPM3 _BIS_SR(LPM3_bits) /* Enter Low Power Mode 3 */
> >
> > #define LPM3_EXIT _BIC_SR_IRQ(LPM3_bits) /* Exit Low Power Mode 3 */
> >
> > #define LPM4 _BIS_SR(LPM4_bits) /* Enter Low Power Mode 4 */
> >
> > #define LPM4_EXIT _BIC_SR_IRQ(LPM4_bits) /* Exit Low Power Mode 4 */
> >
> > ----------------------
> > ----------------------
> >
> >
> >
> > I have defined below registers related to SPI.
> >
> >
> >
> > WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
> >
> > BCSCTL1 = CALBC1_8MHZ;
> >
> > DCOCTL = CALDCO_8MHZ;
> >
> > UCA0CTL0 |= UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
> >
> > UCA0CTL1 |= UCSSEL_2; // SMCLK = 8MHz / 8 = 1MHz
> >
> > UCA0BR0 |= 0x08; // /8
> >
> > UCA0BR1 = 0; //
> >
> > UCA0MCTL = 0; // No modulation
> >
> > UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state
> > machine**
> >
> > IE2 |= UCA0RXIE; // Enable USCI0 RX interrupt
> >
> > __bis_SR_register(GIE); // CPU off, enable interrupts
> >
> >
> >
> >
> >
> > Then in the while loop, if the flag is set in "__interrupt void
> > USCIA0RX_ISR(void) " then it has to enter in the LPM. In the timer B
> > interrupt [ __interrupt void Timer_B (void) ], if the same flag is
> set,
> > it has to exit from LPM.
> >
> >
> >
> > The program flow is
> >
> > 1. Set the uC SFRS,
> > 2. Initialize timers
> > 3. SPI Communication in ISR routine.
> >
> >
> >
> > In my code, based on the raw count of ADC, it needs to reset the SPI
> > clock & restart it again. Hence I thought of resetting the SPI clock
> by
> > entering into LPM & exit from LPM. I hope it works like this.
> >
> >
> >
> > Is there any other method to achieve above.
> >
> >
> >
> > Regards,
> >
> >
> >
> > Dipti
> >
> >
> >
> > ________________________________
> >
> > From: m...
> [mailto:m...
] On
> Behalf
> > Of old_cow_yellow
> > Sent: Tuesday, August 04, 2009 7:35 PM
> > To: m...
> > Subject: [msp430] Re: LPM in MSP430F2xx
> >
> >
> >
> >
> >
> > Those statements in your Method (1) and Method (2) are probably
macros
> > defined in a header file.
> >
> > Depend on how they are defined, they may or may not be suitable for
> your
> > situation.
> >
> > Even when they are suitable, the debugger you use may not be able to
> > handle low power mode.
> >
> > --- In m...
> ,
> > diptipanchal wrote:
> > .
> > > I am using SPI communication to get the ADC values. I am using
timer
> A
> > for
> > > writing data into SPI TX buffer (UCA0TXBUF). After every 100mS,
data
> > is
> > > written into SPI buffer & read the values from SPI RX buffer.
Note:
> > Using
> > > SMCLK, for SPI communication.
> > >
> > > I am trying to go in LPM3 modes based on some ADC values in the
> while
> > loop
> > > of the main function. Then exit from LPM3 mode in TimerB.
> > >
> > > Using following method for LPM3.
> > > Method (1)
> > > __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable
interrupts
> > >
> > > __bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bits from
0(SR)
> > >
> > > Method (2)
> > >
> > > LPM3 // Enter LPM3,
> > > LPM3_EXIT // Clear LPM3
> > >
> > > The problem is after enter or exit of LPM3 mode(I am not too sure
> > about),
> > > the code does not go to while loop in main function. I have
checked
> > with
> > > breakpoint that only ISR routine is getting executed but not the
> main
> > > function.
> > >
> > > Could anyone help how to enter & exit from LPM3 mode? How the
> program
> > > restore it back to main function. Does any one have some
literature
> > about
> > > LPM modes in MSP430F2xx?
> > >
> > > Regards,
> > >
> > > Dipti
> > >
> > >
> > > --
> > >
> > >
> >
> >
> >
> >
> >
> >
> >
>
I need to restart the SMClock since I want to restart SPI communication.
How do I do that?
Is there any method by which I could restart SPI communication between
uC & ADC during runtime?
________________________________
From: m... [mailto:m...] On Behalf
Of old_cow_yellow
Sent: Monday, August 10, 2009 9:38 PM
To: m...
Subject: [msp430] Re: LPM in MSP430F2xx
Sorry, I had a hard time following your code. The mail system strips all
indentations and splits some of the lines. (And I do not worship c.) May
be you have already solved your problems. But this is what I think:
The execution fell through the bottom of you main() and end up in the c
_exit code, which may be a single machine instruction that jumps to
itself. That is, a one-instruction, two-cycle endless loop. If and when
an interrupt is requested, the ISR is executed. After that, back to the
endless loop doing nothing.
--- In m... ,
wrote:
>
> Here is the code snippet
>
> /************************************** CODE
> STARTS******************************************************/
>
> unsigned char Flag_Temp = 0, Cnt_Temp = 0, Flag_LPM_Exit = 0;
>
> /******************************************************/
>
> /* main function */
>
> /******************************************************/
>
> void main(void)
>
> {
>
> WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
>
> BCSCTL1 = CALBC1_8MHZ;
>
> DCOCTL = CALDCO_8MHZ;
>
> P1OUT = 0xFF; //
>
> P1DIR |= 0xFF; // P1 for output
>
> P1SEL |= 0X00; // P1 function selected
>
> P2DIR |= 0xC8; // P2.0,P2.1,P2.2,P2.4 & P2.5 as input, P2.3 as
> output
>
> // P2DIR |= 0xC4, P2.0,P2.1,P2.3,P2.4 & P2.5 as input, P2.2
> as output
>
> P2SEL |= 0XC0; // P2.0 to P2.5 for output, P2.6 XIN,P 2.7 XOUT -
> active
>
> P2OUT |= 0x80;
>
> P3DIR |= 0xFF; // P3.7 & P3.6 out
>
> P3SEL |= 0x37; // P3.0,4,5 USCI_A0 option
> select
>
> P3OUT = 0xC8; // Set slave reset,gain 128,
> PDWN=1
>
> P4DIR |= 0xFF; // P4.0 & P4.1 out
>
> P4SEL |= 0x00; // P3.0,4,5 USCI_A0 option
> select
>
> UCA0CTL0 |= UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
>
> UCA0CTL1 |= UCSSEL_2; // SMCLK
>
> UCA0BR0 |= 0x08; // /8
>
> UCA0BR1 = 0; //
>
> UCA0MCTL = 0; // No modulation
>
> UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state
> machine**
>
> IE2 |= UCA0RXIE; // Enable USCI0 RX interrupt
>
> P3OUT &= ~0x40; // Now with SPI signals
> initialized,
>
> P3OUT |= 0x40; // reset slave
>
> __bis_SR_register(GIE); // CPU off, enable interrupts
>
> TBCTL = TBSSEL_1 + TBCLR; // ACLK, clear TBR, divider=1
>
> TBCCTL0 = CCIE; // TBCCR0 interrupt enabled
>
> TBCCR0 = 0x8F5;
>
> TBCTL = TBSSEL_1 + MC_1; // ACLK, upmode
>
> TACCTL0 = CCIE; // TACCR0 interrupt enabled
>
> TACCR0 = 0x0D16; //100mS,
>
> TACTL = TASSEL_1 + MC_1; // ACLK, upmode,, divider=1
>
> ...........................
>
> ...........................
>
> ...........................
>
> //Code for ADC raw count & display.
>
> ...........................
>
> ........................
>
> If (Flag_Noscl== 1)
>
> {
>
> ...........................
>
> ...........................
>
> if (Flag_Temp == 1) {
>
> Flag_Temp = 0; // reset Flag_Temp
> to sero so only once it will enter into LPM3 mode.
>
> Flag_LPM_Exit = 1;
>
> __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable
> interrupts
>
> }
>
> }
>
> } // main
>
> /******************************************************/
>
> /* ISR for ADC data */
>
> /* Setting & resetting of the Flag_Noscl */
>
> /*happens in this ISR based on the ADC value */
>
> /*recevied from the ADC. */
>
> /******************************************************/
>
> #pragma vector=USCIAB0RX_VECTOR
>
> __interrupt void USCIA0RX_ISR(void)
>
> {
>
> long int adc_data3,adc_data2,adc_data1;
>
> while (!(IFG2 & UCA0RXIFG)); // USCI_A0 TX buffer ready?
>
> adc_data1 = UCA0RXBUF;
>
> adc_data1 = adc_data1 << 16;
>
> ...........................
>
> ...........................
>
> if (some condition )
>
> {
>
> ...........................
>
> ...........................
>
> Flag_Noscl = 0;
>
> Flag_Temp = 0;
>
> Cnt_Temp = 0;
>
> ...........................
>
> ...........................
>
> }
>
> else
>
> {
>
> Flag_Noscl = 1;
>
> Cnt_Temp++;
>
> if ((Flag_Noscl == 1) && (Cnt_Temp==1)) {
>
> Flag_Temp = 1;
>
> Flag_LPM_Exit = 0;
>
> }
>
> if (Cnt_Temp >= 20) {
>
> Cnt_Temp = 0; // Cnt_Temp is reset to 0, so if the
> Flag_Noscl is set & Cnt_Temp is reached 20 , then it would again set
the
> Flag_Temp to enter in LPM mode.
>
> }
>
> ...........................
>
> ...........................
>
> }
>
> ...........................
>
> ...........................
>
> }
>
> /******************************************************/
>
> /* ISR for Timer A */
>
> /******************************************************/
>
> #pragma vector=TIMERA0_VECTOR
>
> __interrupt void Timer_A (void)
>
> {
>
> if (Flag_LPM_Exit == 1) {
>
> __bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bits from
> 0(SR)
>
> }
>
> Else {
>
> UCA0TXBUF = 0x01; // Transmit first character
> UCA0TXBUF = 0x01;
>
> }
>
> }
>
> /************************************** CODE
> ENDS******************************************************/
>
> I have tried to execute above code, but it seems the SMCLK is not
> disabled as mentioned in LPM3 mode. I have checked by connecting
> Oscilloscope at SPI clock pin & see whether it goes off or nor or at
new
> instance the clock is started or not. I am not too sure whether I am
> checking correctly or not.
>
> As I mentioned earlier, I would need to restart the SPI communication
> between ADC & uC based on some ADC data received. I thought by
> restarting the SMCLK would help.
>
> Could you provide some inputs on how to restart the SPI clock for uC
> MSP430F2xx in runtime.
>
> Kindly let me know if you need some more input.
>
> Thanks for you help.
>
> Regards,
>
> Dipti
>
> ________________________________
>
> From: m...
[mailto:m... ] On
Behalf
> Of old_cow_yellow
> Sent: Friday, August 07, 2009 8:26 AM
> To: m...
> Subject: [msp430] Re: LPM in MSP430F2xx
>
> Now you have explained the macro definitions clearly. But I still do
not
> understand what you are trying to do.
>
> You seem to have a SMCLK=8MHz and you use SMCLK/8 for the SPI
controller
> to read an external ADC. Obviously, you cannot go to LPM3 when SPI is
> active. (Because there is no SMCLK in LPM3.) You also want to use
> TimerB. Are you using ACLK for TimerB? Otherwise you cannot use TimerB
> to wake up the CPU from LPM3 either. (Because in LPM3, only ACLK is
> active.)
>
> I understand that you have (a) a while loop in main, (b) an ISR for
ISP
> controller, and (c) an ISR for TimerB. You should not tell CPU to go
to
> LPM in (b) or (c). And you cannot tell CPU to wake up in (a). Can you
> show where are you going to invoke those macros? (And please show some
> surrounding codes so that we know the circumstances?)
>
> --- In m...
,
> wrote:
> >
> > I am using IAR debugger tool Version 4.20
> >
> >
> >
> > In the header file of "msp430x23x0.h" LPMx defined as below
> >
> > ----------------------
> > ----------------------
> >
> > #define LPM0_bits (CPUOFF)
> >
> > #define LPM1_bits (SCG0+CPUOFF)
> >
> > #define LPM2_bits (SCG1+CPUOFF)
> >
> > #define LPM3_bits (SCG1+SCG0+CPUOFF)
> >
> > #define LPM4_bits (SCG1+SCG0+OSCOFF+CPUOFF)
> >
> >
> >
> > #include
> >
> >
> >
> > #define LPM0 _BIS_SR(LPM0_bits) /* Enter Low Power Mode 0 */
> >
> > #define LPM0_EXIT _BIC_SR_IRQ(LPM0_bits) /* Exit Low Power Mode 0 */
> >
> > #define LPM1 _BIS_SR(LPM1_bits) /* Enter Low Power Mode 1 */
> >
> > #define LPM1_EXIT _BIC_SR_IRQ(LPM1_bits) /* Exit Low Power Mode 1 */
> >
> > #define LPM2 _BIS_SR(LPM2_bits) /* Enter Low Power Mode 2 */
> >
> > #define LPM2_EXIT _BIC_SR_IRQ(LPM2_bits) /* Exit Low Power Mode 2 */
> >
> > #define LPM3 _BIS_SR(LPM3_bits) /* Enter Low Power Mode 3 */
> >
> > #define LPM3_EXIT _BIC_SR_IRQ(LPM3_bits) /* Exit Low Power Mode 3 */
> >
> > #define LPM4 _BIS_SR(LPM4_bits) /* Enter Low Power Mode 4 */
> >
> > #define LPM4_EXIT _BIC_SR_IRQ(LPM4_bits) /* Exit Low Power Mode 4 */
> >
> > ----------------------
> > ----------------------
> >
> >
> >
> > I have defined below registers related to SPI.
> >
> >
> >
> > WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
> >
> > BCSCTL1 = CALBC1_8MHZ;
> >
> > DCOCTL = CALDCO_8MHZ;
> >
> > UCA0CTL0 |= UCMSB + UCMST + UCSYNC; // 3-pin, 8-bit SPI master
> >
> > UCA0CTL1 |= UCSSEL_2; // SMCLK = 8MHz / 8 = 1MHz
> >
> > UCA0BR0 |= 0x08; // /8
> >
> > UCA0BR1 = 0; //
> >
> > UCA0MCTL = 0; // No modulation
> >
> > UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state
> > machine**
> >
> > IE2 |= UCA0RXIE; // Enable USCI0 RX interrupt
> >
> > __bis_SR_register(GIE); // CPU off, enable interrupts
> >
> >
> >
> >
> >
> > Then in the while loop, if the flag is set in "__interrupt void
> > USCIA0RX_ISR(void) " then it has to enter in the LPM. In the timer B
> > interrupt [ __interrupt void Timer_B (void) ], if the same flag is
> set,
> > it has to exit from LPM.
> >
> >
> >
> > The program flow is
> >
> > 1. Set the uC SFRS,
> > 2. Initialize timers
> > 3. SPI Communication in ISR routine.
> >
> >
> >
> > In my code, based on the raw count of ADC, it needs to reset the SPI
> > clock & restart it again. Hence I thought of resetting the SPI clock
> by
> > entering into LPM & exit from LPM. I hope it works like this.
> >
> >
> >
> > Is there any other method to achieve above.
> >
> >
> >
> > Regards,
> >
> >
> >
> > Dipti
> >
> >
> >
> > ________________________________
> >
> > From: m...
> [mailto:m...
] On
> Behalf
> > Of old_cow_yellow
> > Sent: Tuesday, August 04, 2009 7:35 PM
> > To: m...
> > Subject: [msp430] Re: LPM in MSP430F2xx
> >
> >
> >
> >
> >
> > Those statements in your Method (1) and Method (2) are probably
macros
> > defined in a header file.
> >
> > Depend on how they are defined, they may or may not be suitable for
> your
> > situation.
> >
> > Even when they are suitable, the debugger you use may not be able to
> > handle low power mode.
> >
> > --- In m...
> ,
> > diptipanchal wrote:
> > .
> > > I am using SPI communication to get the ADC values. I am using
timer
> A
> > for
> > > writing data into SPI TX buffer (UCA0TXBUF). After every 100mS,
data
> > is
> > > written into SPI buffer & read the values from SPI RX buffer.
Note:
> > Using
> > > SMCLK, for SPI communication.
> > >
> > > I am trying to go in LPM3 modes based on some ADC values in the
> while
> > loop
> > > of the main function. Then exit from LPM3 mode in TimerB.
> > >
> > > Using following method for LPM3.
> > > Method (1)
> > > __bis_SR_register(LPM3_bits + GIE); // Enter LPM3, enable
interrupts
> > >
> > > __bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bits from
0(SR)
> > >
> > > Method (2)
> > >
> > > LPM3 // Enter LPM3,
> > > LPM3_EXIT // Clear LPM3
> > >
> > > The problem is after enter or exit of LPM3 mode(I am not too sure
> > about),
> > > the code does not go to while loop in main function. I have
checked
> > with
> > > breakpoint that only ISR routine is getting executed but not the
> main
> > > function.
> > >
> > > Could anyone help how to enter & exit from LPM3 mode? How the
> program
> > > restore it back to main function. Does any one have some
literature
> > about
> > > LPM modes in MSP430F2xx?
> > >
> > > Regards,
> > >
> > > Dipti
> > >
> > >
> > > --
> > >
> > >
> >
> >
> >
> >
> >
> >
> >
>