mirror of
https://github.com/xreef/PCF8574_library.git
synced 2024-08-30 18:12:18 +00:00
Manage initialization of pin INPUT with HIGH value to set pin mode
input, so pull-up and pull-down resistor for correct management is needed now, to restore previous decomment #define PCF8574_SOFT_INITIALIZATION
This commit is contained in:
parent
b6fa26e50d
commit
858f960d1e
27
PCF8574.cpp
27
PCF8574.cpp
@ -200,12 +200,18 @@ void PCF8574::begin(){
|
|||||||
|
|
||||||
|
|
||||||
DEBUG_PRINT("resetInitial pin ");
|
DEBUG_PRINT("resetInitial pin ");
|
||||||
|
#ifdef PCF8574_SOFT_INITIALIZATION
|
||||||
resetInitial = writeModeUp | readModePullUp;
|
resetInitial = writeModeUp | readModePullUp;
|
||||||
|
#else
|
||||||
|
resetInitial = writeModeUp | readMode;
|
||||||
|
#endif
|
||||||
DEBUG_PRINTLN( resetInitial, BIN);
|
DEBUG_PRINTLN( resetInitial, BIN);
|
||||||
|
|
||||||
|
_wire->beginTransmission(_address);
|
||||||
_wire->write(resetInitial);
|
_wire->write(resetInitial);
|
||||||
|
|
||||||
byteBuffered = resetInitial;
|
initialBuffer = writeModeUp | readModePullUp;
|
||||||
|
byteBuffered = initialBuffer;
|
||||||
writeByteBuffered = writeModeUp;
|
writeByteBuffered = writeModeUp;
|
||||||
|
|
||||||
DEBUG_PRINTLN("Start end trasmission if stop here check pullup resistor.");
|
DEBUG_PRINTLN("Start end trasmission if stop here check pullup resistor.");
|
||||||
@ -501,7 +507,11 @@ void PCF8574::readBuffer(bool force){
|
|||||||
if ((bit(7) & writeMode)>0) digitalInput.p7 = ((writeByteBuffered & bit(7))>0)?HIGH:LOW;
|
if ((bit(7) & writeMode)>0) digitalInput.p7 = ((writeByteBuffered & bit(7))>0)?HIGH:LOW;
|
||||||
|
|
||||||
//if ((byteBuffered & readModePullDown)>0 and (~byteBuffered & readModePullUp)>0){
|
//if ((byteBuffered & readModePullDown)>0 and (~byteBuffered & readModePullUp)>0){
|
||||||
byteBuffered = (resetInitial & readMode) | (byteBuffered & ~readMode); //~readMode & byteBuffered;
|
|
||||||
|
// byteBuffered = (resetInitial & readMode) | (byteBuffered & ~readMode); //~readMode & byteBuffered;
|
||||||
|
|
||||||
|
byteBuffered = (initialBuffer & readMode) | (byteBuffered & ~readMode); //~readMode & byteBuffered;
|
||||||
|
|
||||||
DEBUG_PRINT("Buffer hight value readed set readed ");
|
DEBUG_PRINT("Buffer hight value readed set readed ");
|
||||||
DEBUG_PRINTLN(byteBuffered, BIN);
|
DEBUG_PRINTLN(byteBuffered, BIN);
|
||||||
//}
|
//}
|
||||||
@ -536,7 +546,8 @@ void PCF8574::readBuffer(bool force){
|
|||||||
byte byteRead = byteBuffered | writeByteBuffered;
|
byte byteRead = byteBuffered | writeByteBuffered;
|
||||||
|
|
||||||
//if ((byteBuffered & readModePullDown)>0 and (~byteBuffered & readModePullUp)>0){
|
//if ((byteBuffered & readModePullDown)>0 and (~byteBuffered & readModePullUp)>0){
|
||||||
byteBuffered = (resetInitial & readMode) | (byteBuffered & ~readMode); //~readMode & byteBuffered;
|
// byteBuffered = (resetInitial & readMode) | (byteBuffered & ~readMode); //~readMode & byteBuffered;
|
||||||
|
byteBuffered = (initialBuffer & readMode) | (byteBuffered & ~readMode); //~readMode & byteBuffered;
|
||||||
DEBUG_PRINT("Buffer hight value readed set readed ");
|
DEBUG_PRINT("Buffer hight value readed set readed ");
|
||||||
DEBUG_PRINTLN(byteBuffered, BIN);
|
DEBUG_PRINTLN(byteBuffered, BIN);
|
||||||
//}
|
//}
|
||||||
@ -565,7 +576,7 @@ uint8_t PCF8574::digitalRead(uint8_t pin, bool forceReadNow){
|
|||||||
// DEBUG_PRINTLN(byteBuffered, BIN);
|
// DEBUG_PRINTLN(byteBuffered, BIN);
|
||||||
|
|
||||||
|
|
||||||
if (((bit(pin) & (readModePullDown & byteBuffered))>0) or (bit(pin) & (readModePullUp & ~byteBuffered))>0 ){
|
if ((((bit(pin) & (readModePullDown & byteBuffered))>0) or (bit(pin) & (readModePullUp & ~byteBuffered))>0 )){
|
||||||
DEBUG_PRINTLN(" ...Pin already set");
|
DEBUG_PRINTLN(" ...Pin already set");
|
||||||
if ((bit(pin) & byteBuffered)>0){
|
if ((bit(pin) & byteBuffered)>0){
|
||||||
value = HIGH;
|
value = HIGH;
|
||||||
@ -645,10 +656,18 @@ void PCF8574::digitalWrite(uint8_t pin, uint8_t value){
|
|||||||
|
|
||||||
// writeByteBuffered = writeByteBuffered & (~writeMode & byteBuffered);
|
// writeByteBuffered = writeByteBuffered & (~writeMode & byteBuffered);
|
||||||
byteBuffered = (writeByteBuffered & writeMode) | (resetInitial & readMode);
|
byteBuffered = (writeByteBuffered & writeMode) | (resetInitial & readMode);
|
||||||
|
|
||||||
|
// byteBuffered = (writeByteBuffered & writeMode) | (byteBuffered & readMode);
|
||||||
DEBUG_PRINT(" byteBuffered ");
|
DEBUG_PRINT(" byteBuffered ");
|
||||||
DEBUG_PRINTLN(byteBuffered, BIN);
|
DEBUG_PRINTLN(byteBuffered, BIN);
|
||||||
|
|
||||||
|
DEBUG_PRINT("Going to write data ");
|
||||||
|
DEBUG_PRINTLN(writeByteBuffered, BIN);
|
||||||
|
|
||||||
_wire->write(byteBuffered);
|
_wire->write(byteBuffered);
|
||||||
|
|
||||||
|
byteBuffered = (writeByteBuffered & writeMode) | (initialBuffer & readMode);
|
||||||
|
|
||||||
// byteBuffered = (writeByteBuffered & writeMode) & (byteBuffered & readMode);
|
// byteBuffered = (writeByteBuffered & writeMode) & (byteBuffered & readMode);
|
||||||
DEBUG_PRINTLN("Start end trasmission if stop here check pullup resistor.");
|
DEBUG_PRINTLN("Start end trasmission if stop here check pullup resistor.");
|
||||||
|
|
||||||
|
@ -55,6 +55,8 @@
|
|||||||
// Uncomment for low memory usage this prevent use of complex DigitalInput structure and free 7byte of memory
|
// Uncomment for low memory usage this prevent use of complex DigitalInput structure and free 7byte of memory
|
||||||
// #define PCF8574_LOW_LATENCY
|
// #define PCF8574_LOW_LATENCY
|
||||||
|
|
||||||
|
//#define PCF8574_SOFT_INITIALIZATION
|
||||||
|
|
||||||
// Select an algorithm to manage encoder progression
|
// Select an algorithm to manage encoder progression
|
||||||
//#define BASIC_ENCODER_ALGORITHM
|
//#define BASIC_ENCODER_ALGORITHM
|
||||||
#define MISCHIANTI_ENCODER_ALGORITHM
|
#define MISCHIANTI_ENCODER_ALGORITHM
|
||||||
@ -186,6 +188,7 @@ private:
|
|||||||
byte readModePullDown = B00000000;
|
byte readModePullDown = B00000000;
|
||||||
byte byteBuffered = B00000000;
|
byte byteBuffered = B00000000;
|
||||||
byte resetInitial = B00000000;
|
byte resetInitial = B00000000;
|
||||||
|
byte initialBuffer = B00000000;
|
||||||
unsigned long lastReadMillis = 0;
|
unsigned long lastReadMillis = 0;
|
||||||
|
|
||||||
byte writeByteBuffered = B00000000;
|
byte writeByteBuffered = B00000000;
|
||||||
|
Loading…
Reference in New Issue
Block a user