After some nights of hard thinking about pros and cons, I decided to make the three boards of this project to communicate through an SPI bus
The Serial Peripheral Interface Bus or SPI bus is a synchronous serial data link standard, named by Motorola, that operates in full duplex mode. SPI is much simpler than I2C. Master and slave are linked by three data wires, usually called MISO, (Master in, Slave out), MOSI (Master out, Slave in), the SCLK clock line (sometimes called M-CLK), and an optional SS (Slave Select; sometimes known as the Chip Select or CS line or Chip Enable or CE line) is the slave select or chip select line.
In theory, The CS line is optional only if you have one slave, otherwise one or more SS lines are provided. In my case, the chip select line is not required since I’m going to send the same data in “broadcast” to both the NXP Freedom boards.
Usually the transfer sequence consist of driving the SS line low, sending X number of clock signals with the proper polarity and phase, then driving the SS line high to end the communication. As the clock signals are generated, data is transferred in both directions, therefore in a “transmit only” system the received bytes have to be discarded and in a “receive only” system a dummy byte has to be transmitted.
Many SPI-enabled ICs and Microcontrollers can cope with data rates of over 10MHz, so transfer is much faster than with I2C. Since it is synchronous communications, it is not limited to 8-bit words so you can send any message sizes with arbitrary content and purpose. The SPI interface does not require pull-up resistors, which translates to lower power consumption. The downside is that SPI normally has no addressing capability; instead, devices are selected by means of a SS signal which the master can use to enable one slave out of several connected to the SPI bus. If more than one slave exists, one chip select line is required per device, which can use precious GPIO lines on the Master.
Installing SPI on Raspberry Pi
To enable SPI on the Raspberry board, launche the raspi-config utility
$ sudo raspi-config
Then, select the “Advanced options” entry
And finally SPI
Click “Yes” to confirm that you want to enable SPI module. I also answered “yes” when asked whether I want to enable SPI interface by default so that the SPI driver is loaded automatically on boot
You can now reboot the Raspberry. At restart, check whether the SPI devices are there by typing
$ ls /dev
You should see the two SPI devices
If you can’t see the devices, may be you need to update the board to the latest firmware, as the latest has brought out the SPI controller. To do so I used Andrews Hexxeh rpi-update to do this.
Once the updates are all completed., reboot your Raspberry.
and now you should see spidev in /dev/ directory
The last part of this is to test the SPI signal. I'm going to download a test application: spidev_test.c
The test requires that MISO and MOSI pins are shorted.
Then, we need to edit the spidev_test.c file so it it uses the correct spidevice in the /dev/ folder.
scroll down and change the device to "spidev0.0".
Let's compile and run it
gcc spidev_test.c sudo ./a.out
This is the result: so the SPI driver is actually working!