If I wanted to use barebones 168's for IO expansion over i2c I want to know how to address more than 7 slaves without a MUX. The i2c protocol allows for up to 128 addresses (I think only 112 are usable) but this requires 7 pins (or a software programmable address). Every example I've seen of setting the address only shows 3 pins to GND for addressing. Meaning a maximum of 7 addresses without a MUX. What gives?
The 168 is from the ATmega386 family, but has less memory.
A Slave is started with Wire.begin ( i2cAddress ) ;
The i2cAddress can be anything, that is up to your sketch. If you want many Slaves, you can use 7 pins, it is how you write the sketch.
Thanks for the reply Koepel.
Let me try to explain a little better. I know how the Master initiates a read/write to a slave, but each slave on the i2c bus must have a unique hardware address (or node number if you will). The I2C protocol employs a 7 bit addressing scheme (it's actually an 8bit address but the LSB is not used for the actual address). 7 bits = 128 unique addresses that can exist and be addressed on i2c in theory without a mux.
Yet the MCP23008 and the Atmega168 have the 4 MSB of the address FIXED and only allow you to vary the 3 LSB on the IC, effectively limiting you to 8 slaves.
For example:
the PCA8574 and PCA8574A are identical 8 bit port expanders. Both are 3 bit addressable but have different FIXED portions of the address. So one may have a fixed address portion of 1011 and leave the last 3 up to you to choose by grounding one or more of those pins.
The other may have a fixed address portion of 1001 and also leave the last 3 up to you.
So you could have 1011 + (any of 8 combinations of 111) on one chip
and 1001 + (any of 8 combinations of 111) on the other. This means you could have up to 8 8574's and up to 8 8574A's. because of the different fixed portion of the address.
The Atmega168 also fixes the first 4 bits of the i2c address and allows you to choose any one of 8 possible addresses with the remaining 3 pins.
But the fact remains that i2c supports up to 128 addresses (nodes) and the port expander chips are preventing us from addressing more than 8 by fixing the first four bits of the address. Is there a workaround for this besides multiplexing? Is there another IC manufacturer that makes a fully addressable port expander so one could overcome the arbitrary 8 node limit?
The ATmega168 does not fix anything. It is how you write the sketch. You can use any address, although I would avoid address 0.
If you want 7 pins for the address, then use 7 pins. Why are you looking at other chips that have only 3 pins for the address ?
This is an example, not tested.
const int myAddressPins[] = { 2, 3, 4, 5, 6, 7, 8 };
int myAddress = 0;
void setup()
{
for( i=0; i<7; i++)
{
if( digitalRead( myAddressPins[i]) == HIGH)
{
bitSet( myAddress, i);
}
}
Wire.begin(myAddress);
}