PC/CP320 Physical Computing
Raspberry Pi SPI Digital-to-Analog Converter
Overview
Digital transmission of analog data, (such as sound and video),
requires analog input signals to be converted to
digital signals for processing. Once received, the signals
then have
to be converted to back analog.
These conversions are done by analog to digital (A/D) and
digital to
analog (D/A) converters, respectively.
Although you could construct
these converters from discrete components,
integrated circuits specifically designed for these purposes are
usually used.
Objectives
- To introduce the SPI interface on the Raspberry Pi
- To become familiar with digital-to-analog conversion
- To write a test program to show the SPI D/A in operation
Background
The SPI (
Serial
Peripheral
Interface bus
is a
synchronous interface allowing a single
master device to communicate with multiple
slave devices. The master
device controls a clock signal for the slaves. The bus consists of
two data lines (one for each direction), the clock signal, and select
lines for each slave.
Although it may not always be
mentioned, it's also important that the GROUND lines for the
master and slaves be connected.
It is now very commonly used to connect sensors to
microprocessors or microcontrollers, and so will remain relevant for
the forseable future. It's also one of the simplest serial protocols,
and so it's easy to study.
The Raspberry Pi has an SPI bus built-in to handle up to two slave
devices, so it can be used for
SPI communications.
Preparation
Equipment
- Raspberry Pi
- TTL-serial cable
- MAX522
SPI digital-to-analog converter
- 0.1 μ F capacitor
- 0.01 μ F capacitor
- oscilloscope
Procedure
As always, do all of the wiring before
turning on power to the Raspberry Pi.
|
The Rapsberry Pi GPIO pins can easily be damaged with
improper handling. The DAC in this
lab can use a 3.3V
supply, so it can be powered from the 3.3V GPIO pin.
Now that you are going to be using the 3.3V supply, use blue
wires exclusively for 3.3V so that they don't get confused
with 5V supply wires.
|
To wire the DAC, there are 4 different sub-circuits to wire.
They are:
-
Supply voltages and inputs from Raspberry Pi
-
Voltage reference
-
SPI connections to Raspberry Pi
-
Outputs
You will wire each of these sections in turn.
-
SPI GPIO pins
Note: The Spidev library has laready been installed.
From the GPIO diagram,
identify all of the SPI pins, namely:
- Connect VDD
to the appropriate GPIO pin.
- Connect GND
to the appropriate GPIO pin.
- Conect the REF input of the DAC
to the 3.3V pin of the Raspberry Pi.
The output voltage will be proportional to the voltage on the
REF input.
- Conect the Raspberry Pi
SPI pins as follows:
Since communication is only going from the Raspberry Pi
to
the
DAC, which signal line do you need?
Remember to connect the SPI clock and GROUND lines as
well.
How many slave select lines does the Raspberry Pi have? Be
sure your program is correct for the one you choose.
-
Note: The two DACs have different
current limits, so the capacitor required depends on which one
you're using. See the datasheet for details.
Connect either the 0.1 μ F capacitor or the 0.01 μ F
capacitor
from the
output of the DAC
to GROUND, depending on which DAC you are using.
- Conect the output to the
oscilloscope.
- Turn on the Pi and connect to it with the serial monitor.
- Write a program to send values to the DAC.
Note that every
transfer to the DAC should be a two byte transfer.
Download the
test program from the website.
Replace the question marks with appropriate values as needed.
-
If you
have
done everything correctly, you should have a circuit which can
take in an
8-bit digital value and produce an appropriate analog output
between 0 and 3.3 volts.
What is the significance of the value "49" in the code example?
(Hint: Look at the DAC datasheet.)
Demonstrate your circuit to the lab supervisor.
Keep this circuit for future labs.
Don't take it apart.
As always, remember to shut down properly when you are
finished.