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.
我在msp430G2755上写了一段uart串口通讯程序,但运行不成功,不知什么问题?
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
if(UCA0RXBUF==2)
{instru[0]=2;
com_p=0;
}
else if(instru[0]==2)
{instru[++com_p]=UCA0RXBUF;
if(UCA0RXBUF==3||com_p>19)
com=1; // 命令结束
}
else
{instru[com_p]=UCA0RXBUF;
com_p++;
}
if(com_p>=29) com_p=0;
}
//////////串行口初始化
void ini_usart115k()
{
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_1MHZ; // Set DCO 0x86;//
DCOCTL = CALDCO_1MHZ; // 0xdb;//
P3SEL = BIT4 + BIT5 ; // P3.5 = RXD, P3.4=TXD
P3SEL2 = BIT4 + BIT5;
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 8; // 1MHz 115200
UCA0BR1 = 0; // 1MHz 115200
UCA0MCTL = UCBRS2 + UCBRS0; // Modulation UCBRSx = 5
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
}
您好,请参考一下TI提供的例程:
C:\ti\msp\MSP430Ware_3_80_14_01\examples\devices\MSP430G2xx\MSP430G2x55_Code_Examples\C
//////////串行口初始化
void ini_usart115k()
{
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_1MHZ; // Set DCO 0x86;//
DCOCTL = CALDCO_1MHZ; // 0xdb;//
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2;
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 8; // 1MHz 115200
UCA0BR1 = 0; // 1MHz 115200
UCA0MCTL = UCBRS2 + UCBRS0; // Modulation UCBRSx = 5
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
}
以上这段uart()初始化程序能够在msp430g2553上很好运行;后来我只是把P1,1和P1.2改成P3.4,P3.5就不能正常工作了;昨天我把tx和rx接到超级终端上检测,发现能够收到超级终端发出的字符,但超级终端不能收到2755发出的字符,检查寄存器UCA0TXBUF中的字符也是正确的,UCA0TXIFG置位也对,但不知何故就是没有输出信息?
发送函数:
int to232(char c) //发送一个字符
{
if(c<1||c>126) c='0';
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = c; //
return(c);
}