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.

MSP430G2121 SPI SDO and SDI

Other Parts Discussed in Thread: MSP430G2121

I am trying to create working SPI code for the MSP430G2121. I am referencing the example code provided by TI and using a logic analyzer to read the values on the MOSI and MISO lines. However, when I flash the code, the MOSI and MISO values are constantly 0x00 and 0xFF respectively.

Is there something I am missing in the setup?

msp430g2x21_usi_02.c
/* --COPYRIGHT--,BSD_EX
 * Copyright (c) 2012, Texas Instruments Incorporated
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *******************************************************************************
 * 
 *                       MSP430 CODE EXAMPLE DISCLAIMER
 *
 * MSP430 code examples are self-contained low-level programs that typically
 * demonstrate a single peripheral function or device feature in a highly
 * concise manner. For this the code may rely on the device's power-on default
 * register values and settings such as the clock configuration and care must
 * be taken when combining code from several examples to avoid potential side
 * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
 * for an API functional library-approach to peripheral configuration.
 *
 * --/COPYRIGHT--*/
//******************************************************************************
//  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
//
//  **** used with "msp430g2x21_usi_03.c"   ****
//
//                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 <msp430.h>


int 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_register(LPM0_bits + GIE);   // Enter LPM0 w/ interrupt
}

// USI interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USI_VECTOR
__interrupt void universal_serial_interface(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USI_VECTOR))) universal_serial_interface (void)
#else
#error Compiler not supported!
#endif
{
  if (0x10 & USISRL)
    P1OUT |= 0x01;
  else
    P1OUT &= ~0x01;
  USISRL = P1IN;
  USICNT = 8;                           // re-load counter
}

  • Nicholas,

    This example send over the logic level of P1.4 via SPI. Depending if you have P1.4 tied to GND or VCC, it will send over a "0" or "1".

    Regards,
    JH
  • So what we are trying to do is verify that our SPI is working, but we do not have a slave MSP430 to run this code with. Are we still able to send an SPI even though we are not connected to another device, or do we need to make modifications to the code in order to test the SPI functionality?
  • Nicholas,

    You should be able to see something without attaching another device. However, with the code present, you will only see a "0" or "1" depending on the state of P1.4. If you want to see something else on the line, then I suggest filling the transmit buffer with a more distinct hex code.

    Regards,
    JH
  • >Are we still able to send an SPI even though we are not connected to another device

    the software demo is for the master, so yes it will work without anything connected.
    if you send 0x55 you will get 4 quick pulses, it's pretty quick at a 62.5KHz clk rate so what kind of logic analyzer are you using?
    As it is now this code only sends the state of P1IN.

    change USISRL = P1IN; to USISRL = 0x55; if you want a known value.
     

  • The logic analyzer we are using is Saleae Logic Analyzer. Regardless of the USISRL value (P1IN or 0x55), we are still getting 0x00 across the MOSI.
  • Hi Nicholas!

    Where did you place your 0x55? At the beginning of the code?

    ...
    USICKCTL = USIDIV_4 + USISSEL_2;      // /16 SMCLK
    USICTL0 &= ~USISWRST;                 // USI released for operation
    USISRL = P1IN;                        // init-load data                   <== HERE?
    
    P1DIR |= 0x04;                        // Reset Slave
    P1DIR &= ~0x04;
    ...

    or at the end in the ISR?

    ...
    #error Compiler not supported!
    #endif
    {
      if (0x10 & USISRL)
        P1OUT |= 0x01;
      else
        P1OUT &= ~0x01;
      USISRL = P1IN;                        //                      <== HERE?
      USICNT = 8;                           // re-load counter
    }

    If you placed it at the beginning, then only one single 0x55 is sent and all following are not. If you place it inside the ISR, you will continuously see 0x55 (or any other value you type instead of P1IN).

    Dennis

  • Dennis,

    I placed the 0x55 at the end in the ISR, however, we continue to get 0x00 for our MOSI. I have also verified and checked that our MOSI pin is not connected to ground.
  • Ok, I figured out the issue. There was an issue with the MSP430G2121 we ordered. We tried a different one and now it works. I thank you and appreciate all your help.

**Attention** This is a public forum