diff --git a/src/PortIOE.h b/src/PortIOE.h index 3406e7a..83152a1 100644 --- a/src/PortIOE.h +++ b/src/PortIOE.h @@ -13,14 +13,14 @@ AVR port classes do not need a similar class because PORTx is global in the Ardu Instantiation ------------ -Example PortIOE::ADDR initilization: - const uint8_t PortIOE::ADDR = 0x18; -Be careful with the ADDR. +Example PortIOE::DEVICE_ADDR initilization: + const uint8_t PortIOE::DEVICE_ADDR = 0x18; +Be careful with the DEVICE_ADDR. Table 6 in PCA9655E datasheet lists 8-bit versions of I2C addresses. The Arduino Wire library uses 7-bit addresses throughout, so drop the low bit. For example, I2C address with AD2=GND AD1=SCL AD0=SCL, - Table 6 lists 8-bit ADDR = 0x30 (b 00110000) - while Arduino uses 7-bit ADDR = 0x18 (b 00011000) + Table 6 lists 8-bit DEVICE_ADDR = 0x30 (b 00110000) + while Arduino uses 7-bit DEVICE_ADDR = 0x18 (b 00011000) http://playground.arduino.cc/Main/WireLibraryDetailedReference The PCA9655E data sheet is on http://www.onsemi.com/pub_link/Collateral/PCA9655E-D.PDF @@ -39,7 +39,7 @@ Example instantiation for portB with active high rows on pins 0,1,2: */ struct PortIOE { - static const uint8_t ADDR; //I2C address + static const uint8_t DEVICE_ADDR; const uint8_t num; //port number uint8_t outputVal; //bitwise value of output register diff --git a/src/PortRead_MCP23S17.cpp b/src/PortRead_MCP23S17.cpp index a4e65fc..d7e2b44 100644 --- a/src/PortRead_MCP23S17.cpp +++ b/src/PortRead_MCP23S17.cpp @@ -22,13 +22,13 @@ void PortRead_MCP23S17::begin(const uint8_t strobeOn) SPI.beginTransaction(SPISettings (SPI_CLOCK_DIV8, MSBFIRST, SPI_MODE0)); //control SPI bus todo is slow clock needed? digitalWrite(SS, LOW); //enable Slave Select - SPI.transfer(port.ADDR << 1); //write command + SPI.transfer(port.DEVICE_ADDR << 1); //write command SPI.transfer(port.num); //configure IODIR SPI.transfer(readPins); //0=output (for LED), 1=input (for read) digitalWrite(SS, LOW); //enable Slave Select digitalWrite(SS, HIGH); //disable Slave Select - SPI.transfer(port.ADDR << 1); //write command + SPI.transfer(port.DEVICE_ADDR << 1); //write command SPI.transfer(port.num + 0x0C); //configure GPPU SPI.transfer(pullUp); //0=pull-up disabled (for LED), 1=pull-up enabled (for read) digitalWrite(SS, HIGH); //disable Slave Select @@ -45,7 +45,7 @@ uint8_t PortRead_MCP23S17::read() uint8_t portState; //bit wise digitalWrite(SS, LOW); //enable Slave Select - SPI.transfer(port.ADDR << 1 | 1); //read command + SPI.transfer(port.DEVICE_ADDR << 1 | 1); //read command SPI.transfer(port.num + 0x12); //GPIO register address to read data from portState = SPI.transfer(0); //save the data (0 is dummy data to send) digitalWrite(SS, HIGH); //disable Slave Select diff --git a/src/PortRead_PCA9655E.cpp b/src/PortRead_PCA9655E.cpp index 8c11529..9d4ddeb 100644 --- a/src/PortRead_PCA9655E.cpp +++ b/src/PortRead_PCA9655E.cpp @@ -10,7 +10,7 @@ PortRead_PCA9655E::PortRead_PCA9655E (PortIOE& port, const uint8_t readPins) void PortRead_PCA9655E::begin() { - Wire.beginTransmission(port.ADDR); + Wire.beginTransmission(port.DEVICE_ADDR); Wire.write(configurationByteCommand); Wire.write(readPins); //0=configure as output (for LED), 1=configure as input (for read) Wire.endTransmission(); @@ -21,11 +21,11 @@ returns port value */ uint8_t PortRead_PCA9655E::read() { - Wire.beginTransmission(port.ADDR); + Wire.beginTransmission(port.DEVICE_ADDR); Wire.write(inputByteCommand); //input immediately before requestFrom Wire.endTransmission(false); //PCA9655E needs false to send a restart - Wire.requestFrom(port.ADDR, 1u); //request one byte from input port + Wire.requestFrom(port.DEVICE_ADDR, 1u); //request one byte from input port return Wire.read(); } diff --git a/src/PortWrite_MCP23S17.cpp b/src/PortWrite_MCP23S17.cpp index 81c461a..6d48ce2 100644 --- a/src/PortWrite_MCP23S17.cpp +++ b/src/PortWrite_MCP23S17.cpp @@ -5,7 +5,7 @@ void PortWrite_MCP23S17::writePort(const uint8_t registerAddr, const uint8_t data) { digitalWrite(SS, LOW); //enable Slave Select - SPI.transfer(port.ADDR << 1); //write command + SPI.transfer(port.DEVICE_ADDR << 1); //write command SPI.transfer(registerAddr); //register address to write data to SPI.transfer(data); //data digitalWrite(SS, HIGH); //disable Slave Select diff --git a/src/PortWrite_PCA9655E.cpp b/src/PortWrite_PCA9655E.cpp index 85909fb..2e1677f 100644 --- a/src/PortWrite_PCA9655E.cpp +++ b/src/PortWrite_PCA9655E.cpp @@ -12,7 +12,7 @@ Otherwise readPins could be overwritten. */ void PortWrite_PCA9655E::begin() { - Wire.beginTransmission(port.ADDR); + Wire.beginTransmission(port.DEVICE_ADDR); Wire.write(configurationByteCommand); Wire.write(0); //0=configure as output (for strobe pins and LED) Wire.endTransmission(); @@ -35,7 +35,7 @@ void PortWrite_PCA9655E::write(const uint8_t pin, const bool value) port.outputVal |= pin; //set pin output to high } - Wire.beginTransmission(port.ADDR); + Wire.beginTransmission(port.DEVICE_ADDR); Wire.write(outputByteCommand); Wire.write(port.outputVal); Wire.endTransmission(); diff --git a/tutorials/keybrd_4c_split_with_IOE/keybrd_4c_split_with_IOE.ino b/tutorials/keybrd_4c_split_with_IOE/keybrd_4c_split_with_IOE.ino index 656f571..26b609d 100644 --- a/tutorials/keybrd_4c_split_with_IOE/keybrd_4c_split_with_IOE.ino +++ b/tutorials/keybrd_4c_split_with_IOE/keybrd_4c_split_with_IOE.ino @@ -39,7 +39,7 @@ uint8_t readPins[] = {14, 15}; const bool Scanner_Port::STROBE_ON = HIGH; //active high const bool Scanner_Port::STROBE_OFF = LOW; -const uint8_t PortIOE::ADDR = 0x18; +const uint8_t PortIOE::DEVICE_ADDR = 0x18; // ------------------ PORT 1 ------------------- PortIOE port1_R(1, 0); diff --git a/unit_tests/PortRead_MCP23S17/PortRead_MCP23S17.ino b/unit_tests/PortRead_MCP23S17/PortRead_MCP23S17.ino index 936a23f..1886c50 100644 --- a/unit_tests/PortRead_MCP23S17/PortRead_MCP23S17.ino +++ b/unit_tests/PortRead_MCP23S17/PortRead_MCP23S17.ino @@ -14,7 +14,7 @@ http://arduino.stackexchange.com/questions/28792/reading-an-mcp23s17-i-o-expande const bool Scanner_Port::STROBE_ON = LOW; const bool Scanner_Port::STROBE_OFF = HIGH; -const uint8_t PortIOE::ADDR = 0x20; //MCP23S17 address, all 3 ADDR pins are grounded +const uint8_t PortIOE::DEVICE_ADDR = 0x20; //MCP23S17 address, all 3 ADDR pins are grounded PortIOE portB(1, 0); PortRead_MCP23S17 portBRead(portB, ~0); diff --git a/unit_tests/PortWrite_MCP23S17/PortRead_MCP23S17.ino b/unit_tests/PortWrite_MCP23S17/PortRead_MCP23S17.ino index 2901f5e..dc4cb3f 100644 --- a/unit_tests/PortWrite_MCP23S17/PortRead_MCP23S17.ino +++ b/unit_tests/PortWrite_MCP23S17/PortRead_MCP23S17.ino @@ -11,7 +11,7 @@ MCP23S17 on 3.3v does not output enough power to reliable light LEDs #include "PortIOE.h" #include "PortWrite_MCP23S17.h" -const uint8_t PortIOE::ADDR = 0x20; //MCP23S17 address, all 3 ADDR pins are grounded +const uint8_t PortIOE::DEVICE_ADDR = 0x20; //MCP23S17 address, all 3 ADDR pins are grounded PortIOE portA(0, 0); PortWrite_MCP23S17 portAWrite(portA); //PortAWrite needed for begin()