1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #ifdef ENABLE_I2C_INTERFACE
- void i2cscan() {
- byte error, address;
- int nDevices;
-
- snprintf(logBuf, LOG_BUFFER_SIZE, "Scanning I2C devices...");
- sendLog(logBuf, LOGLEVEL_INFO);
-
- nDevices = 0;
- for(address = 1; address < 127; address++ )
- {
- // The i2c_scanner uses the return value of
- // the Write.endTransmisstion to see if
- // a device did acknowledge to the address.
- Wire.beginTransmission(address);
- error = Wire.endTransmission();
-
- if (error == 0)
- {
- //Serial.print("I2C device found at address 0x");
- //if (address<16)
- // Serial.print("0");
- //Serial.print(address,HEX);
- //Serial.println(" !");
- snprintf(logBuf, LOG_BUFFER_SIZE, " device found at address 0x%x", address);
- sendLog(logBuf, LOGLEVEL_INFO);
-
- nDevices++;
- }
- else if (error==4)
- {
- //Serial.print(" unknown error at address 0x");
- //if (address<16)
- // Serial.print("0");
- //Serial.println(address,HEX);
- snprintf(logBuf, LOG_BUFFER_SIZE, " unknown error at address 0x%x", address);
- sendLog(logBuf, LOGLEVEL_INFO);
- }
- }
- if (nDevices == 0) {
- //Serial.println("No I2C devices found\n");
- snprintf(logBuf, LOG_BUFFER_SIZE, " No I2C devices found.");
- sendLog(logBuf, LOGLEVEL_INFO);
- }
- else {
- //Serial.println("done\n");
- snprintf(logBuf, LOG_BUFFER_SIZE, " DONE!");
- sendLog(logBuf, LOGLEVEL_INFO);
- }
- } // i2cscan()
- #endif
|