Hello everyone,
In the code below, the debug cursor is stuck on the line TX_Byte; it doesn't enter the function. Why so?
Krishna.
______________________________________________________________________________________________________________
#define RXD 0x02 // RXD on P1.1
#define TXD 0x20 // TXD on P1.5
// Conditions for 2400 Baud SW UART, ACLK = 32768
#define Bitime_5 0x06 // ~ 0.5 bit length + small adjustment
#define Bitime 0x0E // 427us bit length ~ 2341 baud
unsigned int RXTXData;
unsigned char BitCnt;
void TX_Byte (void);
void RX_Ready (void);
// M. Buccini / L. Westlund
// Texas Instruments Inc.
// October 2005
// Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.40A
//******************************************************************************
//#include <msp430x20x3.h>
#include <intrinsics.h>
#include <msp430xG46x.h>
void main (void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
TACCTL0 = OUT; // TXD Idle as Mark
TACTL = TASSEL_1 + MC_2; // ACLK, continuous mode
P2SEL = TXD + RXD; //
P2DIR = TXD; //
// Mainloop
for (;;)
{
RX_Ready(); // UART ready to RX one Byte
_BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/ interr until char RXed
TX_Byte(); // TX Back RXed Byte Received
}
}
// Function Transmits Character from RXTXData Buffer
void TX_Byte (void)
{
BitCnt = 0xA; // Load Bit counter, 8data + ST/SPo
//while (TAR != TACCR0); // Prevent async capture
TACCR0 = TAR; // Current state of TA counter
TACCR0 += Bitime; // Some time till first bit
RXTXData |= 0x100; // Add mark stop bit to RXTXData
RXTXData = RXTXData << 1; // Add space start bit
TACCTL0 = CCIS0 + OUTMOD0 + CCIE; // TXD = mark = idle
while ( TACCTL0 & CCIE ); // Wait for TX completion
}
// Function Readies UART to Receive Character into RXTXData Buffer
void RX_Ready (void)
{
BitCnt = 0x8; // Load Bit counter
TACCTL0 = SCS + OUTMOD0 + CM1 + CAP + CCIE; // Sync, Neg Edge, Cap
}
// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
TACCR0 += Bitime; // Add Offset to CCR0
// TX
if (TACCTL0 & CCIS0) // TX on CCI0B?
{
if ( BitCnt == 0)
TACCTL0 &= ~ CCIE; // All bits TXed, disable interrupt
else
{
TACCTL0 |= OUTMOD2; // TX Space
if (RXTXData & 0x01)
TACCTL0 &= ~ OUTMOD2; // TX Mark
RXTXData = RXTXData >> 1;
BitCnt --;
}
}
// RX
else
{
if( TACCTL0 & CAP ) // Capture mode = start bit edge
{
TACCTL0 &= ~ CAP; // Switch from capture to compare mode
TACCR0 += Bitime_5;
}
else
{
RXTXData = RXTXData >> 1;
if (TACCTL0 & SCCI) // Get bit waiting in receive latch
RXTXData |= 0x80;
BitCnt --; // All bits RXed?
if ( BitCnt == 0)
//>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
{
TACCTL0 &= ~ CCIE; // All bits RXed, disable interrupt
_BIC_SR_IRQ(LPM3_bits); // Clear LPM3 bits from 0(SR)
}
//>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
}
}