AnsweredAssumed Answered

How to change Chip Select of SPI during runtime?

Question asked by Michael Koller on Aug 2, 2016
Latest reply on Aug 2, 2016 by xiangjun.rong

Hey there!

 

I have used the SPI0 module on my K64F to read sensor date with success. I also tried the different Chip Selects of that module (PCs0,1,2,4 for each sensor in this case).

 

My problem occurs when I configure the Port for the additional PCs like this:

    PORT_HAL_SetMuxMode(PORTD,3u,kPortMuxAlt2);

    PORT_HAL_SetMuxMode(PORTD,1u,kPortMuxAlt2);

    PORT_HAL_SetMuxMode(PORTD,2u,kPortMuxAlt2);

    PORT_HAL_SetMuxMode(PORTD,0u,kPortMuxAlt2); //ptdo: spi0_pcs0

    PORT_HAL_SetMuxMode(PORTC,2u,kPortMuxAlt2); //ptc2: spi0_pcs2

    PORT_HAL_SetMuxMode(PORTC,0u,kPortMuxAlt2); //ptc0: spi0_pcs4

    PORT_HAL_SetMuxMode(PORTD,4u,kPortMuxAlt2); //ptd4: spi0_pcs1

 

and

 

dspi_master_user_config_t SPImasterUserConfigPCS0 = {

        .isChipSelectContinuous     = false,

        .isSckContinuous            = false,

        .pcsPolarity                = kDspiPcs_ActiveLow,

        .whichCtar                  = kDspiCtar0,

        .whichPcs                   = kDspiPcs0

    };

 

and then another like this

 

dspi_master_user_config_t SPImasterUserConfigPCS1 = {

            .isChipSelectContinuous     = false,

            .isSckContinuous            = false,

            .pcsPolarity                = kDspiPcs_ActiveLow,

            .whichCtar                  = kDspiCtar0,

            .whichPcs                   = kDspiPcs1

        };

and two more for 2 and 4.

 

I do the rest of the initialization according to the dspi non blocking example in my driver example folder of KSDK1.3

and call dspiResult = DSPI_DRV_MasterInit(DSPI_INSTANCE, &masterState, &SPImasterUserConfigPCS0); which sets PCS0.

 

If I leave it that way, no problem, readout is fine.

 

But if I try to change the ChipSelect during runtime in the main while loop, I don't get correct readouts.

I don't quite know how, but even if I disable the code part, where it is supposed to switch the ChipSelect, it won't work as well. the readout is always zero, but dspi_result also says success.

 

Can I change the Chip Select in the main while loop?

My try was, to do a new MasterInit call with the new dspi_master_user_config_t and then I can call the DSPI_DRV_MasterTransfer again using the new Chip Select.

 

Thanks for reading this far, I am thankful for any help and information.

 

Best regards,

Michael

Outcomes