Showing posts with label MSP430. Show all posts
Showing posts with label MSP430. Show all posts

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.

Saturday, May 14, 2011

The WII Motion Plus Gyro







Now we return to the Quad Copter project picking up with the WII Motion Plus Gyro that will be used as a sensor. I picked one of these up from Amazon.Com for about 10.00 dollars and free shipping. It makes for an inexpensive 3-axis gyro that can be hacked for use in home-brewed electronics experiments. I have been researching the specifics of how to utilize this device. Most of the information I found indicated that the device can be easily polled by a microprocessor with an an I2C interface. The board inside the WII Motion Plus contains an I2C interface, 14 bit ADC and a 3-axis gyro. A lot in a cheap package. I will be getting into the technical aspects of the interface in a later post. This time I am simply going to describe the process of dismantling the Motion Plus to obtain the gyro. It was definitely designed so that it could not be easily unassembled. Two Y-bit screws on the back could not be removed with any of the tools that I have. I tried phillips and hex and square bits and then tried to drill the screws out. Even then the back would not come apart. I then tried to pry the shell apart, but found it was put together tightly and securely. As a result the outside shell was rendered useless by the time I got to the gyro. I feared that the circuitry would be damaged even though I was careful. In the end I managed to remove the gyro from the plastic case. Then I unsoldered the female pass-through port connector. This will allow me to make a cable with a female plug so that I can use the male connector that is attached to the gyro board. Later will begin experimenting with the hardware interface and making use of the data that the gyro provides.

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
}