EmbeddedRelated.com
Forums

trouble working with UART on MSP430F149

Started by joebobbear July 8, 2003
Hello,

I've just started with the MSP430 in the past month, and have found 
it great. I've just started the past couple of days to try and send 
my data out via the UART to a serial port. The problem is that I'm 
getting different data than I send, along with Uart Receiver Errors 
and Uart Receiver Framing Errors.  

I am using mspgcc at the moment. Here is my code (hopefully the 
linebreaks won't be too badly botched):

____________________________________

#include <io.h>
#include <signal.h>

// Prototypes
void wait(int value);

//Globals
unsigned char n;

// **********************************************************
int main(void)
{
	WDTCTL = WDTPW + WDTHOLD; // Stop WDT
	UTCTL0 = SSEL0;		// UCLK = ACLK
	UBR00 = 0x0D;		// 32k/2400 = 13.65
	UBR10 = 0x00;
	UMCTL0 = 0x6B;		// modulation
	UCTL0 = CHAR; 	        // 8-bit character
	ME1 |= UTXE0 + URXE0; 	// Enable USART0 TXD/RXD
	P3SEL |= 0x30; 	// P3.4,5 = USART0 TXD/RXD
	P3DIR |= 0x10; 	// P3.4 output direction

	UCTL0 |= SPB;		// 2 stop bits
	UCTL0 &= ~PENA;		// parity disable

	n = 100;	// 'd' char for sending

	for (;;) 
	{
		wait(100);
		while ((IFG1 & UTXIFG0) == 0);//USART0 TX ready?
		TXBUF0 = n;
	}
	return 0;
}


void wait(int value)	//delay function
{
  volatile int i;	//declare i as volatile int
  for(i=0;i<value;i++)	//repeat 32000 times
	nop();
}

__________________________________

My circuit is of the plain-vanilla variety:

//
//                      	   TI-MSP430F149
//                        ^      -----------------
//                       /|\    |             XIN |-  
//                        |     |                 | 32kHz
//                        ------|RST         XOUT |- 
//                              |                 |
//                              |                 |
//                              |                 |
//                 UART_RX ---->|P3.5             |
//                 UART_TX <----|P3.4             |
//                              |                 |

_____________________________________

Some examples of the data I'm getting:
with n set to 0 I get 223
with n set to 1 I get 159 (with some 223s)
with n set to 100 I get 57 (with some 121s)
etc.

I've tested this with serial ports on multiple computers (running 
multiple Operating Systems) and get the same results.

Any help to get this going would be greatly appreciated. It doesn't 
seem like it should be that hard!

Thanks in advance,
  -Tim Place




Beginning Microcontrollers with the MSP430

Dear member!
The first obvious thing is that u have not reset the UART. (The 
software reset, SWRST bit). The sequence should be:
Initialize the UART
Enable any interrupts
reset the UART
----regards
Khubaib


--- In msp430@msp4..., "joebobbear" <mrbear@s...> wrote:
> Hello,
> 
> I've just started with the MSP430 in the past month, and have found 
> it great. I've just started the past couple of days to try and send 
> my data out via the UART to a serial port. The problem is that I'm 
> getting different data than I send, along with Uart Receiver Errors 
> and Uart Receiver Framing Errors.  
> 
> I am using mspgcc at the moment. Here is my code (hopefully the 
> linebreaks won't be too badly botched):
> 
> ____________________________________
> 
> #include <io.h>
> #include <signal.h>
> 
> // Prototypes
> void wait(int value);
> 
> //Globals
> unsigned char n;
> 
> // **********************************************************
> int main(void)
> {
> 	WDTCTL = WDTPW + WDTHOLD; // Stop WDT
> 	UTCTL0 = SSEL0;		// UCLK = ACLK
> 	UBR00 = 0x0D;		// 32k/2400 = 13.65
> 	UBR10 = 0x00;
> 	UMCTL0 = 0x6B;		// modulation
> 	UCTL0 = CHAR; 	        // 8-bit character
> 	ME1 |= UTXE0 + URXE0; 	// Enable USART0 TXD/RXD
> 	P3SEL |= 0x30; 	// P3.4,5 = USART0 TXD/RXD
> 	P3DIR |= 0x10; 	// P3.4 output direction
> 
> 	UCTL0 |= SPB;		// 2 stop bits
> 	UCTL0 &= ~PENA;		// parity disable
> 
> 	n = 100;	// 'd' char for sending
> 
> 	for (;;) 
> 	{
> 		wait(100);
> 		while ((IFG1 & UTXIFG0) == 0);//USART0 TX ready?
> 		TXBUF0 = n;
> 	}
> 	return 0;
> }
> 
> 
> void wait(int value)	//delay function
> {
>   volatile int i;	//declare i as volatile int
>   for(i=0;i<value;i++)	//repeat 32000 times
> 	nop();
> }
> 
> __________________________________
> 
> My circuit is of the plain-vanilla variety:
> 
> //
> //                      	   TI-MSP430F149
> //                        ^      -----------------
> //                       /|\    |             XIN |-  
> //                        |     |                 | 32kHz
> //                        ------|RST         XOUT |- 
> //                              |                 |
> //                              |                 |
> //                              |                 |
> //                 UART_RX ---->|P3.5             |
> //                 UART_TX <----|P3.4             |
> //                              |                 |
> 
> _____________________________________
> 
> Some examples of the data I'm getting:
> with n set to 0 I get 223
> with n set to 1 I get 159 (with some 223s)
> with n set to 100 I get 57 (with some 121s)
> etc.
> 
> I've tested this with serial ports on multiple computers (running 
> multiple Operating Systems) and get the same results.
> 
> Any help to get this going would be greatly appreciated. It doesn't 
> seem like it should be that hard!
> 
> Thanks in advance,
>   -Tim Place