Raspberry Pi to MPC5744p over SPI

Started by WouterJ 4 years ago2 replieslatest reply 4 years ago187 views


I am currently trying to get SPI data transfer between the MPC5744p and a Raspberry Pi 4 to work.

I'm using the SPIdev python toolkit to send the value 26 over to the MPC, using the attached SPItest.py script.

To receive this, i've modified the code of the SPI_MPC5744P example to only expect data arriving on the slave DSPI2.

When testing this my connections were as follows:

Raspberry Pi           NXP

SCLK                →   DSPI_2 CLK (PA0 - J5_1)

MOSI                 →   DSPI_2_SIN (PA2 - J5_5)

The code on the MPC5744P was intended to send a message to UART when SPI transfer has happened. However, when using the script on the Raspberry Pi, I could not get this message to show up.

I'm currently stuck as I can't seem to find out what I'm forgetting?

At first I thought that i also needed to connect the Slave Select pin, but the reference manual says that you shouldn't tie this to ground?

Thank you for your time

Main code for NXP MPC5744P:


SPI code for NXP MPC5744P:



Python script for RPI:


Thank you for your time!

[ - ]
Reply by BVRameshJune 8, 2020

Hello Wouter,

You have mentioned that you have not connected the slave select pin of DSPI, to ground, but have you connected it to the slave select of Raspberry PI to slave select of DSPI, as you ave mentioned only CLK and SIN connections. The DSPI will respond to SPI only if Slave select is low.

Please confirm this.

One more point: if you want to use it as two wire mode only (using only CLK and SIN) you have to ground the SS pin at slave side otherwise slave will not receive the data.

[ - ]
Reply by mr_banditJune 8, 2020

(1) - do you have an oscope? If not, get one. The Rigol DS1054Z is $350. 4 channel, 50MHz. (I will not tell you there is a tool on the net that changes 1 byte of EEPROM to make it 100MHz. Yo did not hear that from me.)

(2) Without a scope, take the RPi and put LEDs on the line, and a switch in MISO (so you can have a controlled input. Set the clock to the lowest speed (1Hz?)

In both cases, send a 0x55. Verify it sent it correctly. Repeat with 0xAA. If you are using the LEDs, you should be able to watch them blink. The one on the clock should toggle.

The reason is to confirm the RPi side is working properly on TX.

Now, if you care about RPi SPI RX, set up a loop, reading the port and print it out. Use the switch to change the input. At 1Hz, you can key in a pattern.

NOTE: Do you need pullups on the exterior lines?

Now setup the NXP for RX. Make it 1Hz. Make a loop that just does a read.

Hook the two together. Make sure MISO goes to MOSI properly and the clock (SCLK) is connected.

The RPi should have a loop, sending 0x55.

Make a loop on the NXP: receive one byte and print it out. Continue until the NXP is properly receiving the 0x55. Make the RPi TX 0xAA and verify the NXP receives the 0xAA

Repeat the sequence for the NXP TX.

The reason for this is: you need to simplify the system to one component and make sure it works. The easiest is TX, because you can look at the output, then use it as a tool to debug the RX side.

Why 0x55? bit pattern 01010101    0xAA:  10101010

Hope this helps. And get an oscope.

This method works with any byte/word oriented communication channel protocol.

Personally, I use an Arduino to debug these kinds of comm channels. Simple, cheap, code exists. I recommend having an Arduino AT XMEGA on your bench for these sorts of tasks. Also useful because you have a number of digital lines to wiggle.