I2C interrupt question

Hi, I am planning on using a temp sensor and a port expander on the I2C lines, as well as some other chips. My question is, the PCF8574 and the CN75 have the ability to alert the controller when something is changed. I would like to use this interrupt capability. However I am unclear on how the Arduino will distinguish between which chips are sending the "alert". If I have 4 chips that will send an interrupt and I connect even two of them ( or all four) to pin 2 or 3 of Arduino, how will it know which one is sending the alert signal, so I can send a read message to the correct one?

Hi,
The answer is simple: you can't. Interrupts given by external hardware need to be connected to unique interrupt lines. Since those are scarce, the common method is to link the interrupt lines together and to read each device when an interrupt occurs. This is how it should be done:
connect PCF8574's pin 13 to pin 2 on the arduino. Use the function attachInterrupt(), see: http://arduino.cc/en/Reference/AttachInterrupt for details. Then use the wire library: Wire - Arduino Reference. Look for a wire example in your arduino IDE.

Basically your sketch should like this: (pseudocode)
setup(){
atach interrupt (2,readI2C)
pinmode (2,OUTPUT); //activate pullup resistor!
wire.begin()
}

loop(){
forever()//or do something useful..
}
void readI2C(){//this function is called on every interrupt
Wire.requestFrom(2, 1); // request 6 bytes from slave device #2
while(Wire.available()) // slave may send less than requested
{
char c = Wire.receive(); // receive a byte as character
Serial.print(c); // print the character
}
}

}

This code is not tested, but it should give you a good starting position
to write the program, Keep me posted on the results!


Not what I wanted to hear. Thanks Markohiero for killing my dreams. I'll let you know as I progress.

I can't see any reason why a pin change interrupt would not work. There are plenty of those available. :slight_smile:

Thanks coding badly. I didn't know that existed. Searched pin change and got a slew of examples Thanx.