Other Parts Discussed in Thread: MSP-EXP430G2ET
Tool/software: Code Composer Studio
You are about to read the ADC0 value by connecting the RF430FRL152H patch to MSP-EXP430G2ET + TRF7970ABP.
I'm going to write the following code.
Where should I add printf?
#include <msp430.h>
#define RXD 0x02 // RXD on P1.1
#define TXD 0x20 // TXD on P1.5
#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)
{
BitCnt = 0xA; // Load Bit counter, 8data + ST/SP
while (TA0CCR0 != TA0R) // Prevent async capture
TA0CCR0 = TA0R; // Current state of TA counter
TA0CCR0 += Bitime; // Some time till first bit
RXTXData |= 0x100; // Add mark stop bit to RXTXData
RXTXData = RXTXData << 1; // Add space start bit
TA0CCTL0 = CCIS0 + OUTMOD0 + CCIE; // TXD = mark = idle
while ( TA0CCTL0 & CCIE ); // Wait for TX completion
}
void RX_Ready (void)
{
BitCnt = 0x8; // Load Bit counter
TA0CCTL0 = SCS + OUTMOD0 + CM1 + CAP + CCIE; // Sync, Neg Edge, Cap
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) Timer_A (void)
#else
#error Compiler not supported!
#endif
{
TA0CCR0 += Bitime; // Add Offset to CCR0
// TX
if (TA0CCTL0 & CCIS0) // TX on CCI0B?
{
if ( BitCnt == 0)
TA0CCTL0 &= ~ CCIE; // All bits TXed, disable interrupt
else
{
TA0CCTL0 |= OUTMOD2; // TX Space
if (RXTXData & 0x01)
TA0CCTL0 &= ~ OUTMOD2; // TX Mark
RXTXData = RXTXData >> 1;
BitCnt --;
}
}
// RX
else
{
if( TA0CCTL0 & CAP ) // Capture mode = start bit edge
{
TA0CCTL0 &= ~ CAP; // Switch from capture to compare mode
TA0CCR0 += Bitime_5;
}
else
{
RXTXData = RXTXData >> 1;
if (TA0CCTL0 & SCCI) // Get bit waiting in receive latch
RXTXData |= 0x80;
BitCnt --; // All bits RXed?
if ( BitCnt == 0)
//>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
{
TA0CCTL0 &= ~ CCIE; // All bits RXed, disable interrupt
__bic_SR_register_on_exit(LPM3_bits); // Clear LPM3 bits from 0(SR)
}
//>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
}
}
int main (void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
TA0CCTL0 = OUT; // TXD Idle as Mark
TA0CTL = TASSEL_1 + MC_2; // ACLK, continuous mode
P1SEL0 = TXD + RXD; //
P1DIR = TXD; //
// Mainloop
for (;;)
{
RX_Ready(); // UART ready to RX one Byte
__bis_SR_register(LPM3_bits + GIE); // Enter LPM3 w/ interr until char RXed
TX_Byte(); // TX Back RXed Byte Received
}
}