MSP430F2013 UART with Timer_A

MSP430F2013 doesn’t have UART (serial comm.) directly.

I tried to follow the C sample code file: “msp430x20x3_ta_uart2400.c” (http://www-s.ti.com/sc/techzip/SLAC080.zip) to set up UART with Timer_A IRS.

Unfortunately, I had to use P1.5 as RXD and P1.6 as TXD. Following is my half success trial.

(Only listed changes made to the original code)

#define TXD 0x40 // TXD on P1.6

#define RXD 0x20 // RXD on P1.5

// 57600 baud rate, SMCLK = 16 MHz

#define Bitime_5 139

#define Bitime 278

BCSCTL1 = CALBC1_16MHZ; // set DCO 16MHz

DCOCTL = CALDCO_16MHZ;

CCTL1 = OUT; // TXD Idle as Mark

TACTL = TASSEL_2 + MC_2; // SMCLK, continuous mode

P1SEL = TXD + RXD;

P1DIR = TXD; // not sure if this is correct

_EINT();

//

void RX_Ready (void)

{

BitCnt = 0x8; // Load Bit counter

CCTL0 = CCIS_1+ SCS + OUTMOD0 + CM1 + CAP + CCIE;

}

#pragma vector=TIMERA0_VECTOR

__interrupt void Timer_A (void)

{

CCR0 += Bitime;

// RX

if( CCTL0 & CAP ) // Capture mode = start bit edge

{

CCTL0 &= ~ CAP; // Switch from capture to compare mode

CCR0 += Bitime_5;

}

else

{

if (CCTL0 & SCCI) // Get bit waiting in receive latch

RXTXData |= 0x80;

RXTXData = RXTXData >> 1;

BitCnt --; // All bits RXed?

if ( BitCnt == 0)

{

CCTL0 &= ~ CCIE; // All bits RXed, disable interrupt

}

}

My RX function works after correcting the original code. My TX function doesn’t, though I’ve added another ISR (with TAIV) for CCR1.

For a new bie, it is really not very easy to use this chip. Please help.