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.
code for master controller:-
code for slave :-
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
已解决! 转到解答。
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
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
FRDM board pinouts
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
output is
for Slave
output is
Regards
Amit Kumar
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)
Wish it helps.
Best regards,
Ma Hui
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.
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.
Hi hui
The below figure shows the clock setting in your Code which you posted
the below screenshot shows the clock settings for the code which I am dumping in the FRDM board
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
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
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
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
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
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.
Best Regards
Amit Kumar
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.
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:
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