Skip to content

Commit c821722

Browse files
committed
Use i2c response to check bus
1 parent f253149 commit c821722

File tree

2 files changed

+20
-76
lines changed

2 files changed

+20
-76
lines changed

Firmware/Test Sketches/System_Check/System_Check.ino

Lines changed: 14 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ int pin_microSD_CS;
5050
int pin_zed_tx_ready;
5151
int pin_zed_reset;
5252
int pin_batteryLevel_alert;
53-
int pin_i2c_sda = 21;
54-
int pin_i2c_scl = 22;
5553

5654
int pin_muxA;
5755
int pin_muxB;
@@ -233,7 +231,20 @@ void setup()
233231
//
234232
// Serial.println("Done");
235233

236-
beginI2C();
234+
Wire.begin();
235+
236+
//begin/end wire transmission to see if bus is responding correctly
237+
//All good: 0ms, response 2
238+
//SDA/SCL shorted: 1000ms timeout, response 5
239+
//SCL/VCC shorted: 14ms, response 5
240+
//SCL/GND shorted: 1000ms, response 5
241+
//SDA/VCC shorted: 1000ms, reponse 5
242+
//SDA/GND shorted: 14ms, response 5
243+
unsigned long startTime = millis();
244+
Wire.beginTransmission(0x15); //Dummy address
245+
int endValue = Wire.endTransmission();
246+
Serial.printf("Response time: %d endValue: %d\n\r", millis() - startTime, endValue);
247+
if(endValue == 2) online.i2c = true;
237248

238249
beginBoard(); //Determine what hardware platform we are running on and check on button
239250

@@ -255,72 +266,3 @@ void loop()
255266
{
256267
delay(10);
257268
}
258-
259-
//Verify the I2C bus is clear of impediments
260-
void beginI2C()
261-
{
262-
typedef enum
263-
{
264-
I2C_CLEAR = 0,
265-
I2C_SCL_GND, //SCL Shorted to Ground
266-
I2C_SDA_GND, //SDA Shorted to Ground
267-
I2C_SHORTED, //SDA/SCL Shorted together
268-
I2C_SCL_VCC, //SCL Shorted to VCC
269-
I2C_SDA_VCC, //SDA Shorted to VCC
270-
} I2cState;
271-
I2cState i2cState = I2C_CLEAR;
272-
273-
pinMode(pin_i2c_sda, INPUT_PULLUP);
274-
pinMode(pin_i2c_scl, INPUT_PULLUP);
275-
276-
//Both pins should float high
277-
if (digitalRead(pin_i2c_scl) == LOW) i2cState = I2C_SCL_GND;
278-
if (digitalRead(pin_i2c_sda) == LOW) i2cState = I2C_SDA_GND;
279-
280-
//SCL should be independant of SDA
281-
pinMode(pin_i2c_sda, OUTPUT);
282-
digitalWrite(pin_i2c_sda, LOW);
283-
284-
//Skip check if SCL is already shorted to GND
285-
if(i2cState == I2C_CLEAR)
286-
if (digitalRead(pin_i2c_scl) == LOW) i2cState = I2C_SHORTED;
287-
288-
//SDA should drive low
289-
if (digitalRead(pin_i2c_sda) == HIGH) i2cState = I2C_SDA_VCC;
290-
291-
//SCL should drive low
292-
pinMode(pin_i2c_scl, OUTPUT);
293-
digitalWrite(pin_i2c_scl, LOW);
294-
if (digitalRead(pin_i2c_scl) == HIGH) i2cState = I2C_SCL_VCC;
295-
296-
if (i2cState == I2C_CLEAR)
297-
{
298-
Wire.begin();
299-
online.i2c = true;
300-
return;
301-
}
302-
303-
Serial.print("I2C Error: ");
304-
switch (i2cState)
305-
{
306-
case (I2C_SCL_GND):
307-
Serial.print("SCL shorted to GND");
308-
break;
309-
case (I2C_SDA_GND):
310-
Serial.print("SDA shorted to GND");
311-
break;
312-
case (I2C_SHORTED):
313-
Serial.print("SCL shorted to SDA");
314-
break;
315-
case (I2C_SDA_VCC):
316-
Serial.print("SDA shorted to VCC");
317-
break;
318-
case (I2C_SCL_VCC):
319-
Serial.print("SCL shorted to VCC");
320-
break;
321-
default:
322-
Serial.print("Unknown");
323-
break;
324-
}
325-
Serial.println();
326-
}

Firmware/Test Sketches/System_Check/menuSystem.ino

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ void menuSystem()
3535
}
3636
Serial.println();
3737

38-
if (i2cBorked == true)
38+
if (online.i2c == false)
3939
{
40-
Serial.println("The I2C bus is borked! Something is shorting SDA/SCL pins. Check accelerometer. All devices offline.");
40+
Serial.println("I2C: Offline - Something is causing bus problems");
4141
}
4242
else
4343
{
44+
Serial.println("I2C: Online");
45+
4446
Serial.print(F("GNSS: "));
4547
if (online.gnss == true)
4648
{
@@ -166,8 +168,8 @@ void menuSystem()
166168
if (address == 0x2C) Serial.print(" USB Hub");
167169
if (address == 0x36) Serial.print(" Fuel Gauge");
168170
if (address == 0x19) Serial.print(" Accelerometer");
169-
if (address == 0x3D) Serial.print(" Dsiplay Main");
170-
if (address == 0x3C) Serial.print(" Dsiplay Alternate");
171+
if (address == 0x3D) Serial.print(" Display Main");
172+
if (address == 0x3C) Serial.print(" Display Alternate");
171173
Serial.println();
172174
}
173175
}

0 commit comments

Comments
 (0)