This is more of I/O expander question than a Teensy question. Please tell me if there is a better place to post this question.
I read some I/O expander tutorials and the datasheet but am still easily surprised by I/O expander behavior.
This is the most resent surprise:
A PCA9655E I/O expander is connected to a Teensy 2.0 via I2C.
PCA9655E I/O expander is on the left and Teensy 2.0 on the right:
There is nothing connected to the PCA9655E port pins.
When I run the sketch:
There is nothing connected to the port pins.
Output:
I am using Teensy 2.0, Arduino 1.0.6, and Teensyduino 1.20.
The PCA9655E data sheet is on http://www.onsemi.com/pub_link/Collateral/PCA9655E-D.PDF
Wire class is on http://arduino.cc/en/Reference/Wire
Thank you.
I read some I/O expander tutorials and the datasheet but am still easily surprised by I/O expander behavior.
This is the most resent surprise:
A PCA9655E I/O expander is connected to a Teensy 2.0 via I2C.
PCA9655E I/O expander is on the left and Teensy 2.0 on the right:
There is nothing connected to the PCA9655E port pins.
When I run the sketch:
1110 is output to port 0.
1110 is read from port 1.
How did data get from port 0 to port 1?1110 is read from port 1.
There is nothing connected to the port pins.
Code:
#include "Wire.h"
const uint8_t ADDR = 0x20; //PCA9655E I2C address with AD2 AD1 AD0 grounded
void setup()
{
Wire.begin();
//configure output
Wire.beginTransmission(ADDR);
Wire.write(6); //command byte 6: configure port 0
Wire.write(B00000000); //0=output, 1=input with pullup
Wire.endTransmission();
//configure input
Wire.beginTransmission(ADDR);
Wire.write(7); //command byte 7: configure port 1
Wire.write(B11111111); //0=output, 1=input with pullup
Wire.endTransmission();
}
void loop()
{
//output
Wire.beginTransmission(ADDR);
Wire.write(2); //command byte 2: output port 0
Wire.write(B00001110); //0=low, 1=high
Wire.endTransmission();
//input to read
Wire.beginTransmission(ADDR);
Wire.write(1); //command byte 1: input port 1
Wire.endTransmission();
//read input
Wire.requestFrom(ADDR, static_cast<uint8_t>(1)); //request one-byte read
//display read
Serial.print("\nport1 = "); //port1 = 1110
Serial.print(Wire.read(), BIN);
while (true) {}
}
Code:
port1 = 1110
The PCA9655E data sheet is on http://www.onsemi.com/pub_link/Collateral/PCA9655E-D.PDF
Wire class is on http://arduino.cc/en/Reference/Wire
Thank you.