SPI communication b/w two FRDM-K20D50M Boards

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

SPI communication b/w two FRDM-K20D50M Boards

Jump to solution
5,178 Views
Amit_Kumar1
Senior Contributor II

Hello

I am having problem in transmitting and receiving any character on this FRDM-K20D50M boards. I am using Codewarrior 10.4 with processor expert. I have configured the pins according to the following configuration using processor expert. I am Transmitting and receiving data on both the boards and displaying it on UART. The board configuration is as follows.

      

               pastedImage_0.pngpastedImage_0.png

code for master controller:-

               pastedImage_3.png

code for slave :-

          pastedImage_4.png

The device is configured by processor expert and at any other file apart from this no changes is done. When connecting to the serial port in both the boards the error syntax ie ERROR requesting read operation (slave)  for slave and when connecting to master ERROR requesting read operation (master) is being displayed. which shows that the device is not able to read the data from SPI. Kindly look into the matter.

Regards,

Amit Kumar

1 Solution
1,789 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Kumar,

I check FRDM-K20D50M board schematics and find the PTC6 pin has another connection with MMA8451Q, please remove the jumper on J17.

I don't find any record about FRDM-K20D50M board mounted chip with SPI errata info, which should works as TWR-K20D50M board.

I check your connection is using SPI0_PCS0, please make sure in processor expert project, you set use the correct chip selection pin.

PTC6 (SPI0_SOUT) pin needs to connect with another board's PTC7 (SPI0_SIN) pin.

Wish it helps.

B.R.

Ma Hui

View solution in original post

0 Kudos
16 Replies
1,789 Views
Amit_Kumar1
Senior Contributor II

Hello

The best alternative is to use PTD instead of PTC using pin multiplexing. In this way you wont have to disconnect the J17 jumper and accelerometer will also work fine

pastedImage_0.png

FRDM board pinouts

pastedImage_2.png

1,789 Views
Amit_Kumar1
Senior Contributor II

Hello

I have also tried the code present on the help of the component selector without interrupt and with same configuration which is suggested in the help. but after executing the command for master value 8 is being displayed and for slave value 4 is being displayed. Even if i change the integer value to character still I am getting the same result. Kindly look into the matter.

for master

          pastedImage_0.png

output is

         

          pastedImage_1.png

     for Slave

          pastedImage_2.png

output is

          pastedImage_3.png

Regards

Amit Kumar

0 Kudos
1,789 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Kumar,

I am using two TWR-K20D50M boards test SPI communication with CW V10.4 Processor Expert tool generated project, which works on my side.

Please check my attached example code.

And the SPI pins connection between two TWR-K20D50M board is below:

TWR-K20D50M(SPI Master)          TWR-K20D50M(SPI Slave)

J2-3 (PTC5    SPI0_SCK)              J2-3 (PTC5    SPI0_SCK)

J2-6 (PTC0    SPI0_PCS4)            J1-2 (PTC4    SPI0_PCS0/SS)

J2-7 (PTC6    SPI0_SOUT)            J7-1 (PTC7    SPI0_SIN)  

J7-1 (PTC7    SPI0_SIN)                J2-7 (PTC6    SPI0_SOUT)

J27-2 (GND)                                  J27-2 (GND)

SPI Connection.jpg

Wish it helps.

Best regards,

Ma Hui

1,788 Views
Amit_Kumar1
Senior Contributor II

Hello

I tried one more thing, I removed all the connections and configured TWR board as MASTER and shorted the SPIO_SIN----- SPIO_SOUT. on the same code, I received the data and was displayed on UART. Same thing I did with the FRDM board, and I received empty spaces.

So I think there is something wrong with the FRDM board.

0 Kudos
1,789 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Please notice that TWR-K20D50M use 12MHz crystal with system OSC, while FRDM-K20D50M use 8MHz crystal with system OSC. Please check system clock configuration, if using the correct frequency setting.

And you can debug the code to check if SPI related code was executed.

Wish it hleps.

0 Kudos
1,789 Views
Amit_Kumar1
Senior Contributor II

Hi hui

The below figure shows the clock setting in your Code which you posted

pastedImage_0.png

the below screenshot shows the clock settings for the code which I am dumping in the FRDM board

pastedImage_1.png

Did u meant external xtal ? but in both the boards the external crystal is of 8Mhz. connected on XTAL0 and EXTAL0 pins.

I am attaching my code also.

Regards,

Amit Kumar

0 Kudos
1,788 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Sorry, Kumar,

I made a mistake, both boards use the same frequency crystal.

From your feedback, you can use TWR-K20D50M board works as SPI slave or Master, that board works as expected.

While, you could not run the same code with FRDM-K20D50M board as SPI master or slave?

What I want to know is if you could use my attached code with FRDM-K20D50M board works as SPI master? Could you measure SPI data output data signal with SPI0_SOUT of FRDM-K20D50M PTC6 pin.

For I do not have FRDM-K20D50M board on hand, could you let me know the chip info mounted on that board? PK20DX128VLH5? If possible, could you provide the full print info on chip surface?

Thank you.

B.R.

Ma Hui

0 Kudos
1,788 Views
Amit_Kumar1
Senior Contributor II

Hello HUI

Your code is working fine with TWR board in both the modes. I tried it with the FRDM board and in that I figured out that PT6 is not transmitting any data. in FRDM board I just changed the Serial communication pins ie PTB16, PTB17. it was displaying all the characters but in place of data it was showing empty spaces in the braces '  ' . I have tried shorting the PT6 and PT7 pins in master mode in both the boards independently, there I figured that the TWR is displaying the data but the FRDM is displaying empty space. in the frdm board the part no mention is MK20DX128VLH5 1N86B CTAB1225GB, and the other FRDM board has MK20DX128VLH5 1N86B CTAE1232AK. I also connected CRO probe to PTC6 in FRDM board, and didn't find any fluctuations when sending the data out.

Regards

Amit Kumar

0 Kudos
1,790 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Kumar,

I check FRDM-K20D50M board schematics and find the PTC6 pin has another connection with MMA8451Q, please remove the jumper on J17.

I don't find any record about FRDM-K20D50M board mounted chip with SPI errata info, which should works as TWR-K20D50M board.

I check your connection is using SPI0_PCS0, please make sure in processor expert project, you set use the correct chip selection pin.

PTC6 (SPI0_SOUT) pin needs to connect with another board's PTC7 (SPI0_SIN) pin.

Wish it helps.

B.R.

Ma Hui

0 Kudos
1,788 Views
Amit_Kumar1
Senior Contributor II

Thanks Hui

The above solution worked actually the problem was that J17 Jumper which was connected with accelerometer. That was creating the problem. I disconnected the jumper and the transmission and reception was done successfully. Now by disconnecting the J17, both the FRDM board is working fine. I think you should write this point somewhere in the user manual so that others can be benefited too. Thanks a lot for your help.

Best Regards,

Amit Kumar 

0 Kudos
1,788 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Kumar,

Thank you for the feedback. I will check with document team and add a note about FRDM-K20D50M board SPI application.

best regards,

Ma Hui

1,788 Views
Amit_Kumar1
Senior Contributor II

Hi Ma Hui

Thanks a lot for your reply it was really helpful. although the problem is not completely resolved but some progress is there. Actually I am having two FRDM-K20D50M and one TWR-K20D50M board so I tried your solution. The result was that when I connected two FRDM boards, No output was displayed. instead of data only spaces was displayed. And when I connected 1 FRDM and 1 TWR board board in different configurations, I observed that data was being transmitted from the TWR to FRDM board only. the reception was not being done through the TWR board.

I did all the connections in PTC when I tried to configure PTD in FRDM board as a master and TWR board as a slave then instead of getting '5678' I was receiving '3sdn'. I think the problem is with the transmission of data from the FRDM board. In the below figure , All the communication was supposed to be bidirectional but I have indicated the active flow of data which I received. Kindly look into the matter. 

              

pastedImage_3.png               

Best Regards

Amit Kumar

0 Kudos
1,788 Views
egoodii
Senior Contributor III

I have never used Kinetis SPI in 'slave' mode (nor have I used Codewarrior or PE), but Victor's general comments about SPI are very important:

Every SPI transaction consists of a simultaneous TX and RX of one item (byte to word, length is set).  I would assume a slave would have to be 'preconfigured' with an item to TX, so that when the master's CS (and clock!) comes along, it is ready to send (and simultaneously receive).  You have to be ready at both the master and slave to handle one input and one output transaction per item, regardless of whether 'you need them or not'.  The Kinetis DSPI has some FIFOs that can help decouple 'service time' from line-time, but of course be aware that this further shifts the 'outgoing item sequence' from the 'incoming', for whatever you are trying to interchange.

PS -- your 'IN' and 'OUT' names above look wrong, but the diagrammed interconnect looks OK.

0 Kudos
1,788 Views
VictorLorenzo
Contributor IV

Hi Amit,

SPI silicon IPs work differently from those of the serial ports. In SPI writes and reads occur according to one CLK signal, this signal must be generated by the Master device. It's odd, but needed, you have to 'write' for 'reading', but only in the master device.

In the code for the master device, after writing, you have to keep checking wheter it is busy or not before trying to read:

  1. WriteBlock();
  2. while (busy()) { do something or nothing };
  3. ReadBlock( n bytes );
  4. call inmediately WriteBlock( same n bytes ); for generating the clock, it doesn't matter what you send.

One more thing, take into account the time it takes to the slave device to be ready to return data, it must setup the SPI driver before the master calls for return data. In some cases you could use one HW handshake signal to make the master aware of data availability in the slave device (one interrupt line).

There's a thread where you'll find some info about several issues with the SPI master drivers: Is anyone really using PE Generated SPI driver with MQXLite? How?.

Hope it's usefull for you.

--Victor

0 Kudos
1,788 Views
Amit_Kumar1
Senior Contributor II

hi Victor

while going through SPI_LDD help i found the following connection diagram. I am wondering whether my above connection is correct or wrong?

          pastedImage_0.png

Regards,

Amit Kumar

0 Kudos
1,789 Views
Amit_Kumar1
Senior Contributor II

Hi

Is there any tutorial available to configure SPI?

Regards

Amit Kumar

0 Kudos