How to interface with Maxim 3 wire SPI on the Arduino Due?

Hello! I am a complete beginner and just picked up an Arduino Due with the SAM3x 3.3v chip. I am attempting to communicate with the Maxim DS1801 Digital potentiometer to control an amplifier's volume level but I have no clue how to go about hooking up the 3 wire SPI connection. If I am correct doesn't the Arduino use a 4 wire set up??

I have seen that it is possible from links like this but to be honest with you I don't understand it. Can someone break it down for me and tell me exactly where to plug in the pins for D, RESET(bar), and CLK on the DS1801 into the Arduino Due??

I can see in the datasheet that the DS1801 has a 16 bit interface and that the upper 8 bits set the left wiper resistance and the bottom 8 bits set the right wiper resistance but I am confused on where to plug in the SPI connections. If I had to guess I would just plug them like so:

D ---> MOSI
clk --->SCL
reset ---> SS??

but then what about MISO? and what is the function of SDA, do I just leave them unconnected??

Also, will the arduino SPI interface code work with a 3 wire interface?

It's 3-wire serial and not SPI.

You could probably use some SPI functions to send the data which it is expecting but I'm not sure, without spending an hour reading the datsheet.

If you can't find a library specific to this chip and you can't find a library specific to 3-wire serial then it doesn't look too hard to bit-bang the protocol yourself with lots of digitalWrite()s.

It will be like using SPI, but with a High chip select instead of low.

digitalWrite (rstPin, HIGH);
SPI.transfer(channel1data);
SPI.transfer(channel2data);
digitalWrite (rstPin, LOW);

Library indeed.

And you've tested that with one of these chips, Crossroads?

Well, I DID get the chip to do stuff....

I ended up making the following connections:

POT DUE

CLk ----> SCK
D ----> MOSI
RST ----> CS (PIN10)

I hooked up an led to the digital resistor so I could easily visualize the output and I put a 330ohm resistor on the ground of the led in series so I would not draw too much current. I can get the leds to do stuff but its not working as I expect.

I should be able to send the chip a value from 0 to 63 (64 is mute) and get the led's to fade from off to on, but I can't do that. Here is the code:

// include the SPI library:
#include <SPI.h>


// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 10;
int mute = 64;
int loud = 63;
int soft = 0;

void setup() {
  // set the slaveSelectPin as an output:
  pinMode (slaveSelectPin, OUTPUT);
  // initialize SPI:
  SPI.setBitOrder(LSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(slaveSelectPin,SPI_CLOCK_DIV8);
  SPI.begin(); 
  delay(10);
   digitalPotWrite(mute, mute);
}

void loop() {
  
  // Raise the volume from off to loud
for(int i = 0; i <= 63; i++){
  digitalPotWrite(i, i);
  delay(5);
    }
  }

void digitalPotWrite(int left, int right) {
  // take the SS pin low to select the chip:
  digitalWrite(slaveSelectPin, HIGH);
  //  send in the address and value via SPI:
  SPI.transfer(left);
  SPI.transfer(right);
  // take the SS pin high to de-select the chip:
  digitalWrite(slaveSelectPin, LOW);
}

Any suggestions!?

I think this might have something to do with the chips clock speed? the datasheet says it runs at 10MHz which is why I added SPI.setClockDivider(slaveSelectPin,SPI_CLOCK_DIV8);

That way I can get 10MHz from the normal 84MHz (for the Due) but that does not seem to work either. What happens is the LEDs blink randomly with different intensity, it is kind of cool, but not my intentions.

Here are some photos of the set-up....
Any thoughts on why the LEDs can't be set using the code I wrote?? :slightly_frowning_face:

As you can see in the second photo, the LED's basically just blink from the resistance of the digipot fluctuating on each set cycle of the loop...

OK, first potential problem: pin 10 is special for SPI. Since we're not driving real SPI, I would not use it.

Second, and possibly the real problem, the max wiper current on that chip is 1mA. (Thanks for the link to the datasheet.) It can't drive an LED. It's probably flashing because the chip is going into a shutdown or protection mode. Just measure it with a multimeter.

Got it working!! So if you look at my pictures, you'll note that AGND, the "analog ground" was NOT connected! Go figure, the code works nicely now!!

In addition to the AGND issue, it looks like you MUST put a delay between successive digital pot writes so that you can give the chip time to react. If you bombard it with write operations, it just basically gives up! :roll_eyes:

Also, good point on the current draw... I am using 680 ohm current limiting resistors on the led grounds. I was using 380 I believe but I upped them... That is limiting my current to under 1mA, so I am good. This is just a visual test anyway, I am going to use this to interface with buttons and control volume.

..ohh, as per your advice, I also switched the green wire over to digital pin 13...