EmbeddedRelated.com
Forums

LPM in MSP430F2xx

Started by diptipanchal August 4, 2009
I did not see the while loop that you mentioned in your first posting. The go to LPM3 instruction is in two layers of if statements. Thus either you exit the main without go to LPM3. or you go to LPM3 and wait for wake-up by TimerA. But once awake, main also exits. Thus either way you end up exiting main.

This is what I see:
==================void main (void)
{ //begin main
......
if (......)
{ //begin outer if
......
if (......)
{ //begin inner if
......
go-to=LPM3;
} //end inner if
} //end outer if
} //end main
===================
I this the structure of your main()?
--- In m..., wrote:
>
> 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
> > > >
> > > >
> > > > --
> > > >
> > > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> >
> >
> >
> >
> >
>

Beginning Microcontrollers with the MSP430

After initialize the uC SFR, while(1) loop starts. I have added while(1)
statement below.

does SMclock stops & start again in LPM3? Bcoz when I checked with
Oscilloscope, the SMClock does not seem to stop & start again. This
restart is required so that at a new instant the SMClock is started. But
with below code, SMClock seems to be at same instant hence I am confused
whether the SMClock is getting stopped or not?

I hope you have understood above.

==================void main (void)
{ //begin main
......

While(1) {
if (......)
{ //begin outer if
......
if (......)
{ //begin inner if
......
go-to=LPM3;
} //end inner if
} //end outer if

} // while(1)
} //end main
===================
Regards,

Dipti

________________________________

From: m... [mailto:m...] On Behalf
Of old_cow_yellow
Sent: Tuesday, August 11, 2009 11:49 AM
To: m...
Subject: [msp430] Re: LPM in MSP430F2xx

I did not see the while loop that you mentioned in your first posting.
The go to LPM3 instruction is in two layers of if statements. Thus
either you exit the main without go to LPM3. or you go to LPM3 and wait
for wake-up by TimerA. But once awake, main also exits. Thus either way
you end up exiting main.

This is what I see:
==================void main (void)
{ //begin main
......
if (......)
{ //begin outer if
......
if (......)
{ //begin inner if
......
go-to=LPM3;
} //end inner if
} //end outer if
} //end main
===================
I this the structure of your main()?

--- In m... ,
wrote:
>
> 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 think your problem cannot be solved by stop and start SMCLK.
I think the problem may be caused by the SPI master and SPI slave lost sync. If this is indeed the case, you need to have a separate signal from the master to the slave that says "We are out of sync, let us both stop our SPI state-machine and re-initialize our SPI state-machine."

--- In m..., wrote:
>
> After initialize the uC SFR, while(1) loop starts. I have added while(1)
> statement below.
>
> does SMclock stops & start again in LPM3? Bcoz when I checked with
> Oscilloscope, the SMClock does not seem to stop & start again. This
> restart is required so that at a new instant the SMClock is started. But
> with below code, SMClock seems to be at same instant hence I am confused
> whether the SMClock is getting stopped or not?
>
>
>
> I hope you have understood above.
>
>
>
> ==================> void main (void)
> { //begin main
> ......
>
> While(1) {
> if (......)
> { //begin outer if
> ......
> if (......)
> { //begin inner if
> ......
> go-to=LPM3;
> } //end inner if
> } //end outer if
>
> } // while(1)
> } //end main
> ===================>
> Regards,
>
>
>
> Dipti
>
>
>
> ________________________________
>
> From: m... [mailto:m...] On Behalf
> Of old_cow_yellow
> Sent: Tuesday, August 11, 2009 11:49 AM
> To: m...
> Subject: [msp430] Re: LPM in MSP430F2xx
>
>
>
>
>
> I did not see the while loop that you mentioned in your first posting.
> The go to LPM3 instruction is in two layers of if statements. Thus
> either you exit the main without go to LPM3. or you go to LPM3 and wait
> for wake-up by TimerA. But once awake, main also exits. Thus either way
> you end up exiting main.
>
> This is what I see:
> ==================> void main (void)
> { //begin main
> ......
> if (......)
> { //begin outer if
> ......
> if (......)
> { //begin inner if
> ......
> go-to=LPM3;
> } //end inner if
> } //end outer if
> } //end main
> ===================>
> I this the structure of your main()?
>
> --- In m... ,
> wrote:
> >
> > 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
> > > > >
> > > > >
> > > > > --
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> >
> >
> >
> >
> >
>
How do I synchronize master - slave SPI then?

________________________________

From: m... [mailto:m...] On Behalf
Of old_cow_yellow
Sent: Tuesday, August 11, 2009 12:32 PM
To: m...
Subject: [msp430] Re: LPM in MSP430F2xx

I think your problem cannot be solved by stop and start SMCLK.
I think the problem may be caused by the SPI master and SPI slave lost
sync. If this is indeed the case, you need to have a separate signal
from the master to the slave that says "We are out of sync, let us both
stop our SPI state-machine and re-initialize our SPI state-machine."

