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.

Help configuring McSpi as Slave



Hi, All

Please i need help configuring the McSpi driver as salve device.

  • Do you mean "slave device"?

    Can you state what device you are using and what version of CCS, BIOS, PSP and other software components you are using?

  • Yes, Slave device.

    I am using CCS 4.2.2, pspdrivers_02_20_01_00. Mu device is DM8148.

    I need to configure SPI0 as slave device.

  • Mohamed Osama,

    If you refer the section 6.2 of the release note, it clearly saya that the McSPI slave mode of operation is not tested. But the implementation is there.

    If you stil want to continue, then let me know. 

    Thanks and Regards,

    Sandeep K

  • Hi Sandeep,

     

    Yes, please if  you have the implementation for Slave configuration, i need it.

     

    Thank you in advance.

  • Mohamed,

    The support for McSPI slave mode is already available in the driver. Only thing you have to do is, configuring the driver in slave mode while creating the device in the .cfg file of the application, which look like,

    ============================================================================================

    /* Configure the  SPI module                                                  */
    Mcspi.edmaEnable = true;

    /* configure the SPI parameters  */

    var mcspiPrms = new Mcspi.Params();
    mcspiPrms.instNum    = 0;
    mcspiPrms.opMode     = Mcspi.OpMode_DMAINTERRUPT;
    mcspiPrms.hwiNumber  = 7;
    mcspiPrms.enableCache= true;
    mcspiPrms.edma3EventQueue = 0;

    mcspiPrms.spiHWCfgData.masterOrSlave           = Mcspi.CommMode_SLAVE;  
    mcspiPrms.spiHWCfgData.singleOrMultiChEnable        = Mcspi.SINGLE_CHANNEL;  
    mcspiPrms.spiHWCfgData.pinOpModes           = Mcspi.PinOpMode_4PIN;
    mcspiPrms.spiHWCfgData.fifoRxTrigLvl                         = 1;
    mcspiPrms.spiHWCfgData.fifoTxTrigLvl                         = 1;

    mcspiPrms.spiHWCfgData.configChfmt[0].charLength             = Mcspi.LEN_8BIT;
    mcspiPrms.spiHWCfgData.configChfmt[0].multiWordAccessEnable  = false;
    mcspiPrms.spiHWCfgData.configChfmt[0].spiChipSelectEnablePol = false;
    mcspiPrms.spiHWCfgData.configChfmt[0].clockMode              = Mcspi.mode0;
    mcspiPrms.spiHWCfgData.configChfmt[0].clockRatioExtension    = 0;
    mcspiPrms.spiHWCfgData.configChfmt[0].spiWordInitDelay       = Mcspi.NO_DELAY;
    mcspiPrms.spiHWCfgData.configChfmt[0].trasmitReceiveMode     = Mcspi.Both_RxTx;
    mcspiPrms.spiHWCfgData.configChfmt[0].granularityEnable      = false;
    mcspiPrms.spiHWCfgData.configChfmt[0].busFreq                = 0;
    mcspiPrms.spiHWCfgData.configChfmt[0].spienHighPolarity      = false;
    mcspiPrms.spiHWCfgData.configChfmt[0].slaveModeChipSelect    = Mcspi.SPIEN_0;
    /* The dat0 and dat1 has to be set appropriately according to the EVM connection */
    mcspiPrms.spiHWCfgData.configChfmt[0].spiDat0Dir             = Mcspi.OUT;
    mcspiPrms.spiHWCfgData.configChfmt[0].spiDat1Dir             = Mcspi.IN;

    mcspiPrms.prcmHandle = null;

    var mcspi1 = Mcspi.create(mcspiPrms);
    DriverTable.addMeta("/mcspi0", mcspi0);

    ====================================================================================================

    Can you please explain your use case?

    Thanks and Regards,

    Sandeep K

     

  • Hi again,

    please help, what is the clockMode and what its values mean mode0, mode1, mode2 and mode3.

    And how can i set the polarity and phase of the clock?

  • Hi,

    Please find the clock mode configurations,

    Polarity  (POL)

    PHASE (PHA)

    SPI Mode

    Comment

    0

    0

    Mode0

    SPICLK active high and sampling occurs on the rising edge

    0

    1

    Mode1

    SPICLK active high and sampling occurs on the falling edge

    1

    0

    Mode2

    SPICLK active low and sampling occurs on the falling edge

    1

    1

    Mode3

    SPICLK active low and sampling occurs on the rising edge

     

    Thanks and Regards,

    Sandeep K

  • Have you tried with mode other than 0?

    Trying to use SPI1 as slave, setting mode 3 it works like in mode 0.

    Checking register values:

        // Check current configuration spi1.chan0
        CSL_McspiRegsOvly  spiCtrl = (CSL_McspiRegsOvly)CSL_MCSPI_1_REGS;
        regVal = spiCtrl->CHANNEL[0].CHCONF;

    we have other parameters set, but POL=0 and PHA=0 !?

    So we "hacked" it to using

        spiCtrl->CHANNEL[0].CHCONF = regVal | (Uint32)0x00000001;

    and mode changed. Why it was necessary?

    (biospsp_03_10_06_00)

    The other problem is when we tried to use

    ...charLength             = Mcspi_LEN_32BIT;

    It receives data, but in the buffer for each sample there are only fist bytes of words.

    (register values for SPI1 about charLen is checked as correct)

    What else is necessary to change to receive full 32 bits ?

    Best regards,

    Gentcho Nikolov

  • Hi Gentcho Nikolov,

    Gentcho Nikolov-XID said:

    Trying to use SPI1 as slave, setting mode 3 it works like in mode 0.

    Checking register values:

        // Check current configuration spi1.chan0
        CSL_McspiRegsOvly  spiCtrl = (CSL_McspiRegsOvly)CSL_MCSPI_1_REGS;
        regVal = spiCtrl->CHANNEL[0].CHCONF;

    we have other parameters set, but POL=0 and PHA=0 !?

    So we "hacked" it to using

        spiCtrl->CHANNEL[0].CHCONF = regVal | (Uint32)0x00000001;

    and mode changed. Why it was necessary?

    Please replace the below code at the line number 2486 in Mcspi.c file (inside the function "mcspiChannelConf()"). This was a bug and we fixed it recently.

    ==============================================================================================

        if(Mcspi_Both_RxTx == chanHandle->configChfmt.trasmitReceiveMode)
        {
         /* Since compiler will throw away the code of ORing with 0x00, just
          * make sure that TRM bits are cleared first and then Or it with the
          * required value 
          */
      tempConfReg1 &= ~CSL_MCSPI_CHCONF_TRM_MASK;
            tempConfReg1 |= ((CSL_MCSPI_CHCONF_TRM_TX_RX_MODE) \
                           << (CSL_MCSPI_CHCONF_TRM_SHIFT));
        }

    =====================================================================================================

    Gentcho Nikolov-XID said:

    The other problem is when we tried to use

    ...charLength             = Mcspi_LEN_32BIT;

    It receives data, but in the buffer for each sample there are only fist bytes of words.

    (register values for SPI1 about charLen is checked as correct)

    What else is necessary to change to receive full 32 bits ?

    Have you configured Mcspi to work in DMA mode? Because slave mode is supported only if the mcspi configured to work in DMA mode.

    If you are working in DMA mode, then can you please mention the number of bytes expected at the slave end?

    Regards,

    Sandeep

  • Hi Sandeep Krishnaswamy,

    Proposed patch as general is useful, but It doesn't fix setting of correct clock mode (polarity/phase).

    Look at Mcspi.c
    Fragment starting line 2249 up to line 2283 is responsible for setting of phase/polarity
            /* write 'clock mode' value to MCSPI_CH(chanNum)CONF[PHA & POL];      */
            switch(chanHandle->configChfmt.clockMode)
                case Mcspi_mode0:
    ....
                case Mcspi_mode1:
    ....
                case Mcspi_mode2:
    ....
                case Mcspi_mode3:
            }

    It is valid for both master and slave modes, but is included in the next if():
    line 2243
        /* Channel configuration setup - MCSPI_CH(i)CONF                          */
        if(Mcspi_CommMode_MASTER == instHandle->spiHWconfig.masterOrSlave)
        {
    ...
        }
    So, moving this switch() outside of the if() - before it to become valid for slave mode too, clock mode is set and I receive OK.

    Best regards,

    Gentcho Nikolov