I am trying to program a digital resistor and set it's wiper resistance. The general circuit looks a little like this where "pot" represents the Maxim DS1801 digital resistor and DUE is, of-course the 3.3v Arduino DUE.
POT DUE
CLk ----> SCK
D ----> MOSI
RST ----> CS (ChipSelect) (PIN10)
Now so far, I have sucessfully been able to interface with the DS1801, but I am having issues determining how to properly set the wiper resistance values. The DS1801 datasheet says the it accepts a 16bit input and from application example online it looks like the values range from 0 to 64. Here is my 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);
}
I THINK my issue lies with setting the clock rate for the DS1801. The data sheet say the chip runs at 10MHz which is why I wrote
SPI.setClockDivider(slaveSelectPin,SPI_CLOCK_DIV8);
to divide the 84MHz default speed down to 10MHz.
Anyone have suggestions on why my code is not working??? At the moment, I have LED's connected to chip with series resistors to limit current below 2mA. The resistors just blink randomly with the code posted above.