The following sketch is intended to test pca9655e I/O expander response from I2C.
It's supposed to write to the I/O expander's output register, read the contents of the output register, and then print it.
But it's not working as expected.
Expected results:
change register values to 0
register_3 = 00000000
change register values to 1
register_3 = 11111111
Actual results on breadboard:
change register values to 0
register_3 = 11111111
change register values to 1
register_3 = 11111111
Breadboard pictures:
Breadboard setup:
Teensy 2.0 connected to PCA9655E I/O expander via I2C
4.7K pull-up resistors on SDA and SCL
Pin assignment diagram for PCA9655E I/O expander:
INT 1 24 VDD +5v yellow and 0.1 uF capacitor to ground
SCL AD1 2 23 SDA SDA green
GND AD2 3 22 SCL SCL red
IO0_0 4 21 AD0 SCL white wires on ADs
IO0_1 5 20 IO1_7
IO0_2 6 19 IO1_6
IO0_3 7 18 IO1_5
IO0_4 8 17 IO1_4
IO0_5 9 16 IO1_3
IO0_6 10 15 IO1_2
IO0_7 11 14 IO1_1
GND VSS 12 13 IO1_0
The PCA9655E has 5v between VSS and VDD.
Good continuity from the I/O expander to breakout pins.
A logic analyzer shows a signal on SCL and SDA.
Why does the sketch not print "register_3 = 00000000"?
Maybe something is wrong with the code? What else can I trouble shoot?
PCA9655E I/O expander datasheet is on: http://www.onsemi.com/pub_link/Collateral/PCA9655E-D.PDF
pca9655e_print_register.ino sketch:
#include "Wire.h" //http://arduino.cc/en/Reference/Wire
const uint8_t ADDR = 0x30; //PCA9655E I2C address with AD2=GND AD1=SCL AD0=SCL
void printRegister(uint8_t regist)
{
uint8_t value;
Wire.beginTransmission(ADDR);
Wire.write(regist); //write command byte of register
Wire.endTransmission(false); //PCA9655E needs false to send a restart
Wire.requestFrom(ADDR, static_cast<uint8_t>(regist)); //request one byte from register
value = Wire.read();
Serial.print("\nregister_");
Serial.print(regist);
Serial.print(" = ");
Serial.print(value, BIN);
}
void setup()
{
Wire.begin();
// turn off outputs so that output ports don't get burned
Wire.beginTransmission(ADDR);
Wire.write(6); //configure port_0 direction
Wire.write(~0); //as input with pull-up
Wire.endTransmission();
Wire.beginTransmission(ADDR);
Wire.write(7); //configure port_1 direction
Wire.write(~0); //as input with pull-up
Wire.endTransmission();
Serial.print("\n\nchange register values to 0");
Wire.beginTransmission(ADDR);
Wire.write(3); //set register_3
Wire.write(0);
Wire.endTransmission();
printRegister(3); //expect register_3 = 00000000
Serial.print("\n\nchange register values to 1");
Wire.beginTransmission(ADDR);
Wire.write(3); //set register_3
Wire.write(~0);
Wire.endTransmission();
printRegister(3); //expect register_3 = 11111111
}
void loop() { }