This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SPI EXAMPLE problem in msp430g2231

Other Parts Discussed in Thread: MSP430G2221

//******************************************************************************
//  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
//
//                Slave                      Master
//             MSP430G2x21/G2x31          MSP430G2x21/G2x31
//             -----------------          -----------------
//            |              XIN|-    /|\|              XIN|-
//            |                 |      | |                 |
//            |             XOUT|-     --|RST          XOUT|-
//            |                 | /|\    |                 |
//            |          RST/NMI|--+<----|P1.2             |
//      LED <-|P1.0             |        |             P1.4|<-
//          ->|P1.4             |        |             P1.0|-> LED
//            |         SDI/P1.7|<-------|P1.6/SDO         |
//            |         SDO/P1.6|------->|P1.7/SDI         |
//            |        SCLK/P1.5|<-------|P1.5/SCLK        |
//
//  D. Dang
//  Texas Instruments Inc.
//  October 2010
//  Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//******************************************************************************

#include <msp430g2221.h>


void main(void)
{
  volatile unsigned int i;

  WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
  P1OUT =  0x10;                        // P1.4 set, else reset
  P1REN |= 0x10;                        // P1.4 pullup
  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 |= 0x04;                        // Reset Slave
  P1DIR &= ~0x04;
  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 (0x10 & USISRL)
    P1OUT |= 0x01;
  else
    P1OUT &= ~0x01;
  USISRL = P1IN;
  USICNT = 8;                           // re-load counter
}

hi all i found this example from net.. i  don t know how should i check this example.. that is  whether i should load this program to master as well as slave or else master alone.. then where should i give the input and how can i check whether the serial communication working or not..kindly help me any one am new to this controller??? thanks in advance

  • karthik raja said:
    i should load this program to master as well as slave or else master alone

    karthik raja said:
    MSP430G2x21/G2x31 Demo - SPI full-Duplex 3-wire Master
    (...)

    karthik raja said:
    then where should i give the input

    This code continuously sends teh content of P1IN register (whcih is sort of stupid as P1IN includes the current LED output, the slave CS pin etc.

    karthik raja said:
    how can i check whether the serial communication working or not

    In the slave, with a scope with protocol analyzer, well, and any other means.
    What is the difference whether the communication is working or not if it doesn't serve a purpose. And if it does serve a purpose the fact that it serves a purpose confirms that it is working.
    If a tree fall in the forest and nobody is near to hear it, does it still make a noise? And does it make difference whether it amkes a noise or not?

    (sorry, I feel a bit philosophical at the moment)

    In other words: you need some sort of slave (even if it is a bus protocol analyzer and not a slave device). Without someone listening, well, there's no way to see whether it makes a noise.

**Attention** This is a public forum