I have the following digital potentiometer: DS1803-100 which, according to the datasheet, can be controlled using a two-wire serial interface. I have managed to get it working using Wire, however I can't seem to get it working using only digitalWrite (link to code). Can somebody tell me why? For reference, 0x50 is the address + r/!w bit, 0xA9 is the command (write to pot 0 in my case) and the next 0xA9 is the value to write. I know there's something wrong with the code, however I cannot figure out what. Thank you in advance!
EDIT: Here is the code
int PIN_SCK = 12;
int PIN_SDA = 11;
const int delayvalue = 10;
void setup(){
digitalWrite(PIN_SCK, 1); // I can first declare the state
digitalWrite(PIN_SDA, 1);
pinMode(PIN_SCK, OUTPUT); // then turn them on
pinMode(PIN_SDA, OUTPUT);
delay(1000);
digitalWrite(PIN_SDA, 0); // start bit
shift_out(PIN_SDA, PIN_SCK, 0x50);
shift_out(PIN_SDA, PIN_SCK, 0xA9);
shift_out(PIN_SDA, PIN_SCK, 0xA9);
digitalWrite(PIN_SDA, 1); // stop bit
}
void loop(){
}
// uint8_t is the same as 8 bits aka one byte
void shift_out(uint8_t datapin, uint8_t clockpin, uint8_t val){
uint8_t i;
for (i = 0; i < 8; i++) {
digitalWrite(datapin, !!(val & (1 << (7 - i))));
delay(1);
digitalWrite(clockpin, 0);
delay(delayvalue);
digitalWrite(clockpin, 1);
delay(delayvalue);
}
digitalWrite(datapin, 0); // to enable stop bit
delay(100); // wait fro aknowledgement
}