K82 SPI chip select not going high at end of frame transfer

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

K82 SPI chip select not going high at end of frame transfer

932 Views
gokulnath12345
Contributor I

Hi

My Project requirement is to use K82 SPI transfer to communicate a  slave device.

The requirements for Slave side is the following,

Frame transfer is 16 bits,

CPOL = 0;

CPHA =0; So its mode 0 SPI communication for SCK 

Active Low chip select for 16 bits (also know as slave select)

I need to send some 64 bytes, means 32 frames in total.

So at the end of each frame transfer is completed, I should see Chip Select(slave select) getting low to high.

I used the code given from demo project SDK examples, dspi_half_duplex_polling_master for FRDM k82, which suited my requirements and made the following changes in initial configuration,

int main(void)
{

/* Transfer structure for half-duplex. */
dspi_half_duplex_transfer_t xfer = {0};
dspi_master_config_t masterConfig;

BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();

masterConfig.whichCtar = kDSPI_Ctar0;
masterConfig.ctarConfig.baudRate = TRANSFER_BAUDRATE;
masterConfig.ctarConfig.bitsPerFrame = 16;
masterConfig.ctarConfig.cpol = kDSPI_ClockPolarityActiveHigh;
masterConfig.ctarConfig.cpha = kDSPI_ClockPhaseFirstEdge;
masterConfig.ctarConfig.direction = kDSPI_MsbFirst;
masterConfig.ctarConfig.pcsToSckDelayInNanoSec = 1000000000U / TRANSFER_BAUDRATE;
masterConfig.ctarConfig.lastSckToPcsDelayInNanoSec = 1000000000U / TRANSFER_BAUDRATE;
masterConfig.ctarConfig.betweenTransferDelayInNanoSec = 500000000000U / TRANSFER_BAUDRATE;

masterConfig.whichPcs = EXAMPLE_DSPI_MASTER_PCS_FOR_INIT;
masterConfig.pcsActiveHighOrLow = kDSPI_PcsActiveLow;

masterConfig.enableContinuousSCK = false;
masterConfig.enableRxFifoOverWrite = false;
masterConfig.enableModifiedTimingFormat = false;
masterConfig.samplePoint = kDSPI_SckToSin0Clock;
srcFreq = DSPI_MASTER_CLK_FREQ;
DSPI_MasterInit(EXAMPLE_DSPI_MASTER_BASEADDR, &masterConfig, srcFreq);

// filled the data I need to configure my slave device

for (i = 0; i < BUFFER_SIZE; i++)
{
txData[i] = 1U;
}

/*Start Transfer by polling mode. */
xfer.txData = txData;
xfer.rxData = NULL;
xfer.txDataSize = sizeof(txData);
xfer.rxDataSize = 0; 
xfer.isTransmitFirst = true;
xfer.isPcsAssertInTransfer = true;
xfer.configFlags = kDSPI_MasterCtar0 | EXAMPLE_DSPI_MASTER_PCS_FOR_TRANSFER | kDSPI_PcsActiveLow;

 DSPI_MasterHalfDuplexTransferBlocking(EXAMPLE_DSPI_MASTER_BASEADDR, &xfer);

/* Stop the transfer. */
DSPI_Deinit(EXAMPLE_DSPI_MASTER_BASEADDR);

while (1)
      { }
}

I am unable to see chip select getting active low for every 32 frame, and 16 clock pulse per frame and data in MOSI.

But Iam able to see proper data in another K82 as half duplex slave, and receives correct data when the only change in line, 

xfer.configFlags = kDSPI_MasterCtar0 | EXAMPLE_DSPI_MASTER_PCS_FOR_TRANSFER | kDSPI_MasterPcsContinuous ;

with MasterPcsContinuous instead of PcsActiveLow. I also kept delay between transfer of frames as 

masterConfig.ctarConfig.betweenTransferDelayInNanoSec = 500000000000U / TRANSFER_BAUDRATE;.

Yet I am unable to see my 32 frames with chip select going high to low  and low to high 32 times and 16 clock pulses per frame in scope.

Please help me if Iam making any mistakes.

Thanks

Gokul.

0 Kudos
3 Replies

758 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Gokul,

   Actually, your problem is the SPI_CS pin control.

   If you want the CS pin work as your demand freely, I highly recommend change the SPI_CS hardware CS function to the GPIO, then each time when you want to send and receive the SPI data, you pull the according CS gpio to low, after it finished, you use the code to pull it high, this control will be freely, especially when communicate with the external SPI chip which have it's own CS time sequence.

   So, to save the time, please modify the SPI_CS pin to the GPIO, then use the GPIO to control the CS pin, it will be more effective. This method is the famous method.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

758 Views
gokulnath12345
Contributor I

Hello

Thanks for your input, I could finally make k82 spi communication works well with my slave device.

Thanks guys

Gokul.

0 Kudos

758 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Gokul,

     You are welcome!

     If you have the new question about kinetis, welcome to create the new question post.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos