我的开发板运行程序后与能够正常发出字符,但是在串口调试软件access port 中如果开启自动加入回车换行,那么连续发的字符串会被打断成好几行显示,平均一行只有一两个字符,请问这是什么原因?
还有一个问题,430在接受电脑发出的字符串时,每次都只能收到字符串最后一个字符。
还请各位高手多多指教,先谢谢了
下面是我的程序:
#include <msp430.h>
#define UART0_TXD BIT0
#define UART0_RXD BIT1
#define RXBUF_SIZE 32
#define TXBUF_SIZE 32
//GLOBAL VARIABLE
unsigned char RXBUF[RXBUF_SIZE],TXBUF[TXBUF_SIZE];
unsigned char RXBUF_LEN,TXBUF_LEN;
unsigned char RXBUF_FIFO_FULL,TXBUF_FIFO_FULL;
unsigned char RXBUF_R,RXBUF_W;
unsigned char TXBUF_R,TXBUF_W;
unsigned char data1[]="AAT
";
unsigned char data2[]="ATD15651666695;
";
unsigned char i;
/*
* main.c
*/
void CS_INIT();
void UART0_INIT();
void IO_INIT();
char UART_PUT_CHAR(unsigned char);
char UART_GET_CHAR(unsigned char *);
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
CS_INIT();
UART0_INIT();
IO_INIT();
_bis_SR_register(GIE);
for (i=0;i<16;i++)
UART_PUT_CHAR(data2
);
while(1)
{
while(!UART_GET_CHAR(&i));
UART_PUT_CHAR(i);
}
}
void CS_INIT()
{
CSCTL0_H = 0xA5;
CSCTL1 |=DCORSEL + DCOFSEL0 + DCOFSEL1; // Set max. DCO setting
CSCTL2 = SELA_1 + SELS_3 + SELM_3; // Set ACLK = VLO; MCLK = DCO
CSCTL3 = DIVA_0 + DIVS_5 + DIVM_1; // Set all dividers
CSCTL0_H = 0x00; // Reset password
}
void UART0_INIT()
{
// Configure UART pins
P2SEL1 |= BIT0 + BIT1;
P2SEL0 &= ~(BIT0 + BIT1);
// Configure UART 0
UCA0CTL1 |= UCSWRST;
UCA0CTL1 &= ~(UCPEN|UC7BIT|UCSPB);
UCA0CTL1 |= UCSSEL_2; // SMCLK = 743750HZ -> BAUD RATE = 9600
// N = 77.473958333 DIVIDE
UCA0BR0=4; // INT(77.473958333/16) = 4
UCA0BR1=0;
UCA0MCTLW |= 0x0001; // UCOS16 = 1 Enable oversampling
UCA0MCTLW |= 0x00F0; // UCBRF0 = D INT((77.4739/16-INT(77.4739/16))*16)=13
UCA0MCTLW |= 0xAA00; // UCBRS0 = 0xAA 77.4739-INT(77.4739)=0.4739
UCA0CTL1 &= ~UCSWRST; //Release from reset
UCA0IE |= UCTXIE|UCRXIE;//ENABLE RX/TX INTERRUPT
}
void IO_INIT()
{
P3DIR |= BIT4+BIT5+BIT6+BIT7;
P3OUT &=~(BIT4+BIT5+BIT6+BIT7);
PJDIR |= BIT0+BIT1+BIT2+BIT3;
PJOUT &=~(BIT0+BIT1+BIT2+BIT3);
}
char UART_PUT_CHAR(unsigned char data)
{
if (TXBUF_LEN == TXBUF_SIZE)
{
TXBUF_FIFO_FULL = 1;
return 0;
}
_disable_interrupts();
if (TXBUF_LEN == 0)
{
UCA0IE |= UCTXIE;
if (!(UCA0STATW & UCBUSY))
UCA0IFG |= UCTXIFG;
}
TXBUF[TXBUF_W++] = data;
if (TXBUF_W == TXBUF_SIZE)
TXBUF_W = 0;
TXBUF_LEN ++;
_enable_interrupts();
return 1;
}
char UART_GET_CHAR(unsigned char *ptr)
{
if (RXBUF_LEN == 0)
return 0;
_disable_interrupts();
RXBUF_LEN --;
*ptr = RXBUF[RXBUF_R++];
if (RXBUF_R == RXBUF_SIZE)
RXBUF_R = 0;
_enable_interrupts();
return 1;
}
#pragma vector = USCI_A0_VECTOR
__interrupt void UART0(void)
{
switch (UCA0IV)
{
case 0:
break;
case 2:
if (RXBUF_LEN == RXBUF_SIZE)
{
UCA0IFG &= ~UCRXIFG; //Clear RX interrupt flag
RXBUF_FIFO_FULL = 1; //Set FIFO full
break;
}
RXBUF[RXBUF_W++] = UCA0RXBUF; //Get data from UCA0RXBUF
if (RXBUF_W == RXBUF_SIZE)
RXBUF_W = 0;
RXBUF_LEN++;
break;
case 4:
if (TXBUF_LEN > 0)
{
TXBUF_LEN--;
UCA0TXBUF = TXBUF[TXBUF_R++]; //Send data
if (TXBUF_R == TXBUF_SIZE)
TXBUF_R = 0;
}
else UCA0IE &= ~UCTXIE; //Turn off transmit
break;
case 8:
break;
}
}
此帖出自小平头技术问答
一周热门 更多>