Using PCS1/2/3 on SPI0 - K64F Board

cancel
Showing results for 
Search instead for 
Did you mean: 

Using PCS1/2/3 on SPI0 - K64F Board

Jump to solution
304 Views
michaelkoller
Contributor III

Hello!

I have a sensor that gives readings to the controller via SPI. It's working fine when I am using SPI0_PCS0, but I need more Chip Selects for multiple sensors, which gives me trouble.

I am using the SPI0, in my slightly altered KSDK dspi loopback example.

 

In main.c there is the masterUserConfig, that selects the Peripheral Chip Select (,of which SPI0 has 5, apparantly). It looks like this:

dspi_master_user_config_t masterUserConfig = {

        .isChipSelectContinuous     = false,

        .isSckContinuous            = false,

        .pcsPolarity                = kDspiPcs_ActiveLow,

        .whichCtar                  = kDspiCtar0,

        .whichPcs                   = kDspiPcs0

    };

 

Now I would assume, that changing kDspiPcs0 to kDspiPcs1 for example changes the used chip select and there is also the appropriate enum.

 

Next, I have to set the pin mux of the pinout, that is SPI0_PCS1. I found an excel sheet that lists all the different mux options for the K64F Board.

In the init, there is the command

PORT_HAL_SetMuxMode(PORTD,0u,kPortMuxAlt2);

which works fine and sets the mux mode of PortD0 to SPI0_PCS0.

When I insert

PORT_HAL_SetMuxMode(PORTC,3u,kPortMuxAlt2);

in my main or in the spi_configure function, which should activate the SPI0_PCS1 on PORTC3, without even changing anything else in the otherwise working code. The program doesn't run.

 

After this lengthy explanation, my question is:

Why doesn't this work as expected? Are not all mux modes on the processor available on the K64F Board?

Or do I miss something else?

 

I would assume it should be possible to communicate with multiple slaves with the SPI0 in master mode.

Best regards, any information helps,

Michael

Labels (1)
0 Kudos
1 Solution
90 Views
xiangjunrong
Contributor IV

Hi, Michael,

Firstly, for the macro  PORT_HAL_SetMuxMode(PORTC,3u,kPortMuxAlt2);, you have to enable the PORTC gated clock in SIM_SCGC5 register before you call the macro.

I think it is okay that you use the same SPI0 module to select multiple slave spi devices with different PCSx. From hardware perspective, the SPIx_PUSHR register includes the PCS index, when you write all 32 bits register which includes PCS index, the corresponding PCS pin will be valid when the SPI transfer data.

If you call the KSDK function, you can define multiple dspi_master_user_config_t masterUserConfig, for example:

dspi_master_user_config_t masterUserConfig0 with .whichPcs = kDspiPcs0

dspi_master_user_config_t masterUserConfig1 with .whichPcs = kDspiPcs1

If you switch the PCSx, you have call the DSPI_DRV_MasterInit() with the new masterUserConfigx structure. Before you call the function, you have to configure the corresponding PCSx as PCS function as you have done.

Hope it can help you.

BR

Xiangjun Rong

View solution in original post

0 Kudos
2 Replies
90 Views
michaelkoller
Contributor III

Thank you for the great explanation! It works now.

Best regards,

Michael

0 Kudos
91 Views
xiangjunrong
Contributor IV

Hi, Michael,

Firstly, for the macro  PORT_HAL_SetMuxMode(PORTC,3u,kPortMuxAlt2);, you have to enable the PORTC gated clock in SIM_SCGC5 register before you call the macro.

I think it is okay that you use the same SPI0 module to select multiple slave spi devices with different PCSx. From hardware perspective, the SPIx_PUSHR register includes the PCS index, when you write all 32 bits register which includes PCS index, the corresponding PCS pin will be valid when the SPI transfer data.

If you call the KSDK function, you can define multiple dspi_master_user_config_t masterUserConfig, for example:

dspi_master_user_config_t masterUserConfig0 with .whichPcs = kDspiPcs0

dspi_master_user_config_t masterUserConfig1 with .whichPcs = kDspiPcs1

If you switch the PCSx, you have call the DSPI_DRV_MasterInit() with the new masterUserConfigx structure. Before you call the function, you have to configure the corresponding PCSx as PCS function as you have done.

Hope it can help you.

BR

Xiangjun Rong

View solution in original post

0 Kudos