ksdk spi slave erroneous data - out of sync

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

ksdk spi slave erroneous data - out of sync

807 Views
mjg8t
Contributor IV

I am having issues with received slave spi data on the k22f using KSDK 1.3 and processor expert.  I have simplified the project using 2 frdm-k22f boards one as master and one as slave.  The master send 8 bytes of data 1-8 and I check on the slave to see that it received it.

 

The recieve data is not correct and sometime is will miss a byte being sent.  It misses 0d05 consistently.  When 5 is missed the rx does not know that the frame has finished and recieves the first part of the next frame.  It seems to be a timing issue, but I checked the phase,polarties and even slowed the master clock to a snails pace of 130Khz.

 

I have looked at the data on the scope and the tx data is fine.  See attachment to see the 0d05 value being sent (but no received on the slave).

 

I looked at the slave registers and the only thing that looks funny is that the SR.TFUF.  Though the sdk api sends a successful return.

 

I have simplified the project to 8 bytes from 16 where the more bytes are missed and things get worse.

 

Any ideas what is wrong?

 

 

 

#define SPI_BLOCKING 1 #define SPIS_BUF_SIZE 8   //volatile uint8_t spisTxBuf[SPIS_BUF_SIZE] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; //tx on MISO volatile uint8_t spisTxBuf[SPIS_BUF_SIZE] = { 0, 1, 2, 3, 4, 5, 6, 7 }; //tx on MISO volatile uint8_t spisRxBuf[SPIS_BUF_SIZE] = { 0 }; //received from MOSI dspi_status_t result;

 

#ifdef SPI_BLOCKING   result = DSPI_DRV_SlaveTransferBlocking(SPI1_IDX, // number of SPI peripheral   spisTxBuf, // pointer to transmit buffer, can be NULL   spisRxBuf, // pointer to receive buffer, can be NULL   SPIS_BUF_SIZE, // size of receive and receive data   1000); // Time out after 1000ms   if (result != kStatus_DSPI_Success) {   __asm("NOP");   } #else     //non-blocking   result = DSPI_DRV_SlaveTransfer(SPI1_IDX,// number of SPI peripheral   spisTxBuf,// pointer to transmit buffer, can be NULL   spisRxBuf,// pointer to receive buffer, can be NULL   SPIS_BUF_SIZE// size of receive and receive data   );     // Wait for transfer completion   while(kStatus_DSPI_Success != DSPI_DRV_SlaveGetTransferStatus(SPI1_IDX, NULL)); #endif     __asm("NOP"); //breakpoint to inpect data   clearRxArray();     }      

 

ksdk 1.3

kds 3

Original Attachment has been moved to: DEBUG_K22F_SPI_SLAVE.zip

Original Attachment has been moved to: DEBUG_K22F_SPI_MASTER.zip

Labels (1)
0 Kudos
5 Replies

464 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Michael,

Have you test the SPI demo under KSDK1.3 on your board ?

KSDK_1.3.0\examples\frdmk22f\driver_examples\dspi

Whether it can work well ?

BR

Alice

0 Kudos

464 Views
mjg8t
Contributor IV

Hi Alice,

I was able to get the sdk 1.3 non-blocking example code working. 

The example code had to be modified to get it work with SPI1.  in hardware_init() function where the where it is hard coded for spi0 "configure_spi_pins(0);)" and should be a variable based upon the selected instance in main.  Second in order to get SPI1 to work I had to enable the clock for portd "CLOCK_SYS_EnablePortClock(PORTD_IDX);".  

So it appears that there is a problem with the processor expert generated code. 

0 Kudos

464 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Michael,

Please connect the GND( the J2 pin 14 ) from one board to another board , then have a try.

If it still can not work , i will create one new project about SPI on KDS-PE tomorrow , and today

i don't know where is wrong , when i run your project on my side , the slave can received nothing.

BR

Alice

0 Kudos

464 Views
mjg8t
Contributor IV

Hi Alice,

Thank you for the reply.  I have had gnd connected from board to board in all tests.

I have been able to reproduce the same problem with the sdk example projects master/slave non-blocking at a high enough frequency of baud rate.  In order to use the drivers on my custom board I was not BOARD_ClockInit();, but was running of the default internal osc.  This was slow enough to cause the sdk drivers to fail at a baud rate of 1Mhz with the SDK drivers.  It appears I will have to use the pll to increase the internal clock to get the performance I need.

0 Kudos

464 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello  Michael,

Today , i test your project on my side again , it can work well use the default clock rate .

And i also configure it to 1M , it can work well also .

pastedImage_1.png

pastedImage_0.png

pastedImage_1.png

Hope it helps


Have a great day,
Alice Yang

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

0 Kudos