各位大神好,我的调试程序发现,MSP430G2553串口可以正确接收(LCD显示值与PC机串口调试助手发送值一致),但MSP430执行串口回送时调试助手无显示。 进一步查看,发现由芯片的引脚4(TXD)上示波器根本看不到波形,引脚3(RXD)上波形正确。 反复查看代码也没看出问题,请大家帮忙指定下,谢谢!
#include "msp430G2553.h"
unsigned char g_ucRxdByte;
void WatchDog_Init(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
}
void Clock_Init(void)
{
BCSCTL1 = CALBC1_8MHZ;
DCOCTL = CALDCO_8MHZ;
BCSCTL2 = SELM_0 | DIVS_0;
}
void Io_Init(void)
{
P1SEL = 0x06;
P1SEL2 = 0x06;
}
void Uart_Init(void)
{
UCA0CTL1 |=UCSWRST; //
UCA0CTL1 = 0x80; //时钟源:SMCLK(=8M),工作模式
UCA0CTL0 = 0x00; //无校验,8位数据,1个停止位,UART模式,异步
UCA0BR0 = 0x0a; UCA0BR1 = 0x1a; //1200波特率
UCA0MCTL = 0x00; //UCBRFx=0 UCBRSx=2 UCOS16=0
UCA0STAT = 0x00; //错误状态指示清零
UCA0CTL1 &= ~UCSWRST; //Clearing UCSWRST releases the USCI for operation
IE2 |= UCA0RXIE; //使能接收中断
IFG2 &= ~(UCA0TXIFG + UCA0RXIFG);
}
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
g_ucRxdByte = UCA0RXBUF;
UCA0TXBUF = g_ucRxdByte;
while((IFG2 & UCA0TXIFG)==0); //查询发送是否结束
}
void main(void)
{
WatchDog_Init();
Clock_Init();
Io_Init();
Uart_Init();
_EINT();
for(;;);
}
|