View previous topic :: View next topic |
Author |
Message |
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
PCF8574 can't get the interrupt |
Posted: Sun Dec 19, 2004 3:05 am |
|
|
Okay, this is another question about the venerable PCF8574 I2C I/O expander.
My PCF8574 is running 6 buttons (each with a 4.7k pullup) and 2 LEDs (current source). Here's the code I use to initialize the PCF8574:
Code: |
#define BUTTONS_ADDR 0x40 // i2c write address of the PCF8574 i/o expander
#define I2CWRITE 0x00
#define I2CREAD 0x01
#define LED_TEMP 0x40
#define LED_CURRENT 0x80
#define BTN_TEMP 0x04
#define BTN_CURRENT 0x08
#define BTN_DEC 0x02
#define BTN_INC 0x01
#define BTN_CUT 0x10
#define BTN_ABLATE 0x20
#define BTN_ALL 0x3F
void i2c_init(int8 iAddr)
{
int8 i; // loop counter
i = 0;
do
{
i2c_start();
++i;
}
while (i < I2C_TIMEOUT && i2c_write(iAddr) == 1); // 0 returned for ACK
if (i >= I2C_TIMEOUT)
{
coma(); // I2C bus timed out => disable the device
}
}
// somewhere in the main...
i2c_init(BUTTONS_ADDR | I2CWRITE);
i2c_write(LED_TEMP | LED_CURRENT);
i2c_stop();
i2c_init(BUTTONS_ADDR | I2CWRITE);
i2c_write(BTN_ALL); // keep inputs as inputs
i2c_stop();
|
After I run this INT# line remains low, when none of the buttons are pressed. What am I doing wrong?
Thanks,
Nick |
|
![](templates/subSilver/images/spacer.gif) |
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
Posted: Sun Dec 19, 2004 2:33 pm |
|
|
Here's additional info I gathered. If I want to use INT# line on the PCF8574, I have to make all i/o lines inputs. If I drive any of the i/o lines low I get the interrupt.
I have 2 choices:
1. Use PCA9554, which is pin-for-pin compatible with PCF8574. PCA9554 is truly bidirectional as opposed to quasi bidirectional PCF8574. Arrow carries them in all available packages except DIP. Does anyone know wehere to get PCA9554 in DIP?
2. Poll the buttons.
Nick |
|
![](templates/subSilver/images/spacer.gif) |
Kenny
Joined: 07 Sep 2003 Posts: 173 Location: Australia
|
|
Posted: Sun Dec 19, 2004 9:34 pm |
|
|
A venerable chip indeed, also second-sourced by TI these days.
You can use the PCF8574 for your particular application.
See pages 8 and 9 of the following for an explanation of why INT isn't asserted by a write:
http://focus.ti.com/lit/an/scpa032/scpa032.pdf
Do a read in the initialisation to clear any unhandled interrupt state, similar to the case when using the interrupt-on-change feature of portb on pics. |
|
![](templates/subSilver/images/spacer.gif) |
|