First words – setting up SPI

I’ve finally gotten around to look at SPI transfers between the raspberry pi and the STM32 Nucleo F401RE. As usual, once you know how to do it, it’s incredible simple.


The two new best friends

Of course, when you don’t, it’s not, and as usual it took me some time to get my head around SPI. The SPI protocol is well described many other places so I won’t get into that, but here are a few main points:

  • There’s a master and a slave (and the Raspberry Pi insists on being the master, and it insists on 8bit transactions).
  • The master initiates the transfers, and for every byte sent by the master, the slave sends one back.
  • Once the SPI+DMA is set up on the nucleo board there’s nothing left to do on the nucleo side (this was the part that puzzled me the most).

SPI on the Raspberry Pi side is very easily handled with theĀ wiringPi library. The site contains instructions for installing wiringPi and enabling the SPI peripheral on the rpi.

SPI on the STM32 side is easily handled with the standard peripherals library. Here is the source code for a simple DMA enabled SPI transfer.

Here’s what it looks like through the VNC connection to rpi:


SPI communication between STM32 and raspberry pi.

The entirety of the test program on the rpi is visible in the picture. It could be even simpler, but I also used it for checking how to send 16bit data through the rpi’s 8-bit SPI.

As the nucleo is the slave it cannot start the transfers, so I’ll need to figure out how to let the rpi know when the CCD has been sampled and data is ready to be transferred.

I would also like to do some kind of speed test. The SPI is set to 16MHz in the example, but I’m not sure if in fact it reaches this speed.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s