igor-imx

Kinetis K60 MQX 3.8 - SPI SLAVE problem!

Discussion created by igor-imx on Jun 28, 2012
Latest reply on Jun 25, 2013 by Matthew James

Hi Everyone.

I was trying to get 2 K60 based boads to talk SPI one in slave mode and another one in master using MQX 3.8 and IAR.

Im using MQX interupt drivers for both .

Configuration is as following:

Board 1 using SPI0 interface in Master Mode, Big Endian,  SPI_CLK_POL_PHA_MODE0, 100Khz Baud Rate.

Board 2 using SPI0 interface in Slave mode , Big Endian,  SPI_CLK_POL_PHA_MODE0, 100Khz Baud Rate.

 

On the board 2, i also have an interrupt setup on the SPI0_CS0 pin with my ISR that just sets the semaphore that the recieving task blocks on.

 

Everything seems to be good except couple of things:

 

1.When the rx task on board2 unblocks from the semaphore and tries to read from the SPI, the number of bytes read always return 16.

Read is accomplished with the following code:

 

unsigned char  data[200];

result = fread(&data[0],1,32,spifd)

 

Since the SPI buffer size in the driver is 32 bytes (default that i will have to increase later) i try to read all the available bytes.

This call Always returns 16 as a number of bytes read, instead of the actual number of bytes i send.

Also, when looking at the memory of the SPI buffers (spi_dma_dspi.c line 510, variable rx_ptr), i can see that every byte that i have send from the Master board, in memory looks like this, lets imagine i send 0x1, 0x2,0x3,0x4,0x5

What i see in memory is:

 

0x1 0x00 0x00 0x00 0x2 0x00 0x00 0x00 0x3 0x00 0x00 0x00 0x4 0x00 0x00 0x00 0x5 0x00 0x00 0x00

 

Can anyone shed any light on what im doing wrong?

 

My goal is to have a slave unblock upon recieving the interupt from the CS0 going high and read all the bytes that were recieved.

 

Any help will be greately appriciated.

 

PS

 

I know that the Master SPI driver works good since i use it on the other SPI port to talk to the Flash Chip and never had any issues.

This is the first time im using slave functionality of the driver.

 


Outcomes