Archived
1
0

rename PortIOE.ADDR to DEVICE_ADDR

This commit is contained in:
wolfv6 2016-09-03 14:25:22 -06:00
parent 0a1fd9772f
commit 5c8890312d
8 changed files with 18 additions and 18 deletions

View File

@ -13,14 +13,14 @@ AVR port classes do not need a similar class because PORTx is global in the Ardu
Instantiation Instantiation
------------ ------------
Example PortIOE::ADDR initilization: Example PortIOE::DEVICE_ADDR initilization:
const uint8_t PortIOE::ADDR = 0x18; const uint8_t PortIOE::DEVICE_ADDR = 0x18;
Be careful with the ADDR. Be careful with the DEVICE_ADDR.
Table 6 in PCA9655E datasheet lists 8-bit versions of I2C addresses. 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. 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, For example, I2C address with AD2=GND AD1=SCL AD0=SCL,
Table 6 lists 8-bit ADDR = 0x30 (b 00110000) Table 6 lists 8-bit DEVICE_ADDR = 0x30 (b 00110000)
while Arduino uses 7-bit ADDR = 0x18 (b 00011000) while Arduino uses 7-bit DEVICE_ADDR = 0x18 (b 00011000)
http://playground.arduino.cc/Main/WireLibraryDetailedReference http://playground.arduino.cc/Main/WireLibraryDetailedReference
The PCA9655E data sheet is on http://www.onsemi.com/pub_link/Collateral/PCA9655E-D.PDF 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 struct PortIOE
{ {
static const uint8_t ADDR; //I2C address static const uint8_t DEVICE_ADDR;
const uint8_t num; //port number const uint8_t num; //port number
uint8_t outputVal; //bitwise value of output register uint8_t outputVal; //bitwise value of output register

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? SPI.beginTransaction(SPISettings (SPI_CLOCK_DIV8, MSBFIRST, SPI_MODE0)); //control SPI bus todo is slow clock needed?
digitalWrite(SS, LOW); //enable Slave Select 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(port.num); //configure IODIR
SPI.transfer(readPins); //0=output (for LED), 1=input (for read) SPI.transfer(readPins); //0=output (for LED), 1=input (for read)
digitalWrite(SS, LOW); //enable Slave Select digitalWrite(SS, LOW); //enable Slave Select
digitalWrite(SS, HIGH); //disable 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(port.num + 0x0C); //configure GPPU
SPI.transfer(pullUp); //0=pull-up disabled (for LED), 1=pull-up enabled (for read) SPI.transfer(pullUp); //0=pull-up disabled (for LED), 1=pull-up enabled (for read)
digitalWrite(SS, HIGH); //disable Slave Select digitalWrite(SS, HIGH); //disable Slave Select
@ -45,7 +45,7 @@ uint8_t PortRead_MCP23S17::read()
uint8_t portState; //bit wise uint8_t portState; //bit wise
digitalWrite(SS, LOW); //enable Slave Select 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 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) portState = SPI.transfer(0); //save the data (0 is dummy data to send)
digitalWrite(SS, HIGH); //disable Slave Select digitalWrite(SS, HIGH); //disable Slave Select

View File

@ -10,7 +10,7 @@ PortRead_PCA9655E::PortRead_PCA9655E (PortIOE& port, const uint8_t readPins)
void PortRead_PCA9655E::begin() void PortRead_PCA9655E::begin()
{ {
Wire.beginTransmission(port.ADDR); Wire.beginTransmission(port.DEVICE_ADDR);
Wire.write(configurationByteCommand); Wire.write(configurationByteCommand);
Wire.write(readPins); //0=configure as output (for LED), 1=configure as input (for read) Wire.write(readPins); //0=configure as output (for LED), 1=configure as input (for read)
Wire.endTransmission(); Wire.endTransmission();
@ -21,11 +21,11 @@ returns port value
*/ */
uint8_t PortRead_PCA9655E::read() uint8_t PortRead_PCA9655E::read()
{ {
Wire.beginTransmission(port.ADDR); Wire.beginTransmission(port.DEVICE_ADDR);
Wire.write(inputByteCommand); //input immediately before requestFrom Wire.write(inputByteCommand); //input immediately before requestFrom
Wire.endTransmission(false); //PCA9655E needs false to send a restart 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(); return Wire.read();
} }

View File

@ -5,7 +5,7 @@
void PortWrite_MCP23S17::writePort(const uint8_t registerAddr, const uint8_t data) void PortWrite_MCP23S17::writePort(const uint8_t registerAddr, const uint8_t data)
{ {
digitalWrite(SS, LOW); //enable Slave Select 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(registerAddr); //register address to write data to
SPI.transfer(data); //data SPI.transfer(data); //data
digitalWrite(SS, HIGH); //disable Slave Select digitalWrite(SS, HIGH); //disable Slave Select

View File

@ -12,7 +12,7 @@ Otherwise readPins could be overwritten.
*/ */
void PortWrite_PCA9655E::begin() void PortWrite_PCA9655E::begin()
{ {
Wire.beginTransmission(port.ADDR); Wire.beginTransmission(port.DEVICE_ADDR);
Wire.write(configurationByteCommand); Wire.write(configurationByteCommand);
Wire.write(0); //0=configure as output (for strobe pins and LED) Wire.write(0); //0=configure as output (for strobe pins and LED)
Wire.endTransmission(); 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 port.outputVal |= pin; //set pin output to high
} }
Wire.beginTransmission(port.ADDR); Wire.beginTransmission(port.DEVICE_ADDR);
Wire.write(outputByteCommand); Wire.write(outputByteCommand);
Wire.write(port.outputVal); Wire.write(port.outputVal);
Wire.endTransmission(); Wire.endTransmission();

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_ON = HIGH; //active high
const bool Scanner_Port::STROBE_OFF = LOW; const bool Scanner_Port::STROBE_OFF = LOW;
const uint8_t PortIOE::ADDR = 0x18; const uint8_t PortIOE::DEVICE_ADDR = 0x18;
// ------------------ PORT 1 ------------------- // ------------------ PORT 1 -------------------
PortIOE port1_R(1, 0); PortIOE port1_R(1, 0);

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_ON = LOW;
const bool Scanner_Port::STROBE_OFF = HIGH; 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); PortIOE portB(1, 0);
PortRead_MCP23S17 portBRead(portB, ~0); PortRead_MCP23S17 portBRead(portB, ~0);

View File

@ -11,7 +11,7 @@ MCP23S17 on 3.3v does not output enough power to reliable light LEDs
#include "PortIOE.h" #include "PortIOE.h"
#include "PortWrite_MCP23S17.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); PortIOE portA(0, 0);
PortWrite_MCP23S17 portAWrite(portA); //PortAWrite needed for begin() PortWrite_MCP23S17 portAWrite(portA); //PortAWrite needed for begin()