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.

MSP430 Launchpad USI SPI 3-wire interface help

Other Parts Discussed in Thread: MSP430G2231

Hi all, 

I am a beginner with MSP430 coding and having been combing the internet for help about USI SPI interface but have come up un-fulfilled. 

I am using the MSP430G2231 (launchpad) as the master and a digital potentiometer MAXLATE5386 as the slave (http://datasheet.octopart.com/MAX5386LATE%2B-Maxim-datasheet-8528562.pdf read page 8 of the datasheet for more info).  What I want to do is use the MSP430 to code the digital potentiometer's resistance.

The digital potentiometer supports 3-wire SPI interfacing so I need to use that.  I believe the MSP430G2231 has USI SPI interfacing.  My MSP430 needs to be initialized to run on my externally soldered microcrystal: SCLK.

Can someone point me to/give me some example code that shows me how to do all the USI SPI initialization?  I have seen some useful User Guides/Tutorials but I feel like they leave me confused and don't explain all the code snippets completely.  

Thanks, 

Kevin

p.s. feel free to add any advice/link me to anything that you think might help!!

  • Ok so I read a lot more about USI SPI for the MSP430 and I understand a lot more about it.  One major question though:

     

    Does the MSP430 Launchpad support *3 wire* SPI mode?

  • The naming '3 wire mode" is misleading.

    The full SPI consists of the following signals:

    SOMI (slave output to master input)
    SIMO (slave input form master output)
    SCL (serial clock)
    CS (slave chip select, one per slave except if the slaves are daisy-chained and act as one)

    Slaves may additionally provide a ready/interrupt signal output but this is outside SPI specification.

    Also, SOMI or SIMO may be missing, if the communication is always one-directional. (you can only read the slave, e.g. an ADC, or you can only write to the slave, e.g. a DAC)

    On the MSP, 3 wire mode (as this naming is used in the datasheets) refers to the standard as described above. CS is an outgoing GPIO signal and has to be controlled by software. It is required so select one of the (possibly many) slaves on the same SIMO/MOSI/SCL lines. It also indicates the start of a transmission and therefore synchronizes the slave input shift register and maybe even the higl-level protocol.

    A very odd variant of SPI is a combined SIOMIO line, where the data goes into two directions based on a slave-proprietary protocol. This is not supported by the MSP, you'll need to implement a software bit-banging algorithm to do this, or juggle heavily with the port configurations and synchronize this with the hardware transfers.

    4wire mode, however, is an extension of the hardware that does not have directly to do with the SPI protocol. in slave mode, the 4th pin deactivates the output pin and stops shifting in data based on the clock. In master mode it only makes sense if you have a multi-master setup. So the other master can put the SPI hardware into slave mode immediately. However, this pin alone won't help. The software needs to check for its state manually and reset the SPI hardware etc.

    The USI chip has a dedicated output and a dedicated input line, so it does not swap the data direction with the mode. So this addiitonal line does not make too much sense - the role of the chip (master/slave) is hardwired by the PCB and you cannot switch from one to the other (you'll have to cross the SOMI/SIMO lines if you want to swap the role). So this additional signal doesn't make too much sense. Also, the USI does not have double-bufferign of its transfer registers, so playing a role as SPI slave isn't an easy job (not recommended for beginners).

    However, if the above general explanation doesn't help you to answer your question yourself, I need to know what you mean with "3 wire SPI mode", as this naming is highly ambiguous.

  • My 3 wire is CS, a one way write only Data IN, and also a CLK. 

    I was wondering if someone can take a look at my code and tell me if you see any major problems (timing, initialization, etc?)

    My digital potentiometer actually needs 9 bits so I enable 16 bit shift register, write it to the digital pot with LSB but I write it backwards because the digital pot takes in data to its MSB.

    ***********************************************************************************************************************************************

     

    #include <msp430g2231.h>

    #include <intrinsics.h> // Intrinsic functions

    #include <stdint.h> // Integers of defined sizes

     

    #define nCS P1OUT_bit.P1OUT_4 // Output pin for _CS (active low)

     

    uint16_t TXdata = 0x1DB; // Received and transmitted data (arbitrary value 0x5A)

     

    //Pin 1.4 is SMCLK Output

    //Pin 1.5 is clock input/output in USI mode

    //Pin 1.6 is Data Output in USI SPI mode

    //USIIFG is the USI counter interrupt flag. Set when the USICNTx = 0. Automatically cleared if USICNTx is loaded with a

    //value > 0 when USIIFGCC = 0.

    //LSB to digital pot's MSB

     

    void main(void)

    {

      volatile unsigned int i;

      WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer

      P1OUT = ~BIT4; // nCS low (active)

      P1DIR = BIT4; // nCS output , others input

      USICNT = USI16B; // Use 16 bit shift register

      USICTL0 |= USIPE7 + USIPE6 + USIPE5 + USILSB + USIMST + USIOE; // Port, SPI master, (am I supposed to use LSB for one way 3-wire SPI master?)

      USICTL1 |= USIIE + USICKPH;           // Counter interrupt, flag remains set (Is this clock polarity correct?)

      USICKCTL = USIDIV_0 + USISSEL_1;      // Divide ACLK by 1 (I want to use external microcrystal as clock)

      USICTL0 &= ~USISWRST;                 // USI released for operation 

      USISRL = TXdata;                      // initially-load data

      USICNT = 9;

    }

    // USI interrupt service routine

    #pragma vector = USI_VECTOR

    __interrupt void USI_ISR (void)

    {

      P1OUT = BIT4; // Pull CS high

    }

     

  • Kevin,

    From the MSP430 LaunchPad Wiki page, you can download the MSP430G2xx1 Code Examples zip file slac463a.zip that contains several USI examples for SPI mode.

    i.e.
    msp430g2x21_usi_02.c              SPI full-Duplex 3-wire Master
    msp430g2x21_usi_03.c              SPI full-Duplex 3-wire Slave
    msp430g2x21_usi_04.c              USI SPI Interface with HC165/164 Shift Registers
    msp430g2x21_usi_05.c              USI SPI Interface to TLC549 8-bit ADC

    Dan

  • hi 

    can you share you working code and schematic for the digital pot?

    10x

**Attention** This is a public forum