Hello everyone,
I am using KSDK 1.1.0 on a FRDM-K64 board and would like to use an SPI port with multiple chip selects (multiple connected slaves). I used Processor Expert to set up the DSPI peripheral with two different master configurations that have their dedicated chip select pin.
My question is: How can I change between using the two chip selects? I would like to avoid to reinitialize the whole driver by using DSPI_DRV_Master(De)Init() each time. Is there any simple way to switch between several chip selects?
Best regards
Matthias
Hi matthias ,
You can use "DSPI_HAL_StartTransfer()" and "DSPI_HAL_StopTransfer()" change between using the two chip selects.
Best Regards,
Alice
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Are you sure? According to the comment in peripeherals_init.c:
/*!
* @brief Starts the DSPI transfers, clears HALT bit in MCR.
*
* This function call called whenever the module is ready to begin data transfers in either master
* or slave mode.
*
* @param baseAddr Module base address
*/
static inline void DSPI_HAL_StartTransfer(uint32_t baseAddr)
{
BW_SPI_MCR_HALT(baseAddr, 0);
}
How does this sw change the PCS bits in the SPIx_PUSHR register?
HI Ole
(1) At the begin of the project , it need initialize both SPI0 and SPI1,
complete the two component basic SPI configure.
And delete "
/* Start the transfer process in the hardware */
DSPI_HAL_StartTransfer(baseAddr);
"
(2) n the process of replacement , use the function "DSPI_HAL_StartTransfer()" and "DSPI_HAL_StopTransfer()".
(3) About the bit PCS[x] you said , both PCS[0] and PCS[1] (if use SPI0 and SPI1 ) already set "Assert" in the initialize function.
(4) Of course , if there have public register the two SPI both use ,and only can select one SPI in this register , it need reconfigure in the change period.
BR
Alice
Hello Alice,
thanks for your reply. I think there is a misunderstanding. I do not want to use two different SPI ports. As said, I have two slaves connected to the same SPI port (in my case SPI0) and I want to change the chip select that is used when transferring data.
I figured out that the PCS bits in the SPI0_PUSHR register should be changed as Ole said. To achieve this, I change the component whichPcs in the structure g_dspiStatePtr[FSL_SPICOM0] that is used globally in fsl_dspi_master_driver.c. Like this, the correct PCS bits are set when calling DSPI_DRV_MasterTransferBlocking(), for example.
Is this the right way to do it or are there any functions in the KSDK driver that should be used?
Best regards,
Matthias
Hi mattias,
I know your meaning .
In the KSDK, there is not the driver function to change slave spi.
I recommend you configure the pcs pin to GPIO pin, when want to select the slave spi, set the related pin to 0, the other on to 1.
BR
Alice