@@ -50,8 +50,6 @@ int pin_microSD_CS;
5050int pin_zed_tx_ready;
5151int pin_zed_reset;
5252int pin_batteryLevel_alert;
53- int pin_i2c_sda = 21 ;
54- int pin_i2c_scl = 22 ;
5553
5654int pin_muxA;
5755int 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- }
0 commit comments