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 (wait for the slave to be ready)

Other Parts Discussed in Thread: CC2500

Hi all:

From the code example supplied by TI, a line of code reads:

 

while (P3IN&SOMI);        //Wait for slave ready

 

Basically, P3IN is the input register of port 3 and SOMI is pin 2 of port 3 (0x04), how does this line of code realize this idea of "wait for slave ready?"

 

Thank you

  • while (P3IN&SOMI); 

    can be translated as "if SOMI is high stay in this infinite loop."

    I have this feeling that what we try to say here is: if there is no signal at SOMI, that means the slave is ready?

    Am I getting this right?

    Thank you

  • Yu,

    Conceptually I understand what you are saying, but there are two problems:

    1. If you are polling the slave this indicator will not work in true SPI communication unless you use that SOMI pin on the slave side as a GPIO... I think that is what you are trying to do: use that pin as an indicator.

    2. The acronym "SOMI" is not defined in the MSP430 headers. I am assuming you are defining that to be a logical high for the MSP430 pin associated with SOMI on the master side.

    If the above are taken care of it sounds good to me.

  • Thank you for your reply Brandon.

    You are exactly right. I did not write that code myself, that was from MCU_CC2500 interface code example from TI. The original codes are:

     

    void TI_CC_SPIWriteReg(char addr, char value)
    {
        TI_CC_CSn_PxOUT &= ~TI_CC_CSn_PIN;                                                       // /CS enable
        while (TI_CC_SPI_USCIB0_PxIN&TI_CC_SPI_USCIB0_SOMI);                   // Wait for CCxxxx ready
        IFG2 &= ~UCB0RXIFG;                                                                                            // Clear flag
        UCB0TXBUF = addr;                                                                                                // Send address
        while (!(IFG2&UCB0RXIFG));                                                                                 // Wait for TX to finish
        IFG2 &= ~UCB0RXIFG;                                                                                            // Clear flag
        UCB0TXBUF = value;                                                                                               // Send data
        while (!(IFG2&UCB0RXIFG));                                                                                  // Wait for TX to finish
        TI_CC_CSn_PxOUT |= TI_CC_CSn_PIN;                                                           // /CS disable
    }

     

    I created my own header and used my own simplified naming conventions. TI_CC_SPI_USCIB0_SOMI happens to be a general purpose Input and Output on CC2500.

    Say, what would you do to make sure that the slave is ready?

    Thank you

     

  • Hi all:

    I FINALLY found the answer. We have to wait unitl SO pin to go low after CSn pin is pulled low (active low). As suggested in the CC2500 datasheet.

     

    Thank you all

  • My program hang in

    while (TI_CC_SPI_USI_PxIN&TI_CC_SPI_USI_SOMI);// Wait for CCxxxx ready

    and SOMI pin is high. Does someboby meet this problem?

     

    void TI_CC_SPIWriteReg(char addr, char value)
    {
      TI_CC_CSn_PxOUT &= ~TI_CC_CSn_PIN;        // /CS enable
      while (TI_CC_SPI_USI_PxIN&TI_CC_SPI_USI_SOMI);// Wait for CCxxxx ready
      USISRL = addr;                            // Load address
      USICNT = 8;                               // Send it
      while (!(USICTL1&USIIFG));                // Wait for TX to finish
      USISRL = value;                           // Load value
      USICNT = 8;                               // Send it
      while (!(USICTL1&USIIFG));                // Wait for TX to finish
      TI_CC_CSn_PxOUT |= TI_CC_CSn_PIN;         // /CS disable
    }

     

**Attention** This is a public forum