Kinetis K60 MQX 3.8 - SPI SLAVE problem!

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

Kinetis K60 MQX 3.8 - SPI SLAVE problem!

1,659 Views
igor-imx
Contributor IV

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.

 


0 Kudos
5 Replies

517 Views
matthewjames
Contributor I

Sorry to drag up an old thread but was there any solution to this problem? 

Similar issues here and was hoping that the tech department has formulated an answer by now...

0 Kudos

517 Views
mohwaqas12
Contributor III

Hello Igor,

I am also working on something similar , trying to communicate using spi slave. First of all , i would like to know , how did you setup an interrupt on SPI chip select. For now i am using gpio driver to setup an interrupt on CS2 , but that would extra signal. I want to setup an interrupt on the same CS0.

With my CS2 interrupt i am also trying to read specific number of bytes , byte 1 is always read correctly but i dont understand what happens to others.  I am using polled driver for this case.

With chip select interrupt , did you try using polled spi driver. Does it performs better as compared to interrupt one. Has your byte missing problem been solved.

Regards

0 Kudos

517 Views
igor-imx
Contributor IV

Looks like im over this problem now but have another one however.

 

I setup a simple test, Device 1 (Master) sends one byte to the slave every second.

Device 2 (Slave) recieves one byte and stores it in the array.

 

I notice that device 2 misses on every seconds byte is recieves. So it would recieve: 0x01 0x03 0x05 0x07 etc.

however i have confirmed that device 1 sends 1,2,3,4,5,6,7,8,9,10

Any ideas why this would happen?

 

thanx

0 Kudos

517 Views
mohwaqas12
Contributor III

Hello again , 

Well i also had the similar problem while using interrupt spi driver.

From master i was sending these 10 bytes : 1 2 3 4 5 6 7 8 9 10 .

In slave i was getting : 1 5 6 7 8 9 10 .

Seemed liked it had something to do with ISR priority , so in twrk60n512.h

I changed DSPI interrupt priority from

#define BSP_DSPI_INT_LEVEL               (4)

to

#define BSP_DSPI_INT_LEVEL               (2)

and it solved my problem , hopefully yours too

0 Kudos

517 Views
Monica
Senior Contributor III

Igor, how's it going?

Great thing that you could get out of the initial problem without our help, we're very sorry for the delay.

Tech department is already working to answer all your questions, so I thank you for being so patient!

Regards,

Monica

0 Kudos