--- In m... ,
wrote:
>
> After initialize the uC SFR, while(1) loop starts. I have added
while(1)
> statement below.
>
> does SMclock stops & start again in LPM3? Bcoz when I checked with
> Oscilloscope, the SMClock does not seem to stop & start again. This
> restart is required so that at a new instant the SMClock is started.
But
> with below code, SMClock seems to be at same instant hence I am
confused
> whether the SMClock is getting stopped or not?
>
> I hope you have understood above.
>
> ==================> void main (void)
> { //begin main
> ......
>
> While(1) {
> if (......)
> { //begin outer if
> ......
> if (......)
> { //begin inner if
> ......
> go-to=LPM3;
> } //end inner if
> } //end outer if
>
> } // while(1)
> } //end main
> ===================>
> Regards,
>
> Dipti
>
> ________________________________
>
> From: m...
[mailto:m... ] On
Behalf
> Of old_cow_yellow
> Sent: Tuesday, August 11, 2009 11:49 AM
> To: m...
> Subject: [msp430] Re: LPM in MSP430F2xx
>
> I did not see the while loop that you mentioned in your first posting.
> The go to LPM3 instruction is in two layers of if statements. Thus
> either you exit the main without go to LPM3. or you go to LPM3 and
wait
> for wake-up by TimerA. But once awake, main also exits. Thus either
way
> you end up exiting main.
>
> This is what I see:
> ==================> void main (void)
> { //begin main
> ......
> if (......)
> { //begin outer if
> ......
> if (......)
> { //begin inner if
> ......
> go-to=LPM3;
> } //end inner if
> } //end outer if
> } //end main
> ===================>
> I this the structure of your main()?
>
> --- In m...
,
> wrote:
> >
> > 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 do not know the SPI slave you are using. And I do not know if it was out of sync with the MSP430.

You may try to use one of the digital output pins of the MSP430 as the chip-select input or reset input of the slave SPI.
--- In m..., wrote:
>
> How do I synchronize master - slave SPI then?
>
> ________________________________
>
> From: m... [mailto:m...] On Behalf
> Of old_cow_yellow
> Sent: Tuesday, August 11, 2009 12:32 PM
> To: m...
> Subject: [msp430] Re: LPM in MSP430F2xx
>
>
>
>
>
> I think your problem cannot be solved by stop and start SMCLK.
> I think the problem may be caused by the SPI master and SPI slave lost
> sync. If this is indeed the case, you need to have a separate signal
> from the master to the slave that says "We are out of sync, let us both
> stop our SPI state-machine and re-initialize our SPI state-machine."
>
> --- In m... ,
> wrote:
> >
> > After initialize the uC SFR, while(1) loop starts. I have added
> while(1)
> > statement below.
> >
> > does SMclock stops & start again in LPM3? Bcoz when I checked with
> > Oscilloscope, the SMClock does not seem to stop & start again. This
> > restart is required so that at a new instant the SMClock is started.
> But
> > with below code, SMClock seems to be at same instant hence I am
> confused
> > whether the SMClock is getting stopped or not?
> >
> >
> >
> > I hope you have understood above.
> >
> >
> >
> > ==================> > void main (void)
> > { //begin main
> > ......
> >
> > While(1) {
> > if (......)
> > { //begin outer if
> > ......
> > if (......)
> > { //begin inner if
> > ......
> > go-to=LPM3;
> > } //end inner if
> > } //end outer if
> >
> > } // while(1)
> > } //end main
> > ===================> >
> >
> >
> > Regards,
> >
> >
> >
> > Dipti
> >
> >
> >
> > ________________________________
> >
> > From: m...
> [mailto:m... ] On
> Behalf
> > Of old_cow_yellow
> > Sent: Tuesday, August 11, 2009 11:49 AM
> > To: m...
> > Subject: [msp430] Re: LPM in MSP430F2xx
> >
> >
> >
> >
> >
> > I did not see the while loop that you mentioned in your first posting.
> > The go to LPM3 instruction is in two layers of if statements. Thus
> > either you exit the main without go to LPM3. or you go to LPM3 and
> wait
> > for wake-up by TimerA. But once awake, main also exits. Thus either
> way
> > you end up exiting main.
> >
> > This is what I see:
> > ==================> > void main (void)
> > { //begin main
> > ......
> > if (......)
> > { //begin outer if
> > ......
> > if (......)
> > { //begin inner if
> > ......
> > go-to=LPM3;
> > } //end inner if
> > } //end outer if
> > } //end main
> > ===================> >
> > I this the structure of your main()?
> >
> > --- In m...
> ,
> > wrote:
> > >
> > > 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 am interfacing MSP430 uC to ADC on SPI. uC is master & ADC is slave.

Interconnections are as below:

ADC does not have pin for selecting SPI device. It just has 2 pins for
SPI communication. DRDY/Dout pins do the function of Data Ready(DRDY):
Indicates valid data by going low & Data Output(Dout): Outputs data, MSB
first, on the first rising edge of SCLK. DRDY remains "high"
approximately for 40 uS. This time is for Data updating & no readback
allowed.

In my code, P3.5 is configured for SPI hence I could not check the
status of DRDY/Dout pin before starting the SPI communication. In the
TimerA ISR(Timer A ISR is generated every 100mS), writes data to
transmit buffer (UCA0TXBUF) which activates "__interrupt void
USCIA0RX_ISR(void)" interrupt, & in which it again writes data to
transmit buffer (UCA0TXBUF) 2 times & gets the 24bit from the ADC &
store this 24 bit raw count in some variable. Note that when the data is
written into transmit buffer, uC will send 8 clock pulses.

My problem is when Timer A ISR is generated & writes data into transmit
buffer (UCA0TXBUF), at that instant the DRDY/Dout is "high". & uC sends
24 clock pulses but ADC sends 0x07FFFF data since DRDY/Dout pin is
"high".

To resolve this issue, I thought if I restart SPI clock then at new
instance clock would be generated when the DRDY/Dout is low.

I hope you got some idea of the above explanation. Now I think you would
understand that why I am looking at restarting SPI clock. I though only
by restarting the SPI clock would resolve my problem. Could provide some
input on how to resolve above issue.

Regards,

Dipti

________________________________

From: m... [mailto:m...] On Behalf
Of old_cow_yellow
Sent: Tuesday, August 11, 2009 9:43 PM
To: m...
Subject: [msp430] Re: LPM in MSP430F2xx

I do not know the SPI slave you are using. And I do not know if it was
out of sync with the MSP430.

You may try to use one of the digital output pins of the MSP430 as the
chip-select input or reset input of the slave SPI.

--- In m... ,
wrote:
>
> How do I synchronize master - slave SPI then?
>
> ________________________________
>
> From: m...
[mailto:m... ] On
Behalf
> Of old_cow_yellow
> Sent: Tuesday, August 11, 2009 12:32 PM
> To: m...
> Subject: [msp430] Re: LPM in MSP430F2xx
>
> I think your problem cannot be solved by stop and start SMCLK.
> I think the problem may be caused by the SPI master and SPI slave lost
> sync. If this is indeed the case, you need to have a separate signal
> from the master to the slave that says "We are out of sync, let us
both
> stop our SPI state-machine and re-initialize our SPI state-machine."
>
> --- In m...
,
> wrote:
> >
> > After initialize the uC SFR, while(1) loop starts. I have added
> while(1)
> > statement below.
> >
> > does SMclock stops & start again in LPM3? Bcoz when I checked with
> > Oscilloscope, the SMClock does not seem to stop & start again. This
> > restart is required so that at a new instant the SMClock is started.
> But
> > with below code, SMClock seems to be at same instant hence I am
> confused
> > whether the SMClock is getting stopped or not?
> >
> >
> >
> > I hope you have understood above.
> >
> >
> >
> > ==================> > void main (void)
> > { //begin main
> > ......
> >
> > While(1) {
> > if (......)
> > { //begin outer if
> > ......
> > if (......)
> > { //begin inner if
> > ......
> > go-to=LPM3;
> > } //end inner if
> > } //end outer if
> >
> > } // while(1)
> > } //end main
> > ===================> >
> >
> >
> > Regards,
> >
> >
> >
> > Dipti
> >
> >
> >
> > ________________________________
> >
> > From: m...

> [mailto:m...
] On
> Behalf
> > Of old_cow_yellow
> > Sent: Tuesday, August 11, 2009 11:49 AM
> > To: m...

> > Subject: [msp430] Re: LPM in MSP430F2xx
> >
> >
> >
> >
> >
> > I did not see the while loop that you mentioned in your first
posting.
> > The go to LPM3 instruction is in two layers of if statements. Thus
> > either you exit the main without go to LPM3. or you go to LPM3 and
> wait
> > for wake-up by TimerA. But once awake, main also exits. Thus either
> way
> > you end up exiting main.
> >
> > This is what I see:
> > ==================> > void main (void)
> > { //begin main
> > ......
> > if (......)
> > { //begin outer if
> > ......
> > if (......)
> > { //begin inner if
> > ......
> > go-to=LPM3;
> > } //end inner if
> > } //end outer if
> > } //end main
> > ===================> >
> > I this the structure of your main()?
> >
> > --- In m...

> ,
> > wrote:
> > >
> > > 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 know the details of ADC chip interface. Is the following understanding correct?

(a) It has two pins for interface. An output pin DRDY/Dout. And an input pin CLK.

(b) When data is not ready, DRDY/Dout output stays high. CLK input is ignored. Thus if one attempts to drive the CLK and reads Dout, the result is always high (i.e., a "1").

(c) When data is available, DRDY/Dout output goes low. After this (and within 40 uSec?), if CLK is driven low, DRDY/Dout will present the MSB of the ADC reading. If CLK is driven high and then low again (still within 40 uSec?), DRDY/Dout will present the second MSB. This may repeat for a total of 24 cycles of CLK to read all 24 bits.

My main questions are about (c):

(1) Is my understanding of the 40 uSec limit correct? Do you have only 40 uSec to clock out all 24 bits after DRDY/Dout says data is ready?

(2) After data pears at DRDY/Dout pin when CLK goes low, does DRDY/Dout stays unchanged when CLK goes high? And changes only when CLK goes low again?
--- In m..., wrote:
>
> I am interfacing MSP430 uC to ADC on SPI. uC is master & ADC is slave.
>
>
>
> Interconnections are as below:
>
>
>
> ADC does not have pin for selecting SPI device. It just has 2 pins for
> SPI communication. DRDY/Dout pins do the function of Data Ready(DRDY):
> Indicates valid data by going low & Data Output(Dout): Outputs data, MSB
> first, on the first rising edge of SCLK. DRDY remains "high"
> approximately for 40 uS. This time is for Data updating & no readback
> allowed.
>
>
>
> In my code, P3.5 is configured for SPI hence I could not check the
> status of DRDY/Dout pin before starting the SPI communication. In the
> TimerA ISR(Timer A ISR is generated every 100mS), writes data to
> transmit buffer (UCA0TXBUF) which activates "__interrupt void
> USCIA0RX_ISR(void)" interrupt, & in which it again writes data to
> transmit buffer (UCA0TXBUF) 2 times & gets the 24bit from the ADC &
> store this 24 bit raw count in some variable. Note that when the data is
> written into transmit buffer, uC will send 8 clock pulses.
>
>
>
> My problem is when Timer A ISR is generated & writes data into transmit
> buffer (UCA0TXBUF), at that instant the DRDY/Dout is "high". & uC sends
> 24 clock pulses but ADC sends 0x07FFFF data since DRDY/Dout pin is
> "high".
>
>
>
> To resolve this issue, I thought if I restart SPI clock then at new
> instance clock would be generated when the DRDY/Dout is low.
>
>
>
> I hope you got some idea of the above explanation. Now I think you would
> understand that why I am looking at restarting SPI clock. I though only
> by restarting the SPI clock would resolve my problem. Could provide some
> input on how to resolve above issue.
>
>
>
> Regards,
>
>
>
> Dipti
>
>
>
> ________________________________
>
> From: m... [mailto:m...] On Behalf
> Of old_cow_yellow
> Sent: Tuesday, August 11, 2009 9:43 PM
> To: m...
> Subject: [msp430] Re: LPM in MSP430F2xx
>
>
>
>
>
> I do not know the SPI slave you are using. And I do not know if it was
> out of sync with the MSP430.
>
> You may try to use one of the digital output pins of the MSP430 as the
> chip-select input or reset input of the slave SPI.
>
> --- In m... ,
> wrote:
> >
> > How do I synchronize master - slave SPI then?
> >
> > ________________________________
> >
> > From: m...
> [mailto:m... ] On
> Behalf
> > Of old_cow_yellow
> > Sent: Tuesday, August 11, 2009 12:32 PM
> > To: m...
> > Subject: [msp430] Re: LPM in MSP430F2xx
> >
> >
> >
> >
> >
> > I think your problem cannot be solved by stop and start SMCLK.
> > I think the problem may be caused by the SPI master and SPI slave lost
> > sync. If this is indeed the case, you need to have a separate signal
> > from the master to the slave that says "We are out of sync, let us
> both
> > stop our SPI state-machine and re-initialize our SPI state-machine."
> >
> > --- In m...
> ,
> > wrote:
> > >
> > > After initialize the uC SFR, while(1) loop starts. I have added
> > while(1)
> > > statement below.
> > >
> > > does SMclock stops & start again in LPM3? Bcoz when I checked with
> > > Oscilloscope, the SMClock does not seem to stop & start again. This
> > > restart is required so that at a new instant the SMClock is started.
> > But
> > > with below code, SMClock seems to be at same instant hence I am
> > confused
> > > whether the SMClock is getting stopped or not?
> > >
> > >
> > >
> > > I hope you have understood above.
> > >
> > >
> > >
> > > ==================> > > void main (void)
> > > { //begin main
> > > ......
> > >
> > > While(1) {
> > > if (......)
> > > { //begin outer if
> > > ......
> > > if (......)
> > > { //begin inner if
> > > ......
> > > go-to=LPM3;
> > > } //end inner if
> > > } //end outer if
> > >
> > > } // while(1)
> > > } //end main
> > > ===================> > >
> > >
> > >
> > > Regards,
> > >
> > >
> > >
> > > Dipti
> > >
> > >
> > >
> > > ________________________________
> > >
> > > From: m...
>
> > [mailto:m...
> ] On
> > Behalf
> > > Of old_cow_yellow
> > > Sent: Tuesday, August 11, 2009 11:49 AM
> > > To: m...
>
> > > Subject: [msp430] Re: LPM in MSP430F2xx
> > >
> > >
> > >
> > >
> > >
> > > I did not see the while loop that you mentioned in your first
> posting.
> > > The go to LPM3 instruction is in two layers of if statements. Thus
> > > either you exit the main without go to LPM3. or you go to LPM3 and
> > wait
> > > for wake-up by TimerA. But once awake, main also exits. Thus either
> > way
> > > you end up exiting main.
> > >
> > > This is what I see:
> > > ==================> > > void main (void)
> > > { //begin main
> > > ......
> > > if (......)
> > > { //begin outer if
> > > ......
> > > if (......)
> > > { //begin inner if
> > > ......
> > > go-to=LPM3;
> > > } //end inner if
> > > } //end outer if
> > > } //end main
> > > ===================> > >
> > > I this the structure of your main()?
> > >
> > > --- In m...
>
> > ,
> > > wrote:
> > > >
> > > > 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
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> >
> >
> >
> >
> >
>
It will be better if you send URL of the data-sheet of that ADC.

--- In m..., "old_cow_yellow" wrote:
>
> I need to know the details of ADC chip interface. Is the following understanding correct?
>
> (a) It has two pins for interface. An output pin DRDY/Dout. And an input pin CLK.
>
> (b) When data is not ready, DRDY/Dout output stays high. CLK input is ignored. Thus if one attempts to drive the CLK and reads Dout, the result is always high (i.e., a "1").
>
> (c) When data is available, DRDY/Dout output goes low. After this (and within 40 uSec?), if CLK is driven low, DRDY/Dout will present the MSB of the ADC reading. If CLK is driven high and then low again (still within 40 uSec?), DRDY/Dout will present the second MSB. This may repeat for a total of 24 cycles of CLK to read all 24 bits.
>
> My main questions are about (c):
>
> (1) Is my understanding of the 40 uSec limit correct? Do you have only 40 uSec to clock out all 24 bits after DRDY/Dout says data is ready?
>
> (2) After data pears at DRDY/Dout pin when CLK goes low, does DRDY/Dout stays unchanged when CLK goes high? And changes only when CLK goes low again?
> --- In m..., wrote:
> >
> > I am interfacing MSP430 uC to ADC on SPI. uC is master & ADC is slave.
> >
> >
> >
> > Interconnections are as below:
> >
> >
> >
> > ADC does not have pin for selecting SPI device. It just has 2 pins for
> > SPI communication. DRDY/Dout pins do the function of Data Ready(DRDY):
> > Indicates valid data by going low & Data Output(Dout): Outputs data, MSB
> > first, on the first rising edge of SCLK. DRDY remains "high"
> > approximately for 40 uS. This time is for Data updating & no readback
> > allowed.
> >
> >
> >
> > In my code, P3.5 is configured for SPI hence I could not check the
> > status of DRDY/Dout pin before starting the SPI communication. In the
> > TimerA ISR(Timer A ISR is generated every 100mS), writes data to
> > transmit buffer (UCA0TXBUF) which activates "__interrupt void
> > USCIA0RX_ISR(void)" interrupt, & in which it again writes data to
> > transmit buffer (UCA0TXBUF) 2 times & gets the 24bit from the ADC &
> > store this 24 bit raw count in some variable. Note that when the data is
> > written into transmit buffer, uC will send 8 clock pulses.
> >
> >
> >
> > My problem is when Timer A ISR is generated & writes data into transmit
> > buffer (UCA0TXBUF), at that instant the DRDY/Dout is "high". & uC sends
> > 24 clock pulses but ADC sends 0x07FFFF data since DRDY/Dout pin is
> > "high".
> >
> >
> >
> > To resolve this issue, I thought if I restart SPI clock then at new
> > instance clock would be generated when the DRDY/Dout is low.
> >
> >
> >
> > I hope you got some idea of the above explanation. Now I think you would
> > understand that why I am looking at restarting SPI clock. I though only
> > by restarting the SPI clock would resolve my problem. Could provide some
> > input on how to resolve above issue.
> >
> >
> >
> > Regards,
> >
> >
> >
> > Dipti
> >
> >
> >
> > ________________________________
> >
> > From: m... [mailto:m...] On Behalf
> > Of old_cow_yellow
> > Sent: Tuesday, August 11, 2009 9:43 PM
> > To: m...
> > Subject: [msp430] Re: LPM in MSP430F2xx
> >
> >
> >
> >
> >
> > I do not know the SPI slave you are using. And I do not know if it was
> > out of sync with the MSP430.
> >
> > You may try to use one of the digital output pins of the MSP430 as the
> > chip-select input or reset input of the slave SPI.
> >
> > --- In m... ,
> > wrote:
> > >
> > > How do I synchronize master - slave SPI then?
> > >
> > > ________________________________
> > >
> > > From: m...
> > [mailto:m... ] On
> > Behalf
> > > Of old_cow_yellow
> > > Sent: Tuesday, August 11, 2009 12:32 PM
> > > To: m...
> > > Subject: [msp430] Re: LPM in MSP430F2xx
> > >
> > >
> > >
> > >
> > >
> > > I think your problem cannot be solved by stop and start SMCLK.
> > > I think the problem may be caused by the SPI master and SPI slave lost
> > > sync. If this is indeed the case, you need to have a separate signal
> > > from the master to the slave that says "We are out of sync, let us
> > both
> > > stop our SPI state-machine and re-initialize our SPI state-machine."
> > >
> > > --- In m...
> > ,
> > > wrote:
> > > >
> > > > After initialize the uC SFR, while(1) loop starts. I have added
> > > while(1)
> > > > statement below.
> > > >
> > > > does SMclock stops & start again in LPM3? Bcoz when I checked with
> > > > Oscilloscope, the SMClock does not seem to stop & start again. This
> > > > restart is required so that at a new instant the SMClock is started.
> > > But
> > > > with below code, SMClock seems to be at same instant hence I am
> > > confused
> > > > whether the SMClock is getting stopped or not?
> > > >
> > > >
> > > >
> > > > I hope you have understood above.
> > > >
> > > >
> > > >
> > > > ==================> > > > void main (void)
> > > > { //begin main
> > > > ......
> > > >
> > > > While(1) {
> > > > if (......)
> > > > { //begin outer if
> > > > ......
> > > > if (......)
> > > > { //begin inner if
> > > > ......
> > > > go-to=LPM3;
> > > > } //end inner if
> > > > } //end outer if
> > > >
> > > > } // while(1)
> > > > } //end main
> > > > ===================> > > >
> > > >
> > > >
> > > > Regards,
> > > >
> > > >
> > > >
> > > > Dipti
> > > >
> > > >
> > > >
> > > > ________________________________
> > > >
> > > > From: m...
> >
> > > [mailto:m...
> > ] On
> > > Behalf
> > > > Of old_cow_yellow
> > > > Sent: Tuesday, August 11, 2009 11:49 AM
> > > > To: m...
> >
> > > > Subject: [msp430] Re: LPM in MSP430F2xx
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > I did not see the while loop that you mentioned in your first
> > posting.
> > > > The go to LPM3 instruction is in two layers of if statements. Thus
> > > > either you exit the main without go to LPM3. or you go to LPM3 and
> > > wait
> > > > for wake-up by TimerA. But once awake, main also exits. Thus either
> > > way
> > > > you end up exiting main.
> > > >
> > > > This is what I see:
> > > > ==================> > > > void main (void)
> > > > { //begin main
> > > > ......
> > > > if (......)
> > > > { //begin outer if
> > > > ......
> > > > if (......)
> > > > { //begin inner if
> > > > ......
> > > > go-to=LPM3;
> > > > } //end inner if
> > > > } //end outer if
> > > > } //end main
> > > > ===================> > > >
> > > > I this the structure of your main()?
> > > >
> > > > --- In m...
> >
> > > ,
> > > > wrote:
> > > > >
> > > > > 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
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> >
> >
> >
> >
>

We would decide on ADS1230/1232/1234 chip later on. You could refer to
below datasheet for understanding ADC conversion.

http://focus.ti.com/docs/prod/folders/print/ads1232.html?lpos=See_Also_C
ontainer&lid=Alternative_Devices

________________________________

From: m... [mailto:m...] On Behalf
Of old_cow_yellow
Sent: Wednesday, August 12, 2009 8:43 PM
To: m...
Subject: [msp430] Re: LPM in MSP430F2xx

It will be better if you send URL of the data-sheet of that ADC.

--- In m... ,
"old_cow_yellow" wrote:
>
> I need to know the details of ADC chip interface. Is the following
understanding correct?
>
> (a) It has two pins for interface. An output pin DRDY/Dout. And an
input pin CLK.
>
> (b) When data is not ready, DRDY/Dout output stays high. CLK input is
ignored. Thus if one attempts to drive the CLK and reads Dout, the
result is always high (i.e., a "1").
>
> (c) When data is available, DRDY/Dout output goes low. After this (and
within 40 uSec?), if CLK is driven low, DRDY/Dout will present the MSB
of the ADC reading. If CLK is driven high and then low again (still
within 40 uSec?), DRDY/Dout will present the second MSB. This may repeat
for a total of 24 cycles of CLK to read all 24 bits.
>
> My main questions are about (c):
>
> (1) Is my understanding of the 40 uSec limit correct? Do you have only
40 uSec to clock out all 24 bits after DRDY/Dout says data is ready?
>
> (2) After data pears at DRDY/Dout pin when CLK goes low, does
DRDY/Dout stays unchanged when CLK goes high? And changes only when CLK
goes low again?
> --- In m... ,
wrote:
> >
> > I am interfacing MSP430 uC to ADC on SPI. uC is master & ADC is
slave.
> >
> >
> >
> > Interconnections are as below:
> >
> >
> >
> > ADC does not have pin for selecting SPI device. It just has 2 pins
for
> > SPI communication. DRDY/Dout pins do the function of Data
Ready(DRDY):
> > Indicates valid data by going low & Data Output(Dout): Outputs data,
MSB
> > first, on the first rising edge of SCLK. DRDY remains "high"
> > approximately for 40 uS. This time is for Data updating & no
readback
> > allowed.
> >
> >
> >
> > In my code, P3.5 is configured for SPI hence I could not check the
> > status of DRDY/Dout pin before starting the SPI communication. In
the
> > TimerA ISR(Timer A ISR is generated every 100mS), writes data to
> > transmit buffer (UCA0TXBUF) which activates "__interrupt void
> > USCIA0RX_ISR(void)" interrupt, & in which it again writes data to
> > transmit buffer (UCA0TXBUF) 2 times & gets the 24bit from the ADC &
> > store this 24 bit raw count in some variable. Note that when the
data is
> > written into transmit buffer, uC will send 8 clock pulses.
> >
> >
> >
> > My problem is when Timer A ISR is generated & writes data into
transmit
> > buffer (UCA0TXBUF), at that instant the DRDY/Dout is "high". & uC
sends
> > 24 clock pulses but ADC sends 0x07FFFF data since DRDY/Dout pin is
> > "high".
> >
> >
> >
> > To resolve this issue, I thought if I restart SPI clock then at new
> > instance clock would be generated when the DRDY/Dout is low.
> >
> >
> >
> > I hope you got some idea of the above explanation. Now I think you
would
> > understand that why I am looking at restarting SPI clock. I though
only
> > by restarting the SPI clock would resolve my problem. Could provide
some
> > input on how to resolve above issue.
> >
> >
> >
> > Regards,
> >
> >
> >
> > Dipti
> >
> >
> >
> > ________________________________
> >
> > From: m...
[mailto:m... ] On
Behalf
> > Of old_cow_yellow
> > Sent: Tuesday, August 11, 2009 9:43 PM
> > To: m...
> > Subject: [msp430] Re: LPM in MSP430F2xx
> >
> >
> >
> >
> >
> > I do not know the SPI slave you are using. And I do not know if it
was
> > out of sync with the MSP430.
> >
> > You may try to use one of the digital output pins of the MSP430 as
the
> > chip-select input or reset input of the slave SPI.
> >
> > --- In m...
,
> > wrote:
> > >
> > > How do I synchronize master - slave SPI then?
> > >
> > > ________________________________
> > >
> > > From: m...

> > [mailto:m...
] On
> > Behalf
> > > Of old_cow_yellow
> > > Sent: Tuesday, August 11, 2009 12:32 PM
> > > To: m...

> > > Subject: [msp430] Re: LPM in MSP430F2xx
> > >
> > >
> > >
> > >
> > >
> > > I think your problem cannot be solved by stop and start SMCLK.
> > > I think the problem may be caused by the SPI master and SPI slave
lost
> > > sync. If this is indeed the case, you need to have a separate
signal
> > > from the master to the slave that says "We are out of sync, let us
> > both
> > > stop our SPI state-machine and re-initialize our SPI
state-machine."
> > >
> > > --- In m...

> > ,
> > > wrote:
> > > >
> > > > After initialize the uC SFR, while(1) loop starts. I have added
> > > while(1)
> > > > statement below.
> > > >
> > > > does SMclock stops & start again in LPM3? Bcoz when I checked
with
> > > > Oscilloscope, the SMClock does not seem to stop & start again.
This
> > > > restart is required so that at a new instant the SMClock is
started.
> > > But
> > > > with below code, SMClock seems to be at same instant hence I am
> > > confused
> > > > whether the SMClock is getting stopped or not?
> > > >
> > > >
> > > >
> > > > I hope you have understood above.
> > > >
> > > >
> > > >
> > > > ==================> > > > void main (void)
> > > > { //begin main
> > > > ......
> > > >
> > > > While(1) {
> > > > if (......)
> > > > { //begin outer if
> > > > ......
> > > > if (......)
> > > > { //begin inner if
> > > > ......
> > > > go-to=LPM3;
> > > > } //end inner if
> > > > } //end outer if
> > > >
> > > > } // while(1)
> > > > } //end main
> > > > ===================> > > >
> > > >
> > > >
> > > > Regards,
> > > >
> > > >
> > > >
> > > > Dipti
> > > >
> > > >
> > > >
> > > > ________________________________
> > > >
> > > > From: m...

> >
> > > [mailto:m...

> > ] On
> > > Behalf
> > > > Of old_cow_yellow
> > > > Sent: Tuesday, August 11, 2009 11:49 AM
> > > > To: m...

> >
> > > > Subject: [msp430] Re: LPM in MSP430F2xx
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > I did not see the while loop that you mentioned in your first
> > posting.
> > > > The go to LPM3 instruction is in two layers of if statements.
Thus
> > > > either you exit the main without go to LPM3. or you go to LPM3
and
> > > wait
> > > > for wake-up by TimerA. But once awake, main also exits. Thus
either
> > > way
> > > > you end up exiting main.
> > > >
> > > > This is what I see:
> > > > ==================> > > > void main (void)
> > > > { //begin main
> > > > ......
> > > > if (......)
> > > > { //begin outer if
> > > > ......
> > > > if (......)
> > > > { //begin inner if
> > > > ......
> > > > go-to=LPM3;
> > > > } //end inner if
> > > > } //end outer if
> > > > } //end main
> > > > ===================> > > >
> > > > I this the structure of your main()?
> > > >
> > > > --- In m...

> >
> > > ,
> > > > wrote:
> > > > >
> > > > > 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
> > > > > > > >
> > > > > > > >
> > > > > > > > --
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> >
> >
> >
> >
>


Your MSP430F2xx and ADS123x are not in sync. Since the MSP430F2xx cannot change the timing of ADS123x, it must change its own timing to synchronize with the ADS123x.

The DRDY/Dout and SCLK of ADS123x are currently connected to the SOMI and CLK of the SPI port of MSP430F2xx. This is fine for using SPI to read the ADC. However, the MSP430F2xx has no clue about when it is appropriate to do so. I suggest that you connect the DRDY/Dout=SOMI signal to an additional input pin of the MSP430F2xx. That input pin must be able to detect the falling edge. For example, any one of the P1 or P2 port can do that. Any one of the Capture input for the Timers can do that too. With this additional connection, you can synchronize the SPI reading as follows:

(1) Set up the SPI as you already did. Set up the falling edge detector too. But do not enable them to do anything yet.

(2) When MSP430F2xx is ready to read ADC, clear the falling edge detector flag, enable its interrupt, and wait for the interrupt.

(3) When falling edge detector interrupts, disable that interrupt and activate the SPI to read the ADC as you did before.

(4) After the SPI finishes reading all 24 bits of ADC data, go back to step (2) to wait and read the next ADC reading.

If it become necessary for you to show many lines of code, I wonder if you could download that to the file area or somewhere with the indentation and multiple blanks preserved. I can read code without comments. Actually, I prefer that over incorrect or misleading comments.

--- In m..., wrote:
>
> We would decide on ADS1230/1232/1234 chip later on. You could refer to
> below datasheet for understanding ADC conversion.
>
>
>
> http://focus.ti.com/docs/prod/folders/print/ads1232.html?lpos=See_Also_C
> ontainer&lid=Alternative_Devices
>
>
>
>
>
> ________________________________
>
> From: m... [mailto:m...] On Behalf
> Of old_cow_yellow
> Sent: Wednesday, August 12, 2009 8:43 PM
> To: m...
> Subject: [msp430] Re: LPM in MSP430F2xx
>
>
>
>
>
> It will be better if you send URL of the data-sheet of that ADC.
>
> --- In m... ,
> "old_cow_yellow" wrote:
> >
> > I need to know the details of ADC chip interface. Is the following
> understanding correct?
> >
> > (a) It has two pins for interface. An output pin DRDY/Dout. And an
> input pin CLK.
> >
> > (b) When data is not ready, DRDY/Dout output stays high. CLK input is
> ignored. Thus if one attempts to drive the CLK and reads Dout, the
> result is always high (i.e., a "1").
> >
> > (c) When data is available, DRDY/Dout output goes low. After this (and
> within 40 uSec?), if CLK is driven low, DRDY/Dout will present the MSB
> of the ADC reading. If CLK is driven high and then low again (still
> within 40 uSec?), DRDY/Dout will present the second MSB. This may repeat
> for a total of 24 cycles of CLK to read all 24 bits.
> >
> > My main questions are about (c):
> >
> > (1) Is my understanding of the 40 uSec limit correct? Do you have only
> 40 uSec to clock out all 24 bits after DRDY/Dout says data is ready?
> >
> > (2) After data pears at DRDY/Dout pin when CLK goes low, does
> DRDY/Dout stays unchanged when CLK goes high? And changes only when CLK
> goes low again?
> >
> >
> > --- In m... ,
> wrote:
> > >
> > > I am interfacing MSP430 uC to ADC on SPI. uC is master & ADC is
> slave.
> > >
> > >
> > >
> > > Interconnections are as below:
> > >
> > >
> > >
> > > ADC does not have pin for selecting SPI device. It just has 2 pins
> for
> > > SPI communication. DRDY/Dout pins do the function of Data
> Ready(DRDY):
> > > Indicates valid data by going low & Data Output(Dout): Outputs data,
> MSB
> > > first, on the first rising edge of SCLK. DRDY remains "high"
> > > approximately for 40 uS. This time is for Data updating & no
> readback
> > > allowed.
> > >
> > >
> > >
> > > In my code, P3.5 is configured for SPI hence I could not check the
> > > status of DRDY/Dout pin before starting the SPI communication. In
> the
> > > TimerA ISR(Timer A ISR is generated every 100mS), writes data to
> > > transmit buffer (UCA0TXBUF) which activates "__interrupt void
> > > USCIA0RX_ISR(void)" interrupt, & in which it again writes data to
> > > transmit buffer (UCA0TXBUF) 2 times & gets the 24bit from the ADC &
> > > store this 24 bit raw count in some variable. Note that when the
> data is
> > > written into transmit buffer, uC will send 8 clock pulses.
> > >
> > >
> > >
> > > My problem is when Timer A ISR is generated & writes data into
> transmit
> > > buffer (UCA0TXBUF), at that instant the DRDY/Dout is "high". & uC
> sends
> > > 24 clock pulses but ADC sends 0x07FFFF data since DRDY/Dout pin is
> > > "high".
> > >
> > >
> > >
> > > To resolve this issue, I thought if I restart SPI clock then at new
> > > instance clock would be generated when the DRDY/Dout is low.
> > >
> > >
> > >
> > > I hope you got some idea of the above explanation. Now I think you
> would
> > > understand that why I am looking at restarting SPI clock. I though
> only
> > > by restarting the SPI clock would resolve my problem. Could provide
> some
> > > input on how to resolve above issue.
> > >
> > >
> > >
> > > Regards,
> > >
> > >
> > >
> > > Dipti
> > >
> > >
> > >
> > > ________________________________
> > >
> > > From: m...
> [mailto:m... ] On
> Behalf
> > > Of old_cow_yellow
> > > Sent: Tuesday, August 11, 2009 9:43 PM
> > > To: m...
> > > Subject: [msp430] Re: LPM in MSP430F2xx
> > >
> > >
> > >
> > >
> > >
> > > I do not know the SPI slave you are using. And I do not know if it
> was
> > > out of sync with the MSP430.
> > >
> > > You may try to use one of the digital output pins of the MSP430 as
> the
> > > chip-select input or reset input of the slave SPI.
> > >
> > > --- In m...
> ,
> > > wrote:
> > > >
> > > > How do I synchronize master - slave SPI then?
> > > >
> > > > ________________________________
> > > >
> > > > From: m...
>
> > > [mailto:m...
> ] On
> > > Behalf
> > > > Of old_cow_yellow
> > > > Sent: Tuesday, August 11, 2009 12:32 PM
> > > > To: m...
>
> > > > Subject: [msp430] Re: LPM in MSP430F2xx
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > I think your problem cannot be solved by stop and start SMCLK.
> > > > I think the problem may be caused by the SPI master and SPI slave
> lost
> > > > sync. If this is indeed the case, you need to have a separate
> signal
> > > > from the master to the slave that says "We are out of sync, let us
> > > both
> > > > stop our SPI state-machine and re-initialize our SPI
> state-machine."
> > > >
> > > > --- In m...
>
> > > ,
> > > > wrote:
> > > > >
> > > > > After initialize the uC SFR, while(1) loop starts. I have added
> > > > while(1)
> > > > > statement below.
> > > > >
> > > > > does SMclock stops & start again in LPM3? Bcoz when I checked
> with
> > > > > Oscilloscope, the SMClock does not seem to stop & start again.
> This
> > > > > restart is required so that at a new instant the SMClock is
> started.
> > > > But
> > > > > with below code, SMClock seems to be at same instant hence I am
> > > > confused
> > > > > whether the SMClock is getting stopped or not?
> > > > >
> > > > >
> > > > >
> > > > > I hope you have understood above.
> > > > >
> > > > >
> > > > >
> > > > > ==================> > > > > void main (void)
> > > > > { //begin main
> > > > > ......
> > > > >
> > > > > While(1) {
> > > > > if (......)
> > > > > { //begin outer if
> > > > > ......
> > > > > if (......)
> > > > > { //begin inner if
> > > > > ......
> > > > > go-to=LPM3;
> > > > > } //end inner if
> > > > > } //end outer if
> > > > >
> > > > > } // while(1)
> > > > > } //end main
> > > > > ===================> > > > >
> > > > >
> > > > >
> > > > > Regards,
> > > > >
> > > > >
> > > > >
> > > > > Dipti
> > > > >
> > > > >
> > > > >
> > > > > ________________________________
> > > > >
> > > > > From: m...
>
> > >
> > > > [mailto:m...
>
> > > ] On
> > > > Behalf
> > > > > Of old_cow_yellow
> > > > > Sent: Tuesday, August 11, 2009 11:49 AM
> > > > > To: m...
>
> > >
> > > > > Subject: [msp430] Re: LPM in MSP430F2xx
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > I did not see the while loop that you mentioned in your first
> > > posting.
> > > > > The go to LPM3 instruction is in two layers of if statements.
> Thus
> > > > > either you exit the main without go to LPM3. or you go to LPM3
> and
> > > > wait
> > > > > for wake-up by TimerA. But once awake, main also exits. Thus
> either
> > > > way
> > > > > you end up exiting main.
> > > > >
> > > > > This is what I see:
> > > > > ==================> > > > > void main (void)
> > > > > { //begin main
> > > > > ......
> > > > > if (......)
> > > > > { //begin outer if
> > > > > ......
> > > > > if (......)
> > > > > { //begin inner if
> > > > > ......
> > > > > go-to=LPM3;
> > > > > } //end inner if
> > > > > } //end outer if
> > > > > } //end main
> > > > > ===================> > > > >
> > > > > I this the structure of your main()?
> > > > >
> > > > > --- In m...
>
> > >
> > > > ,
> > > > > wrote:
> > > > > >
> > > > > > 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
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > --
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
>