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.

Step 1:

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.
<p>I used this code with my arduino board to control an SPI device but faced a small problem. I am transferring only one byte at a time. The chip select remains low for much longer period after the data transfer is complete, especially at higher clock rates. Is there a way to make CS high immediately high after completion of data transfer</p>
<p>In your code, there is an extra bracket that breaks the code:</p><p>count i</p><p> } // Otherwise leave it at 0<br> }<br>}//delete this brace, It is causing the code to fail in the compile process.<br> digitalWrite(10,LOW); // Drop SPI chip-select to 0 (Arduino pin 10)<br> SPI.transfer(pot); // Do SPI transfer of variable pot<br> digitalWrite(10,HIGH); // Raise chip-select to 1<br> delay(10000); // Delay loop 10 seconds (pick your time frame)<br>} // Data will be read and sent once every 10 seconds based on this</p>
Hi! <br> <br>May I know how do you modify inorder to output a 32bit? <br> <br>Thank You!
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&amp;postdays=0&amp;postorder=asc&amp;start=15 <br> <br>But I cannot be sure. <br> <br>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;

About This Instructable




More by saratogadude:Controlling the Inrush Current Required by Large Transformers Generating Gcode for ShopBot from AutoCAD file using Vectric Cut 2D Make a 1-2 uH Output Air Core Inductor for Audio Amplifier 
Add instructable to: