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 interface MSP430G2432

Other Parts Discussed in Thread: MSP430G2432

Hello,

I'm using the MSP430G2432 as host controller for two SPI slaves. I have checked the entire Users guide and datasheets but I still haven't found out how to select the slave devices. Which pin (GPIO pin?) and how many pins should I use to send the chip select signal to the SPI slave devices?

Thanks!

 

 

 

 

 

 

 

  • The USI peripheral on the MSP430G2432 is implemented as a 3-wire SPI interface.  These 3 wires are CLK (SCLK), Data In (SDI) and Data Out (SDO).  There is no direct control over a pin to use a chip select.  Therefore you are free to use any GPIO for the chip select, however it will require software to control the SPI chip selects to the slave devices.

  • Thanks for your quick reply! Do I need for each SPI slave a GPIO pin?

     

  • Yue Zhang said:

    Thanks for your quick reply! Do I need for each SPI slave a GPIO pin?

    Yes, you would.

  • BrandonAzbell said:
    Do I need for each SPI slave a GPIO pin?

    It depends. In case of many SPI slave ICs you can save uC pins using 3to8 or 4to16 multiplexer/decoder logic IC.

  • Yue Zhang said:
    Do I need for each SPI slave a GPIO pin?

    That's the standard case.

    Some slaves can be cascaded. You only need one CS signal. The MISO (SDO) pin of oen is connected to the MOSI (SDI) pin of the next and you send commands for all three in a row, for the last in chain first, and get result from all three (form the last in chain first) before releasing CS and all three take the last command that passed them. This daiy-chaining is typical for simple devices such as ADC or DAC or digital pots.

    If you are only sending to the slaves and not getting an answer (no output from them), you may also select multiple slaves with on CS signal, sending to all of them in parallel then. A typical applicaiton are digital pots, where you want to always set them all the same.

    You can use a multiplexer to reduce the number of I/O pins required for a larger number of slaves. Well, this means external hardware, and at the end you still have one separate CS signal for each slave. Just not as many GPIO pins used :)

  • Thank you very much for your replies! Just for interest, can I use the three SPI pins for the one SPI slave device and two of them simultaneously as I2C pins for the other slave device? In this way, I would avoid the chip select problem because the slaves have different serial interfaces right?

     

  • Yue Zhang said:
    can I use the three SPI pins for the one SPI slave device and two of them simultaneously as I2C pins for the other slave device?

    Obviously no (because bus type differs).

    Yue Zhang said:
    I would avoid the chip select problem because the slaves have different serial interfaces right?

    Please define what actually you want to achieve and what kind of chip select "problem" you have?

  • Yue Zhang said:
    Just for interest, can I use the three SPI pins for the one SPI slave device and two of them simultaneously as I2C pins for the other slave device?

    In theory, yes.

    When not selected, the SPI slave(s) do not influence the I2C bus. And when an SPI slave is active, the I2C devices won't see a valid start byte and therefore remain passive too. As long as only one of the two buses is active at the same time, it could work. However, handling of error conditions could be tricky, especially if an I2C slave holds the bus low - you cannot just deactivate the I2C master and continue with SPI then.

    Yue Zhang said:
    , I would avoid the chip select problem because the slaves have different serial interfaces right?

    If this is the only reason, then don't do it. Just handle the chip selects properly. I'd only go for it if there's only one USCI left and you need both, SPI and I2C. As an emergency solution.

  • Jens-Michael Gross said:
    And when an SPI slave is active, the I2C devices won't see a valid start byte

    IMHO not always. What about more than 8 bit transfers when SPI peripheral phase and polarity configuration bits (have to be) set to 1? I think with right data i2c slave can "see" I2C start condition.

    Jens-Michael Gross said:
    I'd only go for it if there's only one USCI left and you need both, SPI and I2C. As an emergency solution.

    For hobby projects.

  • Ilmars said:
    IMHO not always.

    You're right, on certain polarity/phase combinations (and during port pin initialization or USCI (re)-initialization), the I2C slave could see a start condition. Howeve,r it is unlikely that it also will see its own valid address then. Either the data changes during SCL high, then it always does so, resulting in a series of start and stop conditions without valid slave address, or valid data is seen on the bus without a start condition.

    Only on initialization, both (SDA change during clock high, but then during clock low) can happen and then have to match the slave address too (or the general call address).

    YOu're right, I think such a case could be constructed. But isn't that likely. Hence my recommendation as 'emergency solution' only. But not only for hobby projects. I'll only definitely exclude this for medical applicaitons and such, but IIRC, there almost no MSP with medical approval at all.

  •  !!Please help!! 

    Ich want to read and write something from/to the RAM of my SPI slave device and make some further configurations to it. But I can't see any signal on the oscilloscop?! Most of my code is generated by Grace, only the lines in bold are written by me.

    #include <msp430g2432.h>

    extern void Grace_init(void);

    int main( void )
    {
    Grace_init(); // Activate Grace-generated configuration

    return (0);
    }

    void Grace_init(void)
    {
      WDTCTL = WDTPW | WDTHOLD;

     GPIO_graceInit();

     BCSplus_graceInit();

     USI_graceInit();

    // I have only picked out the relevant functions

    }

     void USI_graceInit(void)
    {

    USICTL0 |= USISWRST;

    USICTL0 = USIPE7 + USIPE6 + USIPE5 + USIMST + USIOE + USISWRST;

    USICTL1 = USICKPH + USIIE + USIIFG;

    USICKCTL = USIDIV_0 + USISSEL_2;

    USICTL0 &= ~USISWRST;

    /* USER CODE START (section: USI_graceInit_epilogue) */
    /* User code */

    /* Send 'inbyte' and receive byte via SPI interface*/

    SPISendReceiveByte(inbyte);

    /* USER CODE END (section: USI_graceInit_epilogue) */

    unsigned char SPISendReceiveByte(unsigned char inbyte)
    {

     USISRL = inbyte;          // Load byte to send in USI shift register
     USICNT |= 8;                 // Start to send 8 bits. USIIFG cleared 
     while(!(USICTL1 & USIIFG));            // Wait for all SPI bits to be sent

     return USISRL;                                    // Copy rx SPI byte
    }

    I don't have any compile mistakes, but my MCU just refuses to send any signal!!

    Thanks in advance!

     

     

     

     

     

     

     

  • Hi, my problem was that I havent used a while loop to see the signal :)

     

     

**Attention** This is a public forum