1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-23 12:51:24 +01:00

Update I2CManager.cpp

Rearrange I2C short-circuit check to before I2C is initialised.
This commit is contained in:
Neil McKechnie 2023-03-09 16:28:07 +00:00
parent 3ae1859ec7
commit 471b8ac8e1

View File

@ -72,18 +72,23 @@ static const FSH * guessI2CDeviceType(uint8_t address) {
void I2CManagerClass::begin(void) {
if (!_beginCompleted) {
_beginCompleted = true;
// Check for short-circuit or floating lines (no pull-up) on I2C before enabling I2C
const FSH *message = F("WARNING: Possible short-circuit or inadequate pullup on I2C %S line");
pinMode(SDA, INPUT);
if (!digitalRead(SDA))
DIAG(message, F("SDA"));
pinMode(SCL, INPUT);
if (!digitalRead(SCL))
DIAG(message, F("SCL"));
// Now initialise I2C
_initialise();
#if defined(I2C_USE_WIRE)
DIAG(F("I2CManager: Using Wire library"));
#endif
// Check for short-circuits on I2C
if (!digitalRead(SDA))
DIAG(F("WARNING: Possible short-circuit on I2C SDA line"));
if (!digitalRead(SCL))
DIAG(F("WARNING: Possible short-circuit on I2C SCL line"));
// Probe and list devices. Use standard mode
// (clock speed 100kHz) for best device compatibility.
_setClock(100000);