2016-09-25 03:03:08 +00:00
|
|
|
#include "Port_PCA9655E.h"
|
2016-09-24 23:02:20 +00:00
|
|
|
|
2016-10-30 08:30:13 +00:00
|
|
|
/* beginProtocol() is called from Scanner_IOE::begin(). Initiates I2C bus.
|
2016-09-24 23:02:20 +00:00
|
|
|
|
|
|
|
PCA9655E supports I2C SCL Clock Frequencies: 100 kHz, 400 kHz, 1000 kHz (Datasheet page 1 & 6)
|
|
|
|
The electrical limitation to bus speed is bus capacitance and the length of the wires involved.
|
2016-09-28 20:37:40 +00:00
|
|
|
Longer wires require lower clock speeds.
|
2016-09-24 23:02:20 +00:00
|
|
|
http://playground.arduino.cc/Main/WireLibraryDetailedReference > Wire.setclock()
|
|
|
|
*/
|
2016-09-25 03:03:08 +00:00
|
|
|
void Port_PCA9655E::beginProtocol()
|
2016-09-24 23:02:20 +00:00
|
|
|
{
|
|
|
|
Wire.begin(); //initiate I2C bus to 100 kHz
|
|
|
|
//Wire.setClock(400000L); //set I2C bus to 400 kHz (have not tested 400 kHz)
|
|
|
|
}
|
|
|
|
|
|
|
|
/* begin() is called from Scanner_IOE::begin().
|
|
|
|
Configures read pins to input.
|
2016-11-16 01:41:05 +00:00
|
|
|
activeState is not used because PCA9655E has no internal pull-up resistors.
|
2016-09-24 23:02:20 +00:00
|
|
|
*/
|
2016-11-16 01:41:05 +00:00
|
|
|
void Port_PCA9655E::begin(const uint8_t activeState)
|
2016-09-24 23:02:20 +00:00
|
|
|
{
|
|
|
|
Wire.beginTransmission(deviceAddr);
|
2016-11-12 16:45:48 +00:00
|
|
|
Wire.write(portNum + 6); //configure direction
|
2016-09-24 23:02:20 +00:00
|
|
|
Wire.write(readPins); //0=output (for strobe and LED), 1=input (for read)
|
|
|
|
Wire.endTransmission();
|
|
|
|
}
|
|
|
|
|
2016-11-16 01:47:23 +00:00
|
|
|
/* writeLow() sets pin output LOW.
|
2016-11-14 07:29:29 +00:00
|
|
|
pin is bit pattern, where pin being set is 1.
|
2016-09-24 23:02:20 +00:00
|
|
|
*/
|
2016-11-16 01:47:23 +00:00
|
|
|
void Port_PCA9655E::writeLow(const uint8_t pin)
|
2016-09-24 23:02:20 +00:00
|
|
|
{
|
2016-11-14 07:29:29 +00:00
|
|
|
outputVal &= ~pin; //set pin output to low
|
|
|
|
|
|
|
|
Wire.beginTransmission(deviceAddr);
|
|
|
|
Wire.write(portNum + 2); //output Byte command
|
|
|
|
Wire.write(outputVal);
|
|
|
|
Wire.endTransmission();
|
|
|
|
}
|
|
|
|
|
2016-11-16 01:47:23 +00:00
|
|
|
/* writeHigh() sets pin output HIGH.
|
2016-11-14 07:29:29 +00:00
|
|
|
pin is bit pattern, where pin being set is 1.
|
|
|
|
*/
|
2016-11-16 01:47:23 +00:00
|
|
|
void Port_PCA9655E::writeHigh(const uint8_t pin)
|
2016-11-14 07:29:29 +00:00
|
|
|
{
|
|
|
|
outputVal |= pin; //set pin output to high
|
2016-09-24 23:02:20 +00:00
|
|
|
|
|
|
|
Wire.beginTransmission(deviceAddr);
|
|
|
|
Wire.write(portNum + 2); //output Byte command
|
|
|
|
Wire.write(outputVal);
|
|
|
|
Wire.endTransmission();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read() returns portState.
|
|
|
|
Only portState bits of readPins are valid.
|
|
|
|
*/
|
2016-09-25 03:03:08 +00:00
|
|
|
uint8_t Port_PCA9655E::read()
|
2016-09-24 23:02:20 +00:00
|
|
|
{
|
|
|
|
Wire.beginTransmission(deviceAddr);
|
|
|
|
Wire.write(portNum); //input byte command
|
|
|
|
Wire.endTransmission(false); //PCA9655E needs false to send a restart
|
|
|
|
|
|
|
|
Wire.requestFrom(deviceAddr, 1u); //request one byte from input port
|
|
|
|
|
|
|
|
return Wire.read();
|
|
|
|
}
|