Daisy Chaining AD5204 Digital Potentiometers

I’m using an Arduino to control two (maybe more – I haven’t tried yet) AD5204 digital potentiometers. Here’s some info about adapting the digital pot Arduino example to work with daisy chaining.

These 4-channel digital potentiometers are controlled via SPI. If you look in the Arduino SPI examples, you’ll see one that works with the 6-channel version of these chips (AD5206). It’s easy to adapt that example to the AD5204 – just change the 6 to a 4 in the loop that cycles through the channels. You should also know that the 4-channel version has some different hookup requirements. You’ll need to make sure that the /PR and /SHDN pins are held high or it will freak out.

Once you’ve got one AD5204 working, using that example sketch as a starting point, you can try daisy chaining two of them together. The AD5204 has a serial data output pin (SDO) that passes data from the first chip on to the second one in the daisy chain. This pin needs a pull-up resistor, by the way. 10K ohms works fine. Once you’ve got them wired together properly, it’s time to look at the code again.

From looking at the datasheet, you can see that one chip alone is expecting this kind of message from the microcontroller via SPI:

11 bits of data for controlling a single AD5204

The first 3 bits are the address of the channel that you’re trying to change. The rest is the step that you want that channel to switch to (it’s an 8-bit number, so the steps are from 0 to 255)

If you look back at the sample Arduino code, you’ll see that they aren’t actually sending that to the chip – mainly because the SPI library only allows you to send 8 bits (aka 1 byte) at a time.. not 11. So the sample code ends up looking like this:

Example Arduino code for sending an SPI message to one AD5204

Not ideal, since it’s 16 bits instead of 11. The chip seems to be okay with this though.

When you’re trying to daisy chain the chips together, you’re supposed to hold the chip select (CS) pin low while you send TWO 11 bit messages over:

Two 11 bit SPI messages for the AD5204

Now the question is, if we’re only able to send 8 bit messages at a time with the SPI.transfer() function, what do we do now that the chip is asking for two 11 bit messages back to back? Answer:

Code for daisy chained AD5204s

Modify the original digital pot Arduino example to do the above, between the lines that select and deselect the chip (where it writes slaveSelectPin LOW, then HIGH), and you’re done. (Sorry for the long-winded explanation, when that picture would probably have been enough for most people who are looking for this information) :)

Good luck