Help setting I2C address on MCP23008

I'm using an MCP23008 as a port expander. I have A0, A1, & A2 set to ground. What would be the I2C address for this setting? I thought it would be 0X20 but that is not working. Can someone point me to some help with addressing.

If I'm not mistaken you always do a shift to the datasheet adress's, but I'm not sure if its a left or a right one, so try either the 0x10 adress and the 0x40 ones, but I think its the first one.

See page 6 of the datasheet. It shows the addressing as:

0 1 0 0 A2 A1 A0 RW

Now since you don’t pre-shift the address (the I2C library does that and or’s in the read/write bit), that translates to 0100xxx where xxx are the jumpers, in your case 0, so:

0100000

That is 0x20.

Code from twi.c shows how the shifting is done in the library:

void twi_setAddress(uint8_t address)
{
  // set twi slave address (skip over TWGCE bit)
  TWAR = address << 1;
}

So if it’s “not working” we need more details. Did you use pull-up resistors? What is your code? How long is the wiring run? How is it wired up? How do you know it is not working?

From the Arduino reference for the Wire Library:

There are both 7- and 8-bit versions of I2C addresses. 7 bits identify the device, and the eighth bit determines if it's being written to or read from. The Wire library uses 7 bit addresses throughout. If you have a datasheet or sample code that uses 8 bit address, you'll want to drop the low bit (i.e. shift the value one bit to the right), yielding an address between 0 and 127.

http://arduino.cc/en/Reference/Wire

Lefty

If you do I2C a must have tool is the I2C bus scanner - http://todbot.com/blog/2009/11/29/i2cscanner-pde-arduino-as-i2c-bus-scanner/ it will give you all the device addresses on the bus.

Thanx for all the replies. This is a relay board and I was not getting output to the individual relays. I’m not using pullup resistors as by cable is only about 6 inches for testing. On further investigation I found leakage on the board from 5V to ground that I haven’t been able to correct so I’ll address that issue tomorrow.

BTW, thanx for the I2C address scanner, it works like a charm. The address was set correctly.