TI中文支持网
TI专业的中文技术问题搜集分享网站

msp430 launchpad uart通信

我的设备是MSP EXP430 LaunchPad, 芯片是msp430g2553, 我正在尝试通过UART的方式与PC端进行通信,我相信我的数据已经成功放到UCA0TXBUF里面了,可是在PC端却没有办法接收到数据。我已经尝试了Teraterm,CCS6里面的terminal以及其他第三方的终端都接收不到数据。请问这是为什么?我在终端的接收配置也是8-n-1,9600,应该是没有问题的吧。
如果觉得麻烦能够直接给我一个可以成功和PC通信的uart example吗?
谢谢
以下是我的代码:
#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;
}
 
kqian0327:

你好,

该问题以前也you网友问过类似问题,MSP430G2XX LP 板子之前有一点问题,MSP430G2553的TX,RX和板子上的丝印正好是反的,所以你需要交叉左上脚TX,RX跳帽。

赞(0)
未经允许不得转载:TI中文支持网 » msp430 launchpad uart通信
分享到: 更多 (0)