Serial Peripheral Interface

Synchronous vs. Asynchronous

A serial port with a RX and TX line works in asynchronous mode as there is no common clock on the transmitting and receiving sides. Synchronization is done by adding an extra start and stop sequence to re-synchronize both individual clocks. This only works though when both sides are on the same transmission speed.

SPI is a synchronous data bus as there are two data lines (MISO and MOSI), one clock line and a slave select line. The side generating the clock signal is usually the master and attached devices are called the slaves. When the master wants to send data to the slaves, it simply puts the information on MOSI (Master Out / Slave In) line. Slaves can communicate with the master over the MISO (Master In / Slave Out) line  while the master continues to generate a clock signal.  The slave select line is usually used for the master to talk to a particular slave only.

 

SPI Configurations

The 68HC11 was used because the hardware SPI is mapped out. The SPI block on the microcontroller was used as a master and turned on with following configurations:

  • data is sampled on rising clock edge
  • data is shifted out on data line on falling clock edge
  • active high clock (idles low)
  • Least significant bit gets shifted out first
  • Interrupt generation on completion of SPI transmission
  • 57600 Baud

The resulting SPI looks as follows:

neg_edge_change

The first channel is wired to the data line and the second channel is wired to the clock line. The data transmitted is 01110011 in binary.

The benefits of a hardware SPI is that the clock signal is generated automatically when the master initiates a transfer. Data is also shifted out on command and an interrupt can be generated when the SPI is ready for the next byte to be transmitted.

 

SPI with Dot Matrix Display

In this project, the 68HC11 acts as a master and the dot matrix display acts as a slave. The slave select line is not implemented as there is only one slave. So that line is just pulled low for the same slave to always be selected. There is no need for feedback from the slave so the only data line implemented is the MOSI line for the microcontroller to send display data to the dot matrix.

The tasks performed within the SPI interrupt service routine are following:

  • brightness control
  • prepare data to be sent next