Showing posts with label TI. Show all posts
Showing posts with label TI. Show all posts

Saturday, May 14, 2011

Wireless Launchpad with the EZ430 RF2500T

Recently, I experimented with the LaunchPad and the EZ430 RF2500T. I plugged an EZ430 RF2500T configured as an access point to the USB port on my laptop. I plugged another EZ430 RF on the J4 connector of the Launchpad. This device was configured as an End Device. On the Launchpad I used the 2231 micro controller and loaded a demo application from TI that reports status of tempature readings (LO, IN or HI).

The purpose of this experiment was to validate that the EZ430 RF2500T can be used for wireless communication with the LaunchPad.

With this setup I was able to wirelessly transmit the tempature status from the LaunchPad to the laptop. Using Hyperterminal I was able to view the data transmitted by the EZ430 RF2500T.

You can find the code for the EZ430 RF2500T access point and end device by downloading TI's EKG-Based Heart-Rate Monitor Implementation on the LaunchPad Value Line Development Kit Using the
MSP430G2452 MCU application demo source
. The code for the wireless devices will work right out of the box without modification. I used IAR Kickstart to load the access point and end-device projects on a pair of the EZ430 RF2500T's. Since I did not have the hardware setup for the Heart Rate monitor I loaded the TI demo code shown here on the LaunchPad just so that I could get some data to transmit for the test.

//***********************************************************
// Lab7.c Software UART
//
// SFB 10/2010
//***********************************************************

#include

#define TXD BIT1 // TXD on P1.1
#define RXD BIT2 // RXD on P1.2
#define Bitime 13*1 // 0x0D

unsigned int TXByte;
unsigned char BitCnt;

unsigned int TxHI[]={0x48,0x49,0x0A,0x08,0x08};
unsigned int TxLO[]={0x4C,0x4F,0x0A,0x08,0x08};
unsigned int TxIN[]={0x49,0x4E,0x0A,0x08,0x08};

volatile long tempRaw;
volatile long tempSet = 0;
volatile int i;

void FaultRoutine(void);
void ConfigWDT(void);
void ConfigClocks(void);
void ConfigPins(void);
void ConfigADC10(void);
void ConfigTimerA2(void);
void Transmit(void);

void main(void)
{
ConfigWDT();
ConfigClocks();
ConfigPins();
ConfigADC10();
ConfigTimerA2();

while(1)
{
_bis_SR_register(LPM3_bits + GIE); // turn on interrupts and LPM3

if (tempSet == 0)
{
tempSet = tempRaw; // Set reference temp
}
if (tempSet > tempRaw + 5) // test for lo
{
P1OUT = BIT6; // green LED on
P1OUT &= ~BIT0; // red LED off
for (i=0;i<5;i++)
{
TXByte = TxLO[i];
Transmit();
}
}
if (tempSet < tempRaw - 5) // test for hi
{
P1OUT = BIT0; // red LED on
P1OUT &= ~BIT6; // green LED off
for (i=0;i<5;i++)
{
TXByte = TxHI[i];
Transmit();
}
}
if (tempSet <= tempRaw + 2 & tempSet >= tempRaw - 2)
{ // test for in range
P1OUT &= ~(BIT0 + BIT6); // both LEDs off
for (i=0;i<5;i++)
{
TXByte = TxIN[i];
Transmit();
}
}
}
}

void ConfigWDT(void)
{
WDTCTL = WDT_ADLY_250; // <1 sec WDT interval
IE1 |= WDTIE; // Enable WDT interrupt
}

void ConfigClocks(void)
{
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
FaultRoutine(); // If calibration data is erased
// run FaultRoutine()
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
IFG1 &= ~OFIFG; // Clear OSCFault flag
BCSCTL2 = 0; // MCLK = DCO = SMCLK
}

void FaultRoutine(void)
{
P1OUT = BIT0; // P1.0 on (red LED)
while(1); // TRAP
}

