Instructables

Using an Arduino to Control or Test an SPI electronic device

Featured
Picture of Using an Arduino to Control or Test an SPI electronic device
DSC_4438.JPG
DSC_4462.JPG
Scope A Trace Ohm meter.jpg
Scope B Trace.jpg
AD7376 Pin Out.JPG
AD7376 Timing Diagram.JPG
There are many electronic devices that use the SPI  bus, or Serial Peripheral Interface bus, for communications (e.g. various sensors, LCD displays, digital potentiometers, D/A and A/D converters, wireless transmitters and receivers, audio volume controls).  The devices receive data serially from a microcontroller using a 3-wire set-up that includes a chip select signal (usually titled CS - when this signal is at logic 0, a chip recognizes it will be receiving or sending data), a clock signal for clocking the serial data into the device, and the serial data stream itself.

Many hobbyists use microcontrollers such as the Arduino to control and use SPI devices.  Oftentimes, you just want to test the electronic device to make sure it and its associated circuitry is working properly.  This Instructables will show you how to set up and program a simple proto board circuit using the Arduino Uno to drive SPI data to a peripheral circuit which, in this case, is an Analog Devices AD7376 digital potentiometer.  It could be any 8-bit SPI device using this circuit.

For this Instructables, I used an Arduino Uno board, a proto-board, some DIP (Dual Inline Package) switches (they are optional), a variety of jumper wires, a DC power supply, an ohm meter, a few capacitors for DC power supply smoothing, and a few pull-up resistors for the digital potentiometer.   The AD7376 digital potentiometer is a surface mount device so I soldered it onto a surface-mount proto-PCB so it could be plugged into the proto-board.  I used an oscilloscope to display the signals for this Instructables.
 
Remove these adsRemove these ads by Signing Up

Step 1:

Picture of
Assemble the Circuit: Place the Arduino board on the proto board in a convenient location.  Next insert the DIP switches with all the pins on one side connected to ground (these DIP switches will provide the 8 bits of data that will be read by the Arduino and then sent serially to the AD7376).  Wire digital pins 2 through 9 of the Arduino to the other side of the DIP switch, one wire per switch element.
mc3group7 months ago

In your code, there is an extra bracket that breaks the code:

count i

} // Otherwise leave it at 0
}
}//delete this brace, It is causing the code to fail in the compile process.
digitalWrite(10,LOW); // Drop SPI chip-select to 0 (Arduino pin 10)
SPI.transfer(pot); // Do SPI transfer of variable pot
digitalWrite(10,HIGH); // Raise chip-select to 1
delay(10000); // Delay loop 10 seconds (pick your time frame)
} // Data will be read and sent once every 10 seconds based on this

abovea1110 months ago
Hi!

May I know how do you modify inorder to output a 32bit?

Thank You!
Lcstyle11 months ago
Im using an arduino duemilanove to try to control a 14-TSSOP AD 7376, but no matter what it's just not acting right. I think I'm having an issue similar to this person: http://ww.wmrp.com/forum/viewtopic.php?t=50163&postdays=0&postorder=asc&start=15

But I cannot be sure.

Your code above shows 8 bits but doesnt the data sheet for the AD 7376 show only 7 bits? Also in my setup I am not reading digital pins I am instead setting the value of POT manually by changing the statement where you initialize POT as all 0 using a bit operator. Is this a problem? Example: byte pot = B0111111;