Friday, May 6, 2011

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
}

1 comment: