Closed DavidNidam closed 6 months ago
Thanks for the issue, Will look into it later this week (busy)
transmissionStatus == 4
Thanks for this analysis, need to check the details of the I2C implementation of the ESP8266.
Library code context
bool PCF8575::begin(uint16_t value)
{
if (! isConnected()) return false; <<<<<<<<<<<
PCF8575::write16(value);
return true;
}
bool PCF8575::isConnected()
{
_wire->beginTransmission(_address);
return ( _wire->endTransmission() == 0); <<<<<<<<<<
}
Reproduce:
- run ESP8266
- define PCF8575 pcf8575(0x20);
- call: if (pcf8575.begin()) Serial.println(F("OK")); else Serial.println(F("Failed"));
- wrong behavior... always return fail
I cannot reproduce from that (as it is no code), but I will do a call stack trace
@DavidNidam
uint8_t TwoWire::endTransmission(uint8_t sendStop)
{
int8_t ret = twi_writeTo(txAddress, txBuffer, txBufferLength, sendStop); <<<<<<<<<<
txBufferIndex = 0;
txBufferLength = 0;
transmitting = 0;
return ret;
}
uint8_t twi_writeTo(unsigned char address, unsigned char* buf, unsigned int len,
unsigned char sendStop)
{
return twi.writeTo(address, buf, len, sendStop); <<<<<<<<<<<<<<<
}
unsigned char Twi::writeTo(unsigned char address, unsigned char* buf, unsigned int len,
unsigned char sendStop)
{
unsigned int i;
if (!write_start())
{
return 4; // line busy <<<<<<<<<<<<<<<<<<<<<<<<<<<< Here is your 4
}
if (!write_byte(((address << 1) | 0) & 0xFF))
{
if (sendStop)
{
write_stop();
}
return 2; // received NACK on transmit of address
}
for (i = 0; i < len; i++)
{
if (!write_byte(buf[i]))
{
if (sendStop)
{
write_stop();
}
return 3; // received NACK on transmit of data
}
}
if (sendStop)
{
write_stop();
}
else
{
twi_scl_valley();
// TD-er: Also busywait(twi_dcount) here?
// busywait(twi_dcount);
}
i = 0;
while (!SDA_READ(twi_sda) && (i++) < 10)
{
twi_scl_valley();
busywait(twi_dcount);
}
return 0; <<<<<<<<<<<< this is the zero when all goes well
}
bool Twi::write_start(void)
{
SCL_HIGH(twi_scl);
SDA_HIGH(twi_sda);
if (!SDA_READ(twi_sda))
{
return false; <<<<<<<<<<<<<<<<
}
busywait(twi_dcount);
// A high-to-low transition on the SDA line while the SCL is high defines a START condition.
SDA_LOW(twi_sda);
busywait(twi_dcount);
// An additional delay between the SCL line high-to-low transition and setting up the SDA line
// to prevent a STOP condition execute.
SCL_LOW(twi_scl);
busywait(twi_dcount);
return true;
}
So your I2C seems not to be in a ready or start state.
what seems to go wrong is the SDA_HIGH(twi_sda); call.
Did you call Wire.begin() in your sketch ?
Hey
No need to reproduce… just look at the code…
Line 167 -> this->transmissionStatus = 4;
Line 192-> if (writeMode>0 || readMode>0) -> false
Line 211-> if (_usingInterrupt) -> false
Results: transmissionStatus at 4 (never changed)
Thus line 220-> return this->isLastTransmissionSuccess(); -> return transmissionStatus==0;
IE begin return false even though everything is OK
David
From: Rob Tillaart @.> Sent: Tuesday, April 9, 2024 9:26 PM To: RobTillaart/PCF8575 @.> Cc: DavidNidam @.>; Author @.> Subject: Re: [RobTillaart/PCF8575] wrong return on begin (Issue #40)
Reproduce:
I cannot reproduce from that, but I will do a call stack trace
— Reply to this email directly, view it on GitHub https://github.com/RobTillaart/PCF8575/issues/40#issuecomment-2045831941 , or unsubscribe https://github.com/notifications/unsubscribe-auth/BB4JINZN6SOAR4ASZBXSTUTY4QXB7AVCNFSM6AAAAABF63KOQ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBVHAZTCOJUGE . You are receiving this because you authored the thread. https://github.com/notifications/beacon/BB4JIN7PL54YEH7RSBB7Y23Y4QXB7A5CNFSM6AAAAABF63KOQ2WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTZ6DVQK.gif Message ID: @. @.> >
You refer to line numbers of which file? Please provide URL
@DavidNidam
Your error comes from the PCF8575 library from xreef.
No need to reproduce… just look at the code…
https://github.com/xreef/PCF8575_library/blob/master/PCF8575.cpp#L167
Yep
That’s what I referred to…
From: Rob Tillaart @.> Sent: Wednesday, April 10, 2024 11:19 AM To: RobTillaart/PCF8575 @.> Cc: DavidNidam @.>; Mention @.> Subject: Re: [RobTillaart/PCF8575] wrong return on begin (Issue #40)
@DavidNidam https://github.com/DavidNidam
Your error comes from the PCF8575 library from xreef.
No need to reproduce… just look at the code…
https://github.com/xreef/PCF8575_library/blob/master/PCF8575.cpp#L167
— Reply to this email directly, view it on GitHub https://github.com/RobTillaart/PCF8575/issues/40#issuecomment-2046873096 , or unsubscribe https://github.com/notifications/unsubscribe-auth/BB4JIN2R7DLZ24HMAOQDG2LY4TYXRAVCNFSM6AAAAABF63KOQ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBWHA3TGMBZGY . You are receiving this because you were mentioned. https://github.com/notifications/beacon/BB4JIN7NFXJW2CWB6QHWRQ3Y4TYXRA5CNFSM6AAAAABF63KOQ2WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTT2ADHAQ.gif Message ID: @. @.> >
Yep That’s what I referred to…
That's not my library, so you need to open an issue at his repository.
@DavidNidam As this is not an issue of my library I close the issue.
Sure. Sorry for the mistake
Dady Sent from my Samsung Galaxy smartphone.
From: Rob Tillaart @.> Sent: Tuesday, April 16, 2024 10:34:08 PM To: RobTillaart/PCF8575 @.> Cc: DavidNidam @.>; Mention @.> Subject: Re: [RobTillaart/PCF8575] wrong return on begin (Issue #40)
@DavidNidamhttps://github.com/DavidNidam As this is not an issue of my library I close the issue.
— Reply to this email directly, view it on GitHubhttps://github.com/RobTillaart/PCF8575/issues/40#issuecomment-2059793780, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BB4JINYXIHXDG3JLVBXKAWLY5V4LBAVCNFSM6AAAAABF63KOQ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJZG44TGNZYGA. You are receiving this because you were mentioned.Message ID: @.***>
Hey
Call begin for the first time when no using interrupt and writeMode & readMode == 0 return fail because transmissionStatus == 4.
Reproduce: