EmbeddedRelated.com
Forums

UART Response Problem

Started by matthewolsthoorn March 6, 2007
Hi,

I've been trying to setup the UART on my MSP430f149 using the sample
code given. I haven't had much luck. I'm not sure exactly what's going
on. The code I used is exactly the C example code provided by TI shown
below. However, the interrupt never gets called. (I've send data
directly into the receive pin). I tried to just pass data into the
transmit pin but nothing ever shows up on the pin (I used an
oscilloscope).

Is there some setup that I need to set other than these software parts?
Are there any other pins that need to be used?

This is what I've done:
Powered the Micro
Places a 8Mhz oscillator
Observed the transmit pin for any activity

So far I've not managed to get it to work. What did I miss?
#include

void main(void)
{
volatile unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD

BCSCTL1 &= ~XT2OFF; // XT2on

do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
for (i = 0xFF; i > 0; i--); // Time for flag to set
}
while ((IFG1 & OFIFG)); // OSCFault flag still set?

BCSCTL2 |= SELM_2 + SELS; // MCLK = SMCLK = XT2 (safe)
ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD
UCTL0 |= CHAR; // 8-bit character
UTCTL0 |= SSEL1; // UCLK = SMCLK
UBR00 = 0x45; // 8MHz 115200
UBR10 = 0x00; // 8MHz 115200
UMCTL0 = 0x00; // 8MHz 115200 modulation
UCTL0 &= ~SWRST; // Initialize USART state
machine
IE1 |= URXIE0; // Enable USART0 RX interrupt

_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt

while (1)
{
TXBUF0 |=0xF0;
}
}

#pragma vector=UART0RX_VECTOR
__interrupt void usart0_rx (void)
{
while (!(IFG1 & UTXIFG0)); // USART0 TX buffer ready?
TXBUF0 = RXBUF0; // RXBUF0 to TXBUF0
}

Beginning Microcontrollers with the MSP430

> P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD

You have to set the TXD pin as output with P3DIR, enabling an alt peripheral does not
automatically enable the I/O pins to output (unlike eg. basic AVRs).
That will get your TX to work.

HTH
Best Regards,
Kris

-----Original Message-----
From: m... [mailto:m...] On Behalf Of matthewolsthoorn
Sent: Wednesday, 7 March 2007 7:55 AM
To: m...
Subject: [msp430] UART Response Problem

Hi,

I've been trying to setup the UART on my MSP430f149 using the sample
code given. I haven't had much luck. I'm not sure exactly what's going
on. The code I used is exactly the C example code provided by TI shown
below. However, the interrupt never gets called. (I've send data
directly into the receive pin). I tried to just pass data into the
transmit pin but nothing ever shows up on the pin (I used an
oscilloscope).

Is there some setup that I need to set other than these software parts?
Are there any other pins that need to be used?

This is what I've done:
Powered the Micro
Places a 8Mhz oscillator
Observed the transmit pin for any activity

So far I've not managed to get it to work. What did I miss?
#include

void main(void)
{
volatile unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD

BCSCTL1 &= ~XT2OFF; // XT2on

do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
for (i = 0xFF; i > 0; i--); // Time for flag to set
}
while ((IFG1 & OFIFG)); // OSCFault flag still set?

BCSCTL2 |= SELM_2 + SELS; // MCLK = SMCLK = XT2 (safe)
ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD
UCTL0 |= CHAR; // 8-bit character
UTCTL0 |= SSEL1; // UCLK = SMCLK
UBR00 = 0x45; // 8MHz 115200
UBR10 = 0x00; // 8MHz 115200
UMCTL0 = 0x00; // 8MHz 115200 modulation
UCTL0 &= ~SWRST; // Initialize USART state
machine
IE1 |= URXIE0; // Enable USART0 RX interrupt

_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt

while (1)
{
TXBUF0 |=0xF0;
}
}

#pragma vector=UART0RX_VECTOR
__interrupt void usart0_rx (void)
{
while (!(IFG1 & UTXIFG0)); // USART0 TX buffer ready?
TXBUF0 = RXBUF0; // RXBUF0 to TXBUF0
}

Yahoo! Groups Links
Hmmmm

I thought that for the UART pins selecting them as special specifically
DID set the IO direction.... in the 169/1611 anyway.

see pin logic diagram on page 53 of msp430f1611.pdf

David
Yeah, I'm using the 149, and you don't have to explicitly set the DIR
register for the UART to work. I think the problem is the code below,
try commenting that out and I think the echo should work.

-Peter

while (1)
{
TXBUF0 |=0xF0;
}
--- In m..., "David Collier"
wrote:
>
> Hmmmm
>
> I thought that for the UART pins selecting them as special specifically
> DID set the IO direction.... in the 169/1611 anyway.
>
> see pin logic diagram on page 53 of msp430f1611.pdf
>
> David
>
Actually, your right. This couple of lines I added to try and get the
TX pin to send anything. This of course didn't work. My problem came
about before I added this line.

--- In m..., "thapeez" wrote:
>
> Yeah, I'm using the 149, and you don't have to explicitly set the DIR
> register for the UART to work. I think the problem is the code below,
> try commenting that out and I think the echo should work.
>
> -Peter
>
> while (1)
> {
> TXBUF0 |=0xF0;
> }
> --- In m..., "David Collier"
> wrote:
> >
> > Hmmmm
> >
> > I thought that for the UART pins selecting them as special
specifically
> > DID set the IO direction.... in the 169/1611 anyway.
> >
> > see pin logic diagram on page 53 of msp430f1611.pdf
> >
> > David
>
> Yeah, I'm using the 149, and you don't have to explicitly set the DIR
> register for the UART to work.

That's news to me - I don't think so !
I distinctly recall having to set TXDs to output on F149.
(The only thing I can think of is that a later die spin changed this...)

The OP posted that sending data out of the TXD pin DID NOT work.
WTF does echo have to do with that ?

Once the TXD pin is functional, then of course writing to the TXBUFx register without waiting
for a free buffer won't help, but that's secondary.
Again, the OP stated that his TX data does not work AT ALL.

Best Regards,
Kris

-----Original Message-----
From: m... [mailto:m...] On Behalf Of thapeez
Sent: Thursday, 8 March 2007 1:51 AM
To: m...
Subject: [msp430] Re: UART Response Problem

Yeah, I'm using the 149, and you don't have to explicitly set the DIR
register for the UART to work. I think the problem is the code below,
try commenting that out and I think the echo should work.

-Peter

while (1)
{
TXBUF0 |=0xF0;
}
--- In m..., "David Collier"
wrote:
>
> Hmmmm
>
> I thought that for the UART pins selecting them as special specifically
> DID set the IO direction.... in the 169/1611 anyway.
>
> see pin logic diagram on page 53 of msp430f1611.pdf
>
> David
>

Yahoo! Groups Links
> This couple of lines I added to try and get the TX pin to send anything.
> This of course didn't work.

Geez, and thank you too for the help, fuck.
What kind of people are on this forum recently anyway ?
I've been here 7 years and I've never had someone reciprocate my help with
such arrogance.

Again, the last time I used F149 you had to set P3DIR to OUT for TXD pins to work...

-- Kris

-----Original Message-----
From: m... [mailto:m...] On Behalf Of matthewolsthoorn
Sent: Thursday, 8 March 2007 2:03 AM
To: m...
Subject: [msp430] Re: UART Response Problem

Actually, your right. This couple of lines I added to try and get the
TX pin to send anything. This of course didn't work. My problem came
about before I added this line.

--- In m..., "thapeez" wrote:
>
> Yeah, I'm using the 149, and you don't have to explicitly set the DIR
> register for the UART to work. I think the problem is the code below,
> try commenting that out and I think the echo should work.
>
> -Peter
>
> while (1)
> {
> TXBUF0 |=0xF0;
> }
> --- In m..., "David Collier"
> wrote:
> >
> > Hmmmm
> >
> > I thought that for the UART pins selecting them as special
specifically
> > DID set the IO direction.... in the 169/1611 anyway.
> >
> > see pin logic diagram on page 53 of msp430f1611.pdf
> >
> > David
>

Yahoo! Groups Links
My apologies, I guess I skimmed too fast and just assumed he wasn't
receiving good data from the uC. So I was trying to get his echo
program to work.

--- In m..., "Microbit" wrote:
>
> > Yeah, I'm using the 149, and you don't have to explicitly set the DIR
> > register for the UART to work.
>
> That's news to me - I don't think so !
> I distinctly recall having to set TXDs to output on F149.
> (The only thing I can think of is that a later die spin changed this...)
>
> The OP posted that sending data out of the TXD pin DID NOT work.
> WTF does echo have to do with that ?
>
> Once the TXD pin is functional, then of course writing to the TXBUFx
register without waiting
> for a free buffer won't help, but that's secondary.
> Again, the OP stated that his TX data does not work AT ALL.
>
> Best Regards,
> Kris
>
> -----Original Message-----
> From: m... [mailto:m...] On
Behalf Of thapeez
> Sent: Thursday, 8 March 2007 1:51 AM
> To: m...
> Subject: [msp430] Re: UART Response Problem
>
> Yeah, I'm using the 149, and you don't have to explicitly set the DIR
> register for the UART to work. I think the problem is the code below,
> try commenting that out and I think the echo should work.
>
> -Peter
>
> while (1)
> {
> TXBUF0 |=0xF0;
> }
> --- In m..., "David Collier"
> wrote:
> >
> > Hmmmm
> >
> > I thought that for the UART pins selecting them as special
specifically
> > DID set the IO direction.... in the 169/1611 anyway.
> >
> > see pin logic diagram on page 53 of msp430f1611.pdf
> >
> > David
> >
>
> Yahoo! Groups Links
>
Good luck with your code ....
One day a customer will be using (old stock) F149 instead and it'll be :
"Gosh, the serial just stopped working, we just can't figure out why...".

Two days of frantic debugging later it'll sound like this :
"Oops, I thought that the P3DIR register didn't need setting its bits for the TXD pin(s)..."

And all for the sake of 1 line of ASM or C...
Well, I guess we'll never know now :-)

Best Regards,
Kris

-----Original Message-----
From: m... [mailto:m...] On Behalf Of David Collier
Sent: Wednesday, 7 March 2007 10:13 PM
To: m...
Subject: RE: [msp430] UART Response Problem

Hmmmm

I thought that for the UART pins selecting them as special specifically
DID set the IO direction.... in the 169/1611 anyway.

see pin logic diagram on page 53 of msp430f1611.pdf

David

Yahoo! Groups Links
> > This couple of lines I added to try and get the TX pin to send
anything.
> > This of course didn't work.
> Geez, and thank you too for the help, fuck.
> What kind of people are on this forum recently anyway ?
> I've been here 7 years and I've never had someone reciprocate my
help with
> such arrogance.
>
> Again, the last time I used F149 you had to set P3DIR to OUT for TXD
pins to work...
>
> -- Kris
I didn't mean to be rude. I'm sorry if I was. I was just trying to be
thorough.