Browse Source

rename PortIOE.ADDR to DEVICE_ADDR

tags/v0.6.0
wolfv6 7 years ago
parent
commit
5c8890312d

+ 6
- 6
src/PortIOE.h View File

@@ -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

+ 3
- 3
src/PortRead_MCP23S17.cpp View File

@@ -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

+ 3
- 3
src/PortRead_PCA9655E.cpp View File

@@ -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();
}

+ 1
- 1
src/PortWrite_MCP23S17.cpp View File

@@ -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

+ 2
- 2
src/PortWrite_PCA9655E.cpp View File

@@ -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();

+ 1
- 1
tutorials/keybrd_4c_split_with_IOE/keybrd_4c_split_with_IOE.ino View File

@@ -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);

+ 1
- 1
unit_tests/PortRead_MCP23S17/PortRead_MCP23S17.ino View File

@@ -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);

+ 1
- 1
unit_tests/PortWrite_MCP23S17/PortRead_MCP23S17.ino View File

@@ -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()