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 CS

Other Parts Discussed in Thread: OMAP-L138, AM1808

Hello,

I've looking at the SPI documentation and at the StarterWare drivers for the SPI peripheral and have a doubt in terms of the CS value that is often used/passed in the functions. Does the CS stand for chip select? What is it determined to do?

Any feedback will be appreciated.

Thanks,

Michelle

  • Hi Michelle,

    Yes you are right. CS stands for Chip select. In AM335x TRM you will find SPIEN is mentioned. Even this has the same meaning.

    Regards,

    Jeethan

  • Hi Jeethan,

    Thank you for your reply. I am using the OMAP-L138. I was looking at the example and I noticed they give CS a value of 0x01, how is this value determined?

    Thanks,

    Michelle

  • Ok,

    So I see this in the code:

    /*

    ** Using the Chip Select(CS) 0 pin of SPI1 to communicate with SPI Flash.

    ** AM1808 EVM mandates us to do so.

    */

    SPI1CSPinMuxSetup(0);

     

    But I also see this:

    /* value to configure SMIO,SOMI,CLK and CS pin as functional pin */

    #define SIMO_SOMI_CLK_CS 0x00000E01

    static void SetUpSPI(void){

    unsigned char cs = 0x01;

    unsigned char dcs = 0x01;

    unsigned int val = SIMO_SOMI_CLK_CS;

    SPIReset(SOC_SPI_1_REGS);

    SPIOutOfReset(SOC_SPI_1_REGS);

    SPIModeConfigure(SOC_SPI_1_REGS, SPI_MASTER_MODE);

    SPIClkConfigure(SOC_SPI_1_REGS, 150000000, 20000000, SPI_DATA_FORMAT0);

    SPIPinControl(SOC_SPI_1_REGS, 0, 0, &val);

    SPIDefaultCSSet(SOC_SPI_1_REGS, dcs);

    /* Configures SPI Data Format Register */

    SPIConfigDataFmtReg(SPI_DATA_FORMAT0);

    /* Selects the SPI Data format register to used and Sets CSHOLD

    * to assert CS pin(line)

    */

    SPIDat1Config(SOC_SPI_1_REGS, (SPI_CSHOLD | SPI_DATA_FORMAT0), cs);

    /* map interrupts to interrupt line INT1 */

    SPIIntLevelSet(SOC_SPI_1_REGS, SPI_RECV_INTLVL | SPI_TRANSMIT_INTLVL);

    /* Enable SPI communication */

    SPIEnable(SOC_SPI_1_REGS);

    }

     

    So this is the value of 0x01 that I am referring to which is used in the setup.

     

  • The "SPI1CSPinMuxSetup(0)" call sets up the PINMUX for SPI1_SCS[0]. There should be SPIPinMuxSetup() call that sets up the PINMUX for the other SPI1 pins. This function is specific to the board where a 4-line SPI is used. SIMO, SOMI, CLK and CS are connected.

    The "SPIDat1Config(SOC_SPI_1_REGS, (SPI_CSHOLD | SPI_DATA_FORMAT0), cs)" call sets up format 0 on SPI1 to use just SCS[0]. All other SCS lines are not used. The cs value of 0x01 is a bitmask for SCS[0], ie. 0x01<<0. If required, more than one CS can be toggled. The pinmux functions are hard-coded to one CS.

    Hopefully I got that right. Might have misremembered.

  • "
    unsigned char cs = 0x01;
    ... ...

    SPIDat1Config(SOC_SPI_1_REGS, (SPI_CSHOLD | SPI_DATA_FORMAT0), cs);
    "

    It's not meens setup SCS[1] on SPI1, it's just means the value to driven on SCS[n] ("n" depend on the set in function "SPIPinControl()")
    See the function prototype "SPIDat1Config()" and "SPIPinControl()", I think it'll useful for you:


    void SPIPinControl(unsigned int baseAdd, unsigned int idx,
    unsigned int flag, unsigned int *val)
    {
      if (0 == flag)
      {
        HWREG(baseAdd + SPI_SPIPC(idx)) = *val;    //SPI chip select pin n was set at here
      }
      else
      {
        *val = HWREG(baseAdd + SPI_SPIPC(idx));
      }
    }


    void SPIDat1Config(unsigned int baseAdd, unsigned int flag, unsigned char cs)
    {
      unsigned char *ptr = (unsigned char*)(baseAdd + SPI_SPIDAT1);
      unsigned char dcs;

      *(ptr+3) = (char)((flag >> 24) | (flag & (SPI_SPIDAT1_DFSEL >>
        SPI_SPIDAT1_DFSEL_SHIFT)));

      dcs = HWREG(baseAdd + SPI_SPIDEF ) & (SPI_SPIDEF_CSDEF);

      *(ptr+2) = cs ^ dcs;    //It's just set the value of the SPIx_SCS[n] pin during a master data transfer.
    }