SPI communication with KSDK 1.3 using "fsl_spi" and Processor Expert - Chip Select Problems

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

SPI communication with KSDK 1.3 using "fsl_spi" and Processor Expert - Chip Select Problems

Jump to solution
1,105 Views
andrelemke
Contributor III

Hi!

 

I'm working with the Kinetis KL27Z connected with a SPI Flash Memory through SPI module.

Everything is working fine controlling the Chip Select or "Chip Enable" externally of the SPI functions using the "fsl_gpio", but I would like to control using the proper control of “Slave Select Pin” provided by “fsl_spi”. I had some tests and the device doesn’t answer when I’m sending or receiving more than one byte…

 

Here is the logic diagram provided by the memory manufacturer (Reading Chip ID, for example):

133003_133003.jpgSPI Read ID sequence.jpg

 

I'm using this component and their function:

133145_133145.jpgSPI função master transfer.jpg

 

The "fsl_gpio" configuration:

 

133150_133150.pngSPI GPIO.png

 

 

I needed to add a little delay to correct the toggle time of the “chip select “logic level. The code is shown below:

133146_133146.jpgSPI Código por fora da função.jpg

 

The device is working fine, like the proposal of the manufacturer:

133147_133147.jpgSPI Chip Select por fora.jpg

 

Until here is ok, the device is working… But I would like to don’t use “delays” or “blocking” functions. I just need to use the interface with interrupts and live my main function free!

 

When I put the configuration of the “Slave Select Pin”, like below some problems occur...

133149_133149.jpgSPI PEx Slave Select.jpg

 

The code...

133151_133151.jpgcodigo sem chip en.jpg

 

...and device toggle the "Chip Enable" between each byte sent or received. The logic diagram is shown below:

133152_133152.jpgSPI Chip Select por dentro.jpg

 

My doubts are: It's a bug from the KSDK 1.3 or isn't possible to transfer multiple data bytes using just "fsl_spi" configurations?

 

Sorry my english... Thank's!

Labels (1)
1 Solution
610 Views
isaacavila
NXP Employee
NXP Employee

Hello Andre,

In fact, SPI module's functionality allows user to control SS automatically or manual, if you select automatic control on Slave Select, SS output feature automatically drives the SS pin low during transmission to select external devices and drives the SS pin high during idle to deselect external devices, it is to say, that if you are sending 8 (or 16) bits, once they have transfered, SS will go to idle state. (This is practical by a single communication scheme). On the other hand, if you want to send more than 8 bits (or 16 bits if you are using 16 bit extension) in the same transaction, you will need to use manual control, otherwise, SPI module will act as if these bits are different transactions. So it is not a Driver issue, it is SPI's module functionality.

So for your current transaction scheme, you can use manual control and also, replace the delay for next instructions:

    error = SPI_DRV_MasterTransfer(SPI_MASTER_INSTANCE, NULL, spi_buffer, NULL, sizeof(spi_buffer)/sizeof(spi_buffer[0]));

    if (kStatus_SPI_Success != error) {

#ifdef DEBUG

        PRINTF("Error on SPI_DRV_MasterTransfer\r\n");

#endif

    }

    while(kStatus_SPI_Success != SPI_DRV_MasterGetTransferStatus(SPI_MASTER_INSTANCE, NULL));

The SPI_DRV_MasterGetTransferStatus function returns kstatus_SPI_Success when all data have been transfered, this way, you won't need delay function in order to finish the transaction.

I hope this can help you!

Best Regards,

Isaac Avila

----------------------------------------------------------------------------------------------------------------------------------------

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

----------------------------------------------------------------------------------------------------------------------------------------

View solution in original post

1 Reply
611 Views
isaacavila
NXP Employee
NXP Employee

Hello Andre,

In fact, SPI module's functionality allows user to control SS automatically or manual, if you select automatic control on Slave Select, SS output feature automatically drives the SS pin low during transmission to select external devices and drives the SS pin high during idle to deselect external devices, it is to say, that if you are sending 8 (or 16) bits, once they have transfered, SS will go to idle state. (This is practical by a single communication scheme). On the other hand, if you want to send more than 8 bits (or 16 bits if you are using 16 bit extension) in the same transaction, you will need to use manual control, otherwise, SPI module will act as if these bits are different transactions. So it is not a Driver issue, it is SPI's module functionality.

So for your current transaction scheme, you can use manual control and also, replace the delay for next instructions:

    error = SPI_DRV_MasterTransfer(SPI_MASTER_INSTANCE, NULL, spi_buffer, NULL, sizeof(spi_buffer)/sizeof(spi_buffer[0]));

    if (kStatus_SPI_Success != error) {

#ifdef DEBUG

        PRINTF("Error on SPI_DRV_MasterTransfer\r\n");

#endif

    }

    while(kStatus_SPI_Success != SPI_DRV_MasterGetTransferStatus(SPI_MASTER_INSTANCE, NULL));

The SPI_DRV_MasterGetTransferStatus function returns kstatus_SPI_Success when all data have been transfered, this way, you won't need delay function in order to finish the transaction.

I hope this can help you!

Best Regards,

Isaac Avila

----------------------------------------------------------------------------------------------------------------------------------------

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

----------------------------------------------------------------------------------------------------------------------------------------