# MSP430F2013 UART with Timer\_A

**URL:** <https://community.sparkfun.com/t/msp430f2013-uart-with-timer-a/5667>\
**Category:** MicroMod\
**Tags:** msp\
**Created:** [November 4, 2007, 10:08pm UTC](https://community.sparkfun.com/t/msp430f2013-uart-with-timer-a/5667 "2007-11-04T22:08:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamhuzhe](https://avatars.discourse-cdn.com/v4/letter/i/cab0a1/32.png) [@iamhuzhe](https://community.sparkfun.com/u/iamhuzhe)\
**Post date:** [November 4, 2007, 10:08pm UTC](https://community.sparkfun.com/t/msp430f2013-uart-with-timer-a/5667/1 "2007-11-04T22:08:33Z")

</div>

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](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.
