This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430 UART communication with PC

I am making my MSP430 LaunchPad communicate to PC. The chip is MSP EXP430G2553, and I utilize USCI. I think I have successfully put my data into UCA0BUF, but I just receive nothing in the terminal on PC. ( I have tried Teraterm, the terminal of CCS and another third party terminal software, but none of them receive even a byte.)

Can anyone helps me? I have been trapped in this problem for 2 days.

Or if you think it's wasting time to read through my codes, can you give me an example of the UART communication to PC?

My ISR code gives as below:

#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void) {
	if (UART_OutLen > 0) {
		UART_OutLen--;
		UCA0TXBUF = TX_BUFF[TX_IndexR];
		while (!(IFG2 & UCA0TXIFG));				//to check the state of the TXbuffer
		if (++TX_IndexR >= TXBUF_SIZE) {
			TX_IndexR = 0;
		}
	} else
		IE2 &= ~UCA0TXIE;
}

And my whole program gives as below:

#include <msp430.h>
#include "stdint.h"
#include <stdio.h>

static const RXBUF_SIZE = 16;
static const TXBUF_SIZE = 16;
static const uint8_t ch = 'a';
int g = 0;
int tmp;
char tmp2;
unsigned char RX_BUFF[RXBUF_SIZE] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		0, 0 }; 									//receive buffer
unsigned int UART_InLen = 16; 						//input data lenth
unsigned char TX_BUFF[TXBUF_SIZE] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
		0, 0 }; 									//
unsigned int UART_OutLen = 16; 						//data length
unsigned int TX_IndexR = 0; 						//FIFO pointer for RX
unsigned int TX_IndexW = 0; 						//FIFO pointer for WX

unsigned char *str = "helloworld!!!!!";


void main(void)
{
	MCU_init();
	LED_init();
	UART_init();
	UART_sent(ch);
	_delay_cycles(10);
	UART0_PutFrame(str,16);
	int temp = 0;

}

void MCU_init(void) {

	WDTCTL = WDTPW + WDTHOLD;                 		// Stop WDT

	BCSCTL1 = CALBC1_1MHZ;                   		// Set range
	DCOCTL = CALDCO_1MHZ;
	BCSCTL2 &= ~(DIVS_3);                     		// SMCLK = DCO = 1MHz

	_BIS_SR(GIE);									// Enable global interrupt
}


void UART_init(void) {
	UCA0CTL1 |= UCSWRST;
	UCA0CTL1 |= UCSSEL_2; 							//SMCLK
	UCA0BR0 = 0x68; 								//32.768/9600=
	UCA0BR1 = 0x00; 								// 1000kHz/9600 = 104.166 =0X68 波特率9600
	UCA0MCTL = UCBRS_2; 							// Modulation UCBRSx = 1
	UCA0CTL0 &= ~UCPEN;
	UCA0CTL0 &= ~UCSPB;
	UCA0CTL0 &= ~UC7BIT;
	UCA0CTL1 &= ~UCSWRST;
	P1SEL |= BIT1 + BIT2;
	P1SEL2 |= BIT1 + BIT2;
	//P1DIR |=BIT2;									//dont need to configure output in this pin?
	IFG2 &= ~UCA0TXIFG;
	IE2 |= UCA0RXIE + UCA0TXIE;
	unsigned int j;
	for (j = 0; j < 2000; j++)
		;
}

/*
* Put data into buffer and enable the interruption
*/
int UART0_PutFrame(unsigned char *Ptr, unsigned int Lenth) {
	int i;
	if (IE2 & UCA0TXIE) {
		return (0);
	}
	if (Lenth > TXBUF_SIZE) {
		return (0);
	}
	for (i = 0; i < Lenth; i++) {
		TX_BUFF[i] = Ptr[i];
	}
	TX_IndexR = 0;
	UART_OutLen = Lenth;
	IFG2 |= UCA0TXIFG;
	IE2 |= UCA0TXIE;
	return (1);
}

/*
* try to send one char
*/
void UART_sent(uint8_t Chr) {
	IFG2 &= ~UCA0TXIFG;
	UCA0TXBUF = Chr;
	while ((IFG2 & UCA0TXIFG) == 0)
		;				// USCI_A0 TX buffer ready?
}

/*
* ISR of TX
*/
#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void) {
	if (UART_OutLen > 0) {
		UART_OutLen--;
		UCA0TXBUF = TX_BUFF[TX_IndexR];
		while (!(IFG2 & UCA0TXIFG));				//USCI_A0 TX buffer ready?
		if (++TX_IndexR >= TXBUF_SIZE) {
			TX_IndexR = 0;
		}
	} else
		IE2 &= ~UCA0TXIE;
}



THX.

 

**Attention** This is a public forum