Currently I am working on a project which requries TX and RX share the same data line.
Thus, I connected UART TX with RX and start with a RX interrupt. However, when I send a message from PC and msp430 goes into RX interrrupt, msp430 transmit the message back immediately.
For example, with RX and TX connected together, I wrote a code that when msp430 receive a 0x31, it will return a 0x0D. However, the result I got is: I transmit a 0x31, I got 0x31 0x0D back.
Is that possible to stop TX function when TX and RX are connected together?
My code is attached. Many many thanks!
int main(void)
{
P1SEL = 0X06; // P1.1 = RXD, P1.2=TXD
P1SEL2 = 0X02; // P1.1 = RXD, P1.2=TXD
P1OUT = 0X00;
a=x=i=0;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
if (CALBC1_1MHZ==0xFF) // If calibration constant erased
{
while(1); // do not load, trap CPU!!
}
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 104; // 1MHz 9600
UCA0BR1 = 0; // 1MHz 9600
UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled
}
// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
Received[1] = UCA0RXBUF;
if(UCA0RXBUF == 0X31)
{
IE2 |= UCA0TXIE;
}
P1SEL = 0X04; // P1.1 = RXD, P1.2=TXD
P1SEL2 = 0X04; // P1.1 = RXD, P1.2=TXD
P1OUT = 0X00;
a++;
}
#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void)
{
//while (!(IFG2 & UCA0TXIFG));
UCA0TXBUF = 0x0D; // TX next character
__delay_cycles(5000);
IE2 &= ~UCA0TXIE; // Disable USCI_A0 TX interrupt
P1SEL = 0X02; // P1.1 = RXD, P1.2=TXD
P1SEL2 = 0X02; // P1.1 = RXD, P1.2=TXD
P1OUT = 0X00;
b++;
}