вот этот код работает char volatile rx_buf0[RxBufSize0];
char rx_head0;
volatile char rx_tail0;
char tx_buf0[TxBufSize0];
volatile char tx_head0;
char tx_tail0;
void Uart0Configuration38400(void)
{
UCA0CTL0 =
// UCSYNC | // asynchro
// UCMODE0 | //
// UCMODE1 | // mode 00 = UART
// UCSPB | // 0: one stop bit
// UC7BIT | // 0: 8 bit
// UCMSB | // 0: LSB
// UCPAR | // not used, no matter
// UCPEN | // 0: parity disabled
0;
UCA0CTL1 = UCSWRST | // reset uart perifery flag = 0
// UCXBRK | // next frame is not break
// UCTXADDR| // next frame is data
// UCDORM | // not dormant
// UCBRKIE | // not interrupt for break
// UCRXEIE | // not interrupt for
UCSSEL0 | // UCLK=SMCLK (8MHz)
UCSSEL1 | //
0;
UCA0BR0 = 0xD0; // 8MHz/38400 = 208 or 0xD0 ( from datasheet)
UCA0BR1 = 0x00; // Hi byte
UCA0MCTL = UCBRS1 + UCBRS0; // Modulation UCBRSx = 3 (from datasheet)
// ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD
UCA0CTL1 &=~UCSWRST; // end of reset
rx_tail0=0;
rx_head0=0;
IE2 |= UCA0RXIE; // Enable USART0 RX interrupt
}
void CTB0(void) //clear transmitt buffer
{ __disable_interrupt();
tx_head0=tx_tail0=0;
__enable_interrupt();
}
void STB0(void) //send transmitt buffer
{ IFG2 |= UCA0TXIE;
}
void SendByteFromBuffer0(void)
{ char d;
if ((IFG2 & UCA0TXIFG) == 0)
return;
if (tx_tail0==tx_head0)
return;
d=tx_buf0[tx_tail0];
tx_tail0++;
if (tx_tail0>=TxBufSize0)
tx_tail0=0;
UCA0TXBUF = d;
}
void ATB0(char c) //add transmitt buffer
{
tx_buf0[tx_head0]=c;
tx_head0++;
if (tx_head0>=TxBufSize0) tx_head0=0;
}
void tx_isr0(void)
{
char d;
if (!(tx_tail0==tx_head0))
{ d=tx_buf0[tx_tail0];
tx_tail0++;
if (tx_tail0>=TxBufSize0)
tx_tail0=0;
UCA0TXBUF = d;
}
}
void rx_isr0(void)
{
rx_buf0[rx_head0]=UCA0RXBUF;
rx_head0++;
if (rx_head0>=RxBufSize0)
rx_head0=0;
}
char NextRxChar0(void)
{ char result;
if (rx_tail0==rx_head0)
result=0;
else
{ result=rx_buf0[rx_tail0];
rx_tail0++;
if (rx_tail0>=RxBufSize0)
rx_tail0=0;
}
return(result);
}