void ConfigPins(void)
{
P1SEL |= TXD + RXD; // P1.1 & 2 TA0, rest GPIO
P1DIR = ~(BIT3 + RXD); // P1.3 input, other outputs
P1OUT = 0; // clear output pins
P2SEL = ~(BIT6 + BIT7); // P2.6 and 7 GPIO
P2DIR |= BIT6 + BIT7; // P1.6 and 7 outputs
P2OUT = 0; // clear output pins

}

void ConfigADC10(void)
{
ADC10CTL1 = INCH_10 + ADC10DIV_0; // Temp Sensor ADC10CLK
}

void ConfigTimerA2(void)
{
CCTL0 = OUT; // TXD Idle as Mark
TACTL = TASSEL_2 + MC_2 + ID_3; // SMCLK/8, continuos mode
}

// WDT interrupt service routine
#pragma vector=WDT_VECTOR
__interrupt void WDT(void)
{
ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON;
_delay_cycles(500); // Wait for ADC Ref to settle
ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
_delay_cycles(100);
ADC10CTL0 &= ~ENC; // Disable ADC conversion
ADC10CTL0 &= ~(REFON + ADC10ON); // Ref and ADC10 off
tempRaw = ADC10MEM; // Read conversion value
_bic_SR_register_on_exit(LPM3_bits); // Clr LPM3 bits from SR on exit
}

// Function Transmits Character from TXByte
void Transmit()
{
BitCnt = 0xA; // Load Bit counter, 8data + ST/SP
while (CCR0 != TAR) // Prevent async capture
CCR0 = TAR; // Current state of TA counter
CCR0 += Bitime; // Some time till first bit
TXByte |= 0x100; // Add mark stop bit to TXByte
TXByte = TXByte << 1; // Add space start bit
CCTL0 = CCIS0 + OUTMOD0 + CCIE; // TXD = mark = idle
while ( CCTL0 & CCIE ); // Wait for TX completion
}

// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
CCR0 += Bitime; // Add Offset to CCR0
if (CCTL0 & CCIS0) // TX on CCI0B?
{
if ( BitCnt == 0)
{
CCTL0 &= ~ CCIE ; // All bits TXed, disable interrupt
}

else
{
CCTL0 |= OUTMOD2; // TX Space
if (TXByte & 0x01)
CCTL0 &= ~ OUTMOD2; // TX Mark
TXByte = TXByte >> 1;
BitCnt --;
}
}
}

This experiment was a success. Some day I will try the EKG Heart rate demo if I can put together the hardware or obtain the demo board at a reasonable price.

Friday, May 6, 2011

Attaching an EZ430 RF target board to the Launch Pad

The Launch Pad development board provides unpopulated pads for adding a header so that a target board such as the EZ430 RF board can be attached to it. To connect one of the ez430 targets, connector J4 must be populated with a 0.050-in (1.27-mm) pitch male header, as shown in Figure 4, to connect the target boards. The part number for the header is Mill-Max 850-10-006-20-001000. I had a relatively hard time finding the header so I asked Mill Max for free samples and they graciously sent me a few. I would not normally ask for samples but in this case I could not find the header part. The manufacturer's will usually oblige requests if you are not greedy.


The header for J4 is very small and with the 0.05 in pitch it presented a challenge for my rusty soldering skills. One of the images shows the header part beside a ruler. I is a little over 1/2 an inch. The pads on J4 are close together on the Launch Pad. My hand shakes a lot more than it did when I was a youngster, but I was successful in soldering the connector to the Launch Pad. The target board was installed and all came up without a problem.



The EZ430 RF2500T target board is about 1 inch in length with an onboard chip antennae. In testing with my daughter we were able to maintain a connection outdoors for at least half a foot ball field distance. In my next post I hope to be able to share the results of experimenting with this setup to allow the two boards to talk to one another.







Two Launchpad SPI experiment


I began experimenting last night with the SPI module of the MSP430 mcu's on the launchpad. The experiment involved connecting two launchpad's together with a full-duplex SPI interface. One launchpad was configured as a master and the other as a slave. Full duplex communicationg between the two boards exists allowing both the master and the slave to send data simultaneously. When the switch on on either board is pressed the value on the io port is transmitted to the other device causing the led to light up. I soldered the male headers that came with the Launchpad board on to two of the kits so that I could get easy access to the processor pins. SPI is serial peripheral interface. You can find more about SPI at wikipedia. This is relatively easy to set up and play with. Nothing but four wires between the launchpads was required. The wiring schematic is shown below along with the code for the master and slave. The source code came from the TI code samples that were downloaded from their website. A couple of minor adjustments had to be made for the launch pad hardware to work primarily to use the push-button switch that is connected on P1.3. No pull up resisters were used in the experiment.

Though this is a simple experiment it provided an opportunity to learn how to use the Code Composer Studio tool to program the launchpads. Additionally, it helped to learn more about how to use the MSP430 SPI module. This is the beginning step in developing code to allow a launch pad to communicate with a EZ430 wire less RF target board that will be piggybacked on the lauchpad for wireless capability.

//******************************************************************************
// MSP430G2xx2 Demo - SPI full-Duplex 3-wire Slave
//
// Description: SPI Master communicates full-duplex with SPI Slave using
// 3-wire mode. The level on P1.3 is TX'ed and RX'ed to P1.0.
// Master will pulse slave reset for synch start.
// ACLK = n/a, MCLK = SMCLK = Default DCO
//
// D. Dang
// Texas Instruments Inc.
// December 2010
// Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//******************************************************************************

#include


void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1OUT = 0x08; // P1.3 set, else reset-Modification for LP
P1REN = 0x08; // P1.3 pullup- modified for LP
P1DIR = 0x01; // P1.0 output, else input
USICTL0 = USIPE7 + USIPE6 + USIPE5 + USIOE; // Port, SPI slave
USICTL1 = USIIE; // Counter interrupt, flag remains set
USICTL0 &= ~USISWRST; // USI released for operation
USISRL = P1IN; // init-load data
USICNT = 8; // init-load counter

_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}

// USI interrupt service routine
#pragma vector=USI_VECTOR
__interrupt void universal_serial_interface(void)
{
if (0x08 & USISRL) // Modified for Launch Pad
P1OUT = 0x01;
else
P1OUT &= ~0x01;
USISRL = P1IN;
USICNT = 8; // re-load counter
}

//******************************************************************************
// MSP430G2x21/G2x31 Demo - SPI full-Duplex 3-wire Master
//
// Description: SPI Master communicates full-duplex with SPI Slave using
// 3-wire mode. The level on P1.4 is TX'ed and RX'ed to P1.0.
// Master will pulse slave reset for synch start.
// ACLK = n/a, MCLK = SMCLK = Default DCO
// D. Dang
// Texas Instruments Inc.
// October 2010
// Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//******************************************************************************

#include


void main(void)
{
volatile unsigned int i;

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1OUT = 0x08; // P1.3 set, else reset - modified for LP
P1REN = 0x08; // P1.3 pullup - modified for LP
P1DIR = 0x01; // P1.0 output, else input
USICTL0 = USIPE7 + USIPE6 + USIPE5 + USIMST + USIOE; // Port, SPI master
USICTL1 = USIIE; // Counter interrupt, flag remains set
USICKCTL = USIDIV_4 + USISSEL_2; // /16 SMCLK
USICTL0 &= ~USISWRST; // USI released for operation
USISRL = P1IN; // init-load data

P1DIR = 0x08; // Reset Slave
P1DIR &= ~0x08;
for (i = 0xFFF; i > 0; i--); // Time for slave to ready
USICNT = 8; // init-load counter
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}

// USI interrupt service routine
#pragma vector=USI_VECTOR
__interrupt void universal_serial_interface(void)
{
if (0x08 & USISRL) // modified for Launch pad
P1OUT = 0x01;
else
P1OUT &= ~0x01;
USISRL = P1IN;
USICNT = 8; // re-load counter
}