EmbeddedRelated.com
Forums

UART problem

Started by hragsarkissian February 24, 2009
Hi,

I am working on a small UART program using wireless transmitter and
receiver. I have on one end a transmitter connected to an msp430
along with some pushbuttons. each pushbutton sends a specific
character throuh the transmitter.

On the receiving end, i have a receiver connected to another MSP430.
the wireless part works fine. I would like an LED to turn on when
the first push button is pressed on the transmitting end. Thefore, i
used Ti's example program for UART. When i pause the receiving end
and check for RXBUF i do get the transmitted value. However, it
seems that I am doing something wrong with the interrupt, or at least
TI. What happens is that it never actually gets out of the interrupt
i have tried using _BIC_SR but still doesn't work.
Could you please let me know, what I'm doing wrong. I am fairly new
and am using the MSP430F2132.

int test = 0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT

if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ =0xFF)
{
while(1); // If calibration
constants erased
// do not load, trap CPU!!
}
P1DIR |= BIT0;
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
P3DIR &= ~BIT5;
P3SEL = 0x30; // P3.4,5 = USCI_A0
TXD/RXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 0x35; // 1MHz 30bps
UCA0BR1 = 0x82; // 1MHz 30 bps
UCA0MCTL = 0x94; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI
state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX
interrupt

for(;;){
test = 0;
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0,
interrupts enabled
if(test == 0x11)
P1OUT ^= BIT0;
}
}
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{

test = UCA0RXBUF;
}

Beginning Microcontrollers with the MSP430

As the last statement in your interrupt routine, add:
__low_power_mode_off_on_exit();

This will bring the system out of LPMx to execute the next statement (in
your main loop) following the statement which put the system into LPM0:
__bis_SR_register(LPM0_bits + GIE);

Hope this helps,

Jim Smith

_____

From: m... [mailto:m...] On Behalf Of
hragsarkissian
Sent: Tuesday, February 24, 2009 7:25 PM
To: m...
Subject: [msp430] UART problem

Hi,

I am working on a small UART program using wireless transmitter and
receiver. I have on one end a transmitter connected to an msp430
along with some pushbuttons. each pushbutton sends a specific
character throuh the transmitter.

On the receiving end, i have a receiver connected to another MSP430.
the wireless part works fine. I would like an LED to turn on when
the first push button is pressed on the transmitting end. Thefore, i
used Ti's example program for UART. When i pause the receiving end
and check for RXBUF i do get the transmitted value. However, it
seems that I am doing something wrong with the interrupt, or at least
TI. What happens is that it never actually gets out of the interrupt
i have tried using _BIC_SR but still doesn't work.
Could you please let me know, what I'm doing wrong. I am fairly new
and am using the MSP430F2132.

int test = 0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT

if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ =0xFF)
{
while(1); // If calibration
constants erased
// do not load, trap CPU!!
}
P1DIR |= BIT0;
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
P3DIR &= ~BIT5;
P3SEL = 0x30; // P3.4,5 = USCI_A0
TXD/RXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 0x35; // 1MHz 30bps
UCA0BR1 = 0x82; // 1MHz 30 bps
UCA0MCTL = 0x94; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI
state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX
interrupt

for(;;){
test = 0;
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0,
interrupts enabled
if(test == 0x11)
P1OUT ^= BIT0;
}
}

#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{

test = UCA0RXBUF;
}

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.0.237 / Virus Database: 270.11.3/1968 - Release Date: 02/23/09
18:22:00



Ok, thanks a lot for your advice. So i tried that. And what happens
is that it still stops. but when i debug and then pause the program
and manually step into using (F5) it actually does gets out of the
interrupt and continues normally. However, when i try using it
without any intervention. It doesn't go any further than the
interrupt.

Please let me know,

Thanks,

Hrag
--- In m..., "Jim Smith" wrote:
>
> As the last statement in your interrupt routine, add:
> __low_power_mode_off_on_exit();
>
> This will bring the system out of LPMx to execute the next
statement (in
> your main loop) following the statement which put the system into
LPM0:
> __bis_SR_register(LPM0_bits + GIE);
>
> Hope this helps,
>
> Jim Smith
>
> _____
>
> From: m... [mailto:m...] On
Behalf Of
> hragsarkissian
> Sent: Tuesday, February 24, 2009 7:25 PM
> To: m...
> Subject: [msp430] UART problem
>
> Hi,
>
> I am working on a small UART program using wireless transmitter and
> receiver. I have on one end a transmitter connected to an msp430
> along with some pushbuttons. each pushbutton sends a specific
> character throuh the transmitter.
>
> On the receiving end, i have a receiver connected to another
MSP430.
> the wireless part works fine. I would like an LED to turn on when
> the first push button is pressed on the transmitting end. Thefore,
i
> used Ti's example program for UART. When i pause the receiving end
> and check for RXBUF i do get the transmitted value. However, it
> seems that I am doing something wrong with the interrupt, or at
least
> TI. What happens is that it never actually gets out of the
interrupt
> i have tried using _BIC_SR but still doesn't work.
> Could you please let me know, what I'm doing wrong. I am fairly new
> and am using the MSP430F2132.
>
> int test = 0;
> void main(void)
> {
> WDTCTL = WDTPW + WDTHOLD; // Stop WDT
>
> if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ => 0xFF)
> {
> while(1); // If calibration
> constants erased
> // do not load, trap CPU!!
> }
> P1DIR |= BIT0;
> BCSCTL1 = CALBC1_1MHZ; // Set DCO
> DCOCTL = CALDCO_1MHZ;
> P3DIR &= ~BIT5;
> P3SEL = 0x30; // P3.4,5 = USCI_A0
> TXD/RXD
> UCA0CTL1 |= UCSSEL_2; // SMCLK
> UCA0BR0 = 0x35; // 1MHz 30bps
> UCA0BR1 = 0x82; // 1MHz 30 bps
> UCA0MCTL = 0x94; // Modulation UCBRSx = 1
> UCA0CTL1 &= ~UCSWRST; // **Initialize USCI
> state machine**
> IE2 |= UCA0RXIE; // Enable USCI_A0 RX
> interrupt
>
> for(;;){
> test = 0;
> __bis_SR_register(LPM0_bits + GIE); // Enter LPM0,
> interrupts enabled
> if(test == 0x11)
> P1OUT ^= BIT0;
> }
> }
>
> #pragma vector=USCIAB0RX_VECTOR
> __interrupt void USCI0RX_ISR(void)
> {
>
> test = UCA0RXBUF;
> }
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 8.0.237 / Virus Database: 270.11.3/1968 - Release Date:
02/23/09
> 18:22:00
>
>

What exactly do you mean by "It doesn't go any further than the
interrupt."??
What are you expecting your program to do? What does (or doesn't) it do?
What compiler are you using? If it's IAR, I'd suggest to replace
"__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, "
by
_EINT();
LPM0;

Better yet, place _EINT() before for(;;) as you only need to turn on
the GIE bit once.

Michael K.

--- In m..., "hragsarkissian"
wrote:
>
> Ok, thanks a lot for your advice. So i tried that. And what happens
> is that it still stops. but when i debug and then pause the program
> and manually step into using (F5) it actually does gets out of the
> interrupt and continues normally. However, when i try using it
> without any intervention. It doesn't go any further than the
> interrupt.
>
> Please let me know,
>
> Thanks,
>
> Hrag
> --- In m..., "Jim Smith" wrote:
> >
> > As the last statement in your interrupt routine, add:
> > __low_power_mode_off_on_exit();
> >
> > This will bring the system out of LPMx to execute the next
> statement (in
> > your main loop) following the statement which put the system into
> LPM0:
> > __bis_SR_register(LPM0_bits + GIE);
> >
> > Hope this helps,
> >
> > Jim Smith
> >
> > _____
> >
> > From: m... [mailto:m...] On
> Behalf Of
> > hragsarkissian
> > Sent: Tuesday, February 24, 2009 7:25 PM
> > To: m...
> > Subject: [msp430] UART problem
> >
> >
> >
> > Hi,
> >
> > I am working on a small UART program using wireless transmitter and
> > receiver. I have on one end a transmitter connected to an msp430
> > along with some pushbuttons. each pushbutton sends a specific
> > character throuh the transmitter.
> >
> > On the receiving end, i have a receiver connected to another
> MSP430.
> > the wireless part works fine. I would like an LED to turn on when
> > the first push button is pressed on the transmitting end. Thefore,
> i
> > used Ti's example program for UART. When i pause the receiving end
> > and check for RXBUF i do get the transmitted value. However, it
> > seems that I am doing something wrong with the interrupt, or at
> least
> > TI. What happens is that it never actually gets out of the
> interrupt
> > i have tried using _BIC_SR but still doesn't work.
> > Could you please let me know, what I'm doing wrong. I am fairly new
> > and am using the MSP430F2132.
> >
> > int test = 0;
> > void main(void)
> > {
> > WDTCTL = WDTPW + WDTHOLD; // Stop WDT
> >
> >
> >
> > if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ => > 0xFF)
> > {
> > while(1); // If calibration
> > constants erased
> > // do not load, trap CPU!!
> > }
> > P1DIR |= BIT0;
> > BCSCTL1 = CALBC1_1MHZ; // Set DCO
> > DCOCTL = CALDCO_1MHZ;
> > P3DIR &= ~BIT5;
> > P3SEL = 0x30; // P3.4,5 = USCI_A0
> > TXD/RXD
> > UCA0CTL1 |= UCSSEL_2; // SMCLK
> > UCA0BR0 = 0x35; // 1MHz 30bps
> > UCA0BR1 = 0x82; // 1MHz 30 bps
> > UCA0MCTL = 0x94; // Modulation UCBRSx = 1
> > UCA0CTL1 &= ~UCSWRST; // **Initialize USCI
> > state machine**
> > IE2 |= UCA0RXIE; // Enable USCI_A0 RX
> > interrupt
> >
> > for(;;){
> > test = 0;
> > __bis_SR_register(LPM0_bits + GIE); // Enter LPM0,
> > interrupts enabled
> > if(test == 0x11)
> > P1OUT ^= BIT0;
> > }
> > }
> >
> > #pragma vector=USCIAB0RX_VECTOR
> > __interrupt void USCI0RX_ISR(void)
> > {
> >
> > test = UCA0RXBUF;
> > }
> >
> >
> >
> >
> >
> > No virus found in this incoming message.
> > Checked by AVG - www.avg.com
> > Version: 8.0.237 / Virus Database: 270.11.3/1968 - Release Date:
> 02/23/09
> > 18:22:00
> >
> >
> >
> >
> >
>

Hrag, try this:

In your interrupt routine, replace "Test = UCA0RXBUF;" with "if(UCA0RXBUF 0x11) P1 ^= BIT0; __no_operation();"

And, change your main routine for-loop to: "for(;;){__low_power_mode_1();
__no_operation();}"

Now you can set breakpoints on the "__no_operation();" statement in both
places to see what is happening.

Let me know if this helps.

Jim Smith
________________________________

From: m... [mailto:m...] On Behalf Of
hragsarkissian
Sent: Friday, February 27, 2009 3:15 PM
To: m...
Subject: [msp430] Re: UART problem

Ok, thanks a lot for your advice. So i tried that. And what happens
is that it still stops. but when i debug and then pause the program
and manually step into using (F5) it actually does gets out of the
interrupt and continues normally. However, when i try using it
without any intervention. It doesn't go any further than the
interrupt.

Please let me know,

Thanks,

