Interfacing with 3-wire SPI – Total Phase
Interfacing with 3-wire SPI

Contents

Introduction

A normal SPI interface consists of four signals: clock (SCLK), slave select (!SS or !CS), master input/slave output (MISO), and master output/slave input (MOSI). SPI has separate pins for input and output data, making it full-duplex. Some chips use a half-duplex interface similar to true SPI, but with a single data line. Interfaces like this are commonly called "3-wire SPI" and can be used with Total Phase SPI products with some simple circuit modifications.

In this article, we will show how the Aardvark I2C/SPI host adapter and the Beagle I2C/SPI protocol analyzer can work with slaves that use a 3-wire SPI interface. As an example, we have chosen to work with the National LM74 temperature sensor, whose pinout is shown below:

Pinout of the National LM74
Figure 1: Pinout of National LM74

Step 1: Read the data sheet

The LM74's data sheet says that a complete transaction consists of 32 clock pulses. The LM74 will output data for the first 16 clocks, and will read input data for the remaining clocks. This sounds simple enough, but we need to setup our Aardvark adapter or Beagle analyzer properly to avoid damaging any devices.

The key point to realize is that, although the Aardvark adapter will send out 4 MOSI bytes, the LM74 will only read the last 2 of these. Similarly, only the first 2 MISO bytes will contain temperature (the last 2 MISO bytes will mirror the MOSI data and should be ignored).

Step 2: Connect the signals

It is obvious how to connect the clock and slave select lines, but the MOSI and MISO lines require some thought. We need to make sure that the MOSI and MISO lines are not shorted together because this would damage the equipment.

Aardvark I2C/SPI host adapter

To connect the Aardvark's MOSI and MISO lines to the slave's single data line without shorting them together, we need to insert a 10k resistor between MOSI and MISO. Then, the MISO line should be connected directly to the slave's data line.

LM74 and Aardvark Connections
Figure 2: LM74 and Aardvark Connections

When the slave is driving MISO, the Aardvark's readings will not be disturbed by the state of the MOSI line. If the system uses 5.0V as a logical high, then a maximum current of 0.5mA will flow through the resistor.

When the slave's data line is configured as an input, the voltage on MOSI and MISO will be essentially the same (there will be little voltage drop across the resistor because the high-impedance slave sinks little current).

Beagle I2C/SPI protocol analyzer

The Beagle I2C/SPI protocol analyzer does not drive any signals. Either the MOSI or MISO line can be connected directly to the data line. In Data Center, you will only look at the data on the signal that is connected to the target interface.

LM74 and Beagle ISM Connections
Figure 3: LM74 and Beagle ISM Connections

Step 3: Read and transmit data

Although the raw MOSI and MISO data can be displayed in Control Center and Data Center, you cannot customize the the way it is displayed. To have complete control over how the data is displayed and processed, we recommend using our free API.

Using the API

The Aardvark adapter is meant to work with full-duplex SPI, so you will need to carefully setup the bytes to be transmitted. Additionally, you will need to convert the raw temperature data into meaningful Celsius/Fahrenheit values. For a complete example, please see the Python program (lm74.zip in the Reference section below) which was used to interface the Aardvark adapter with the with the National LM74. This program reads and writes data to the LM74 using 3-wire SPI.

Output of API program
Figure 5: Example output of Python program

Using Control Center software

Control Center can be used to read the raw temperature data, as shown below. In this case, the temperature reading is 28.5625 Celsius (by looking at the top 11 bits of first 2 bytes received). For more details, see the LM74 data sheet and the Python program.

LM74 Reading in Control Center
Figure 4: LM74 Reading in Control Center

Additional Comments

There are a number of different versions of the LM74 which have different VDD compatibilities and different logical thresholds. For this example, we used the LM74CIM-5 with VDD = 4.5V and a logical high threshold of 3.15V.

The 10k resistor between MOSI and MISO will increase the time constant of the MOSI signal and may decrease the maximum frequency at which reliable communication can occur.

References

Have more questions? Submit a request