Close

3-Wire SPI - A deep dive

A project log for Self Flying Quadcopter

A fun and educational project to convert a small quadcopter to a self-flying indoor drone.

George AlbercookGeorge Albercook 12/27/2017 at 04:140 Comments

The XN297L radio chip uses an uncommon implementation of SPI.  SPI typically uses four wires to achieve synchronize communication they are Clock, MOSI and MISO and ground.  Sparkfun has a great tutorial on serial communication.

When two devices communicate with a synchronized protocol one has to control the clock. That one is called the master.  Now the master can either send or receive data so that leaves several possibilities. Typically, in SPI one pin will act as the master (control the clock) when it is sending data, but when it is receiving data it will be the slave. This are denoted Master Out Slave In (MOSI). A second pin is called MISO (Master In Slave Out) meaning that pin controls the clock when data is coming in but is the slave when data is going out. One benefit of this configuration is that Data can be going both ways at the same time.

In order to do this four wires are required. MOSI, MISO, Clock and Ground but the XN297L does not use all four. It runs in a much less common configuration that only allows data to go in one direction at a time. This is called 3-wire SPI.  The XN297L will always act as the slave so its' communication pin is called SOSI (Slave out, Slave In).  This pin connects to a pin on the master which is called MOMI (Master Out, Master In). 

In order to get our microcontroller to us this configuration we will have to tell it which of its' SPI pins will become MOMI and to ignore the other pin. The easy way to do this is to cheat and copy some example code that does it. Unfortunately, we could not find such an example so we put on our miner hardhats (the ones with lamps on them) kissed our wives and descended into the depths of the microcontroller data sheets.

Discussions