Hrag
--- In m... , "Jim
Smith" wrote:
>
> As the last statement in your interrupt routine, add:
> __low_power_mode_off_on_exit();
>
> This will bring the system out of LPMx to execute the next
statement (in
> your main loop) following the statement which put the system into
LPM0:
> __bis_SR_register(LPM0_bits + GIE);
>
> Hope this helps,
>
> Jim Smith
>
> _____
>
> From: m...
[mailto:m... ] On
Behalf Of
> hragsarkissian
> Sent: Tuesday, February 24, 2009 7:25 PM
> To: m...
> Subject: [msp430] UART problem
>
> Hi,
>
> I am working on a small UART program using wireless transmitter and
> receiver. I have on one end a transmitter connected to an msp430
> along with some pushbuttons. each pushbutton sends a specific
> character throuh the transmitter.
>
> On the receiving end, i have a receiver connected to another
MSP430.
> the wireless part works fine. I would like an LED to turn on when
> the first push button is pressed on the transmitting end. Thefore,
i
> used Ti's example program for UART. When i pause the receiving end
> and check for RXBUF i do get the transmitted value. However, it
> seems that I am doing something wrong with the interrupt, or at
least
> TI. What happens is that it never actually gets out of the
interrupt
> i have tried using _BIC_SR but still doesn't work.
> Could you please let me know, what I'm doing wrong. I am fairly new
> and am using the MSP430F2132.
>
> int test = 0;
> void main(void)
> {
> WDTCTL = WDTPW + WDTHOLD; // Stop WDT
>
> if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ => 0xFF)
> {
> while(1); // If calibration
> constants erased
> // do not load, trap CPU!!
> }
> P1DIR |= BIT0;
> BCSCTL1 = CALBC1_1MHZ; // Set DCO
> DCOCTL = CALDCO_1MHZ;
> P3DIR &= ~BIT5;
> P3SEL = 0x30; // P3.4,5 = USCI_A0
> TXD/RXD
> UCA0CTL1 |= UCSSEL_2; // SMCLK
> UCA0BR0 = 0x35; // 1MHz 30bps
> UCA0BR1 = 0x82; // 1MHz 30 bps
> UCA0MCTL = 0x94; // Modulation UCBRSx = 1
> UCA0CTL1 &= ~UCSWRST; // **Initialize USCI
> state machine**
> IE2 |= UCA0RXIE; // Enable USCI_A0 RX
> interrupt
>
> for(;;){
> test = 0;
> __bis_SR_register(LPM0_bits + GIE); // Enter LPM0,
> interrupts enabled
> if(test == 0x11)
> P1OUT ^= BIT0;
> }
> }
>
> #pragma vector=USCIAB0RX_VECTOR
> __interrupt void USCI0RX_ISR(void)
> {
>
> test = UCA0RXBUF;
> }
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 8.0.237 / Virus Database: 270.11.3/1968 - Release Date:
02/23/09
> 18:22:00
>
>

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.0.237 / Virus Database: 270.11.5/1977 - Release Date: 02/28/09
17:21:00

No virus found in this outgoing message.
Checked by AVG - www.avg.com
Version: 8.0.237 / Virus Database: 270.11.5/1977 - Release Date: 03/01/09
17:46:00

Correction: "Test = UCA0RXBUF;" with "if(UCA0RXBUF = 0x11) P1 ^= BIT0;
__no_operation();"
Should be: "Test = UCA0RXBUF;" with "if(UCA0RXBUF == 0x11) P1 ^= BIT0;
__no_operation();"

Either my mind was asleep, or I missed a key in entering the phrase!

Jim Smith

-----Original Message-----
From: m... [mailto:m...] On Behalf Of
Jim Smith
Sent: Monday, March 02, 2009 1:30 AM
To: m...
Subject: RE: [msp430] Re: UART problem

Hrag, try this:

In your interrupt routine, replace "Test = UCA0RXBUF;" with "if(UCA0RXBUF 0x11) P1 ^= BIT0; __no_operation();"

And, change your main routine for-loop to: "for(;;){__low_power_mode_1();
__no_operation();}"

Now you can set breakpoints on the "__no_operation();" statement in both
places to see what is happening.

Let me know if this helps.

Jim Smith
________________________________

From: m... [mailto:m...] On Behalf Of
hragsarkissian
Sent: Friday, February 27, 2009 3:15 PM
To: m...
Subject: [msp430] Re: UART problem

Ok, thanks a lot for your advice. So i tried that. And what happens
is that it still stops. but when i debug and then pause the program
and manually step into using (F5) it actually does gets out of the
interrupt and continues normally. However, when i try using it
without any intervention. It doesn't go any further than the
interrupt.

Please let me know,

Thanks,

Hrag
--- In m... , "Jim
Smith" wrote:
>
> As the last statement in your interrupt routine, add:
> __low_power_mode_off_on_exit();
>
> This will bring the system out of LPMx to execute the next
statement (in
> your main loop) following the statement which put the system into
LPM0:
> __bis_SR_register(LPM0_bits + GIE);
>
> Hope this helps,
>
> Jim Smith
>
> _____
>
> From: m...
[mailto:m... ] On
Behalf Of
> hragsarkissian
> Sent: Tuesday, February 24, 2009 7:25 PM
> To: m...
> Subject: [msp430] UART problem
>
> Hi,
>
> I am working on a small UART program using wireless transmitter and
> receiver. I have on one end a transmitter connected to an msp430
> along with some pushbuttons. each pushbutton sends a specific
> character throuh the transmitter.
>
> On the receiving end, i have a receiver connected to another
MSP430.
> the wireless part works fine. I would like an LED to turn on when
> the first push button is pressed on the transmitting end. Thefore,
i
> used Ti's example program for UART. When i pause the receiving end
> and check for RXBUF i do get the transmitted value. However, it
> seems that I am doing something wrong with the interrupt, or at
least
> TI. What happens is that it never actually gets out of the
interrupt
> i have tried using _BIC_SR but still doesn't work.
> Could you please let me know, what I'm doing wrong. I am fairly new
> and am using the MSP430F2132.
>
> int test = 0;
> void main(void)
> {
> WDTCTL = WDTPW + WDTHOLD; // Stop WDT
>
> if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ => 0xFF)
> {
> while(1); // If calibration
> constants erased
> // do not load, trap CPU!!
> }
> P1DIR |= BIT0;
> BCSCTL1 = CALBC1_1MHZ; // Set DCO
> DCOCTL = CALDCO_1MHZ;
> P3DIR &= ~BIT5;
> P3SEL = 0x30; // P3.4,5 = USCI_A0
> TXD/RXD
> UCA0CTL1 |= UCSSEL_2; // SMCLK
> UCA0BR0 = 0x35; // 1MHz 30bps
> UCA0BR1 = 0x82; // 1MHz 30 bps
> UCA0MCTL = 0x94; // Modulation UCBRSx = 1
> UCA0CTL1 &= ~UCSWRST; // **Initialize USCI
> state machine**
> IE2 |= UCA0RXIE; // Enable USCI_A0 RX
> interrupt
>
> for(;;){
> test = 0;
> __bis_SR_register(LPM0_bits + GIE); // Enter LPM0,
> interrupts enabled
> if(test == 0x11)
> P1OUT ^= BIT0;
> }
> }
>
> #pragma vector=USCIAB0RX_VECTOR
> __interrupt void USCI0RX_ISR(void)
> {
>
> test = UCA0RXBUF;
> }
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 8.0.237 / Virus Database: 270.11.3/1968 - Release Date:
02/23/09
> 18:22:00
>
>

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.0.237 / Virus Database: 270.11.5/1977 - Release Date: 02/28/09
17:21:00

No virus found in this outgoing message.
Checked by AVG - www.avg.com
Version: 8.0.237 / Virus Database: 270.11.5/1977 - Release Date: 03/01/09
17:46:00