Friday, January 27, 2012

123 UART Test for Launchpad and EZ430 RF2500T


The challenge was to connect a Launchpad and an EZ430 RF2500T board via UART interface. I had a Launchpad populated with an MSP430G2553 microcontroller that had the UART working to the PC with the USB cable. The plan was to connect the EZ430 as a daughter board on J4. An earlier blog post had shown that the configuration at least somewhat works. Today's post shows a 123 test to validate the UART between the RF430 and the Launchpad. The EZ430 RF device sends a 0,1,2 3 pattern to the Lauchpad which sets displays the number on the leds and echos back the sequence to the EZ430 RF which in turn receives the number and its leds display the echoed number. It is an easy visual way to verify that the UART communication link between the two devices is working.

Lessons Learned about the Launchpad daughter board connection for the EZ430 RF device

There are a couple different versions of the lauchpad developer board. Revision 1.4 and under require a jumper configuration change on J3 when using a device such as the MSPG2553 with a hardware UART. This is because these boards are wired for earlier 14 pin devices using a software UART. Here it is necessary to criss cross the RX and TX pins at J3 in order to use the hardware UART over the USB interface. Revision 1.5 and later have moved the RX and TX configuration on the board. This solves the issue of using the 20 pin devices with the hardware UART.

It should be noted also that the screen print on my rev 1.4 boards label pin 3 (P1.1) as TXD and pin 4 (P1.2) as RXD. This is fine for 14 pin devices when using software UART solutions, however, the g2553 UART uses pin 3 (P1.1) as RXD and pin 4 (P1.2) as TXD. As a result the J4 connector is wired backwards for using the hardware UART on the 20 pin G2553 devices. Therefore, it is necessary to connect the EZ430 RF device using jumper wires and the J4 connector is useless when hardware UART is used.

Code for the Lauchpad 123 UART test
Load the Launchpad 123 Test software onto a Launchpad that is populated with an g2553 device. Remove jumpers from J3 after programming the Launchpad.
//******************************************************************************
// UART TESTING CODE FOR Launchpad
//
// By M. Tellitocci
// Tellitronics Inc.
// January 2012
//
// Description: Perform a 123 test on the Launchpad and EZ430 RF2500T boards to verify UART operation.
// On the EZ430 RF board timer A triggers a transmission of test sequence
// 0x030, 0x031, 0x032, 0x033 which repeats and is transmitted
// by the EZ430 UART. The launchpad with a MSPG2553 Hardware UART
// receives the test sequence and toggles its leds in binary sequence.
// The launchpad echos back the test pattern and the LED's on the
// EZ430 RF2500T repeat the pattern.
// Built with CCS Version 4.2.0
//
// Companion code for the launchpad board is called echotest.
//
// This software sample code is provided for educational purposes only and
// the user assumes all risk of its use there is no warranty or support.
// It is provided as is for education and hobbyist experimentation.
//******************************************************************************
#include "msp430g2553.h"
char str[31];
unsigned int i;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;

P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1DIR = BIT6 + BIT0; // P1.6 and P1.0 outputs
P1OUT = BIT6+BIT0; // LEDs off
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)
{

if(UCA0RXBUF==0x030)
{
P1OUT=0;
UCA0TXBUF = 0x030;
}
else if (UCA0RXBUF==0x031)
{
P1OUT= BIT0;
UCA0TXBUF = 0x031;
}
else if (UCA0RXBUF==0x032)
{
P1OUT=BIT6;
UCA0TXBUF = 0x032;
}
else if (UCA0RXBUF==0x033)
{
P1OUT=BIT0+BIT6;
UCA0TXBUF = 0x033;
}

}

// USCI A0/B0 Transmit ISR
#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void)
{
UCA0TXBUF = str[i++]; // TX next character
}

Code for the EZ430 RF2500T dongle
Load an EZ430 RF2500T board with the test software using Code Composer. Remove the
EZ430 board and install on its battery board.
//******************************************************************************
// UART TESTING CODE FOR EZ430 RF2500T
//
// By M. Tellitocci
// Tellitronics Inc.
// January 2012
//
// Description: Timer A triggers a transmission of test sequence
// 0x030, 0x031, 0x032, 0x033 which repeats and is transmitted
// by the EZ430 UART. A launchpad with a MSPG2553 Hardware UART
// receives the test sequence and toggles its leds in binary sequence.
// The launchpad echos back the test pattern and the LED's on the
// EZ430 RF2500T repeat the pattern.
//
//
// Built with CCS Version 4.2.0
//
// Companion code for the launchpad board is called echotest.
//
// This software sample code is provided for educational purposes only and
// the user assumes all risk of its use there is no warranty or support.
// It is provided as is for education and hobbyist experimentation.
//******************************************************************************
#include "msp430.h"
#include "in430.h"
#include "msp430F2274.h"
unsigned int i=0;
unsigned int j=0;
int main ( void )
{
//- timer example code
WDTCTL = WDTPW + WDTHOLD;
P1DIR |= 0x03; // initialize led pins

// basic clock system control register 3
BCSCTL3 |= LFXT1S_2; // VLOCLK
TACCTL0 = CCIE; // Capture compare interupt enable
TACCR0 = 2000; // Timer A capture register value
TACTL = MC_1+TASSEL_1; // Up mode: the timer counts up to TACCR0. Clock srce ACLK.

BCSCTL1 = CALBC1_1MHZ; // Set DCO
DCOCTL = CALDCO_1MHZ;
P3SEL = 0x30; // P3.4,5 = USCI_A0 TXD/RXD
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 (GIE+LPM3_bits ) ;
}

#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
if (i==0)
{
UCA0TXBUF=0x030;
i++;
}
else if (i==1)
{
UCA0TXBUF=0x031;
i++;
}
else if (i==2)
{
UCA0TXBUF=0x032;
i++;
}
else if (i==3)
{
UCA0TXBUF=0x033;
i=0;
}
}

#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
if(UCA0RXBUF==0x030)
{ P1OUT=0x00;
}
else if (UCA0RXBUF==0x031)
{ P1OUT= 0x01;
}
else if (UCA0RXBUF==0x032)
{ P1OUT=0x02;
}
else if (UCA0RXBUF==0x033)
{ P1OUT=0x03;
}
//UCA0TXBUF=UCA0RXBUF;
}

// USCI A0/B0 Transmit ISR
#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void)
{
}

Hardware Setup

A male header was soldered on to the EZ430 battery board in order to easily access the RX, TX, VCC and GND connections.

The EZ430 battery pack is used to power both the launchpad and the EZ430.

Jumpers were connected between VCC on the Launchpad and EZ430 battery board, GND on the Launchpad and GND on the EZ430 battery board.

The UART is connected as follows:

Pin 3 (P1.1) on launchpad to pin 3.4 (TXD) on the EZ430.
Pin 4 (P1.2) on the launchpad to Pin 3.5 on the EZ430.

Remove all jumpers on J3 of the launchpad.

Once all the hardware connections are made and the battery jumper on the EZ430 in place the 123 UART test begins. The EZ430 transmits 0,1, 2 and 3. The Launchpad receives the byte and its leds display the binary number and the byte is echoed back to the EZ430. The EZ430 receives the byte and its leds display the received byte.

Coming soon is the code to enable the Launchpad to operate wirelessly.