Go Down

Topic: Using the DS1803 digital pot. (Read 3277 times) previous topic - next topic

xSmurf

Hello, I'm trying to interface a DS1803 I2C digital pot without much luck :/
It looks like I'm just writing/reading back the buffer when I communicate with it.
I don't understand why, the address is properly set. And the I2C bus works, I have another device (PCF8574) on it.
If you guys have any idea....

These are the read/write function I'm using. As usual the read address is write+1.
As far as I can see from the datasheet the registers are none looping.
When I write a value and read back, the first is the register address instead of the first byte of data.

Code: [Select]

Void DS1803::setValue(uint8_t value)
{
     Wire.beginTransmission(DPOT_ADDRESS_W);
     Wire.send(DPOT_WIPERS); // Send the wiper address
     
     Wire.send(value);
     
     Wire.endTransmission();
}

uint8_t DS1803::getValue()
{
     Wire.requestFrom(DPOT_ADDRESS_R, 2);
     
     while (Wire.available()) {
           Serial.println((uint8_t)Wire.receive(), DEC);
     }
     
     return 0;
}
"Pilots believe in a clean living... they never drink wisky from a dirty glass."

xSmurf

Got it! Ok so apparently the datasheet gave the address as a 7bit address and I was reading it as an 8bit address. I should have been using 0x28 instead of 0x50... but the fun part is how I figured it out. As someone on IRC suggested I tapped into the twi library and wrote an I2C scanner. Here's the code:

Code: [Select]

void scanTWI(void)
{
     Wire.begin();
     
     int ii;
     uint8_t *txBuffer;
     
     for (ii=1;ii<128;ii++)
     {
           twi_writeTo(ii, txBuffer, 0, 1);
           
           if (twi_isFound())
           {
                 Serial.println(ii, HEX);
           }
     }
     Serial.println();
}


I also had to apply the following modification to the twi.c file:
Code: [Select]

312a313,324
> int foundDevice = 0;
> int twi_isFound(void)
> {
>       if (foundDevice)
>       {
>               foundDevice = 0;
>               return 1;
>       }
>
>       return 0;
> }
>
325a338,340
>       {
>               foundDevice = 1;
>       }


It's probably terrible code, but as a patch, it works. The question is why isn't something like this in the library? It would be very useful! IMHO at least.

Hope this helps others
"Pilots believe in a clean living... they never drink wisky from a dirty glass."

xSmurf

#2
Oct 13, 2007, 03:12 am Last Edit: Oct 13, 2007, 03:20 am by xSmurf Reason: 1
You can also do the following:

Add this to the public functions in Wire.h
Code: [Select]

bool checkAddress(uint8_t);


And this in Wire.cpp
Code: [Select]

bool TwoWire::checkAddress(uint8_t twiAddress)
{
     uint8_t *txBuffer;
     twi_writeTo(twiAddress, txBuffer, 0, 1);
     twi_isFound();
}


You can now easily check an address by doing Wire.checkAddress(address). w00t  :D
"Pilots believe in a clean living... they never drink wisky from a dirty glass."

xSmurf

I also added this to the Wire.h so I can detect the mod:

Code: [Select]

#define WIRE_LIB_SCAN_MOD
"Pilots believe in a clean living... they never drink wisky from a dirty glass."

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy