@@ -143,8 +143,6 @@ wippersnapper_i2c_v1_BusResponse WipperSnapper_Component_I2C::getBusStatus() {
143
143
/* ***********************************************************************/
144
144
wippersnapper_i2c_v1_I2CBusScanResponse
145
145
WipperSnapper_Component_I2C::scanAddresses () {
146
- uint8_t endTransmissionRC;
147
- uint16_t address;
148
146
wippersnapper_i2c_v1_I2CBusScanResponse scanResp =
149
147
wippersnapper_i2c_v1_I2CBusScanResponse_init_zero;
150
148
@@ -157,36 +155,42 @@ WipperSnapper_Component_I2C::scanAddresses() {
157
155
// Scan all I2C addresses between 0x08 and 0x7F inclusive and return a list of
158
156
// those that respond.
159
157
WS_DEBUG_PRINTLN (" EXEC: I2C Scan" );
160
- for (address = 0x08 ; address < 0x7F ; address++) {
158
+ for (uint8_t address = 1 ; address < 127 ; ++address) {
159
+ WS_DEBUG_PRINT (" Address: 0x" );
160
+ WS_DEBUG_PRINTLN (address);
161
161
_i2c->beginTransmission (address);
162
- endTransmissionRC = _i2c->endTransmission ();
162
+ uint8_t endTransmissionRC = _i2c->endTransmission ();
163
163
164
- #if defined(ARDUINO_ARCH_ESP32)
165
- // Check endTransmission()'s return code (Arduino-ESP32 ONLY)
166
- // https://github.com/espressif/arduino-esp32/blob/master/libraries/Wire/src/Wire.cpp
167
- if (endTransmissionRC == 5 ) {
168
- WS_DEBUG_PRINTLN (" ESP_ERR_TIMEOUT: I2C Bus Busy" );
169
- scanResp.bus_response =
170
- wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_ERROR_HANG;
171
- // NOTE: ESP-IDF appears to handle this "behind the scenes" by
172
- // resetting/clearing the bus. The user should be prompted to
173
- // perform a bus scan again.
174
- break ;
175
- } else if (endTransmissionRC == 7 ) {
176
- WS_DEBUG_PRINT (" I2C_ESP_ERR: SDA/SCL shorted, requests queued: " );
177
- WS_DEBUG_PRINTLN (endTransmissionRC);
178
- break ;
179
- }
180
- #endif
181
-
182
- // Found device!
183
164
if (endTransmissionRC == 0 ) {
184
165
WS_DEBUG_PRINT (" Found I2C Device at 0x" );
185
166
WS_DEBUG_PRINTLN (address);
186
167
scanResp.addresses_found [scanResp.addresses_found_count ] =
187
168
(uint32_t )address;
188
169
scanResp.addresses_found_count ++;
189
170
}
171
+ #if defined(ARDUINO_ARCH_ESP32)
172
+ // Check endTransmission()'s return code (Arduino-ESP32 ONLY)
173
+ else if (endTransmissionRC == 1 ) {
174
+ WS_DEBUG_PRINTLN (" [i2c] ERROR: data too long to fit in transmit buffer!" );
175
+ continue ;
176
+ } else if (endTransmissionRC == 2 ) {
177
+ WS_DEBUG_PRINTLN (" [i2c] ERROR: received NACK on transmit of address!" );
178
+ continue ;
179
+ } else if (endTransmissionRC == 3 ) {
180
+ WS_DEBUG_PRINTLN (" [i2c] ERROR: received NACK on transmit of data!" );
181
+ continue ;
182
+ } else if (endTransmissionRC == 4 ) {
183
+ WS_DEBUG_PRINTLN (" [i2c] ERROR: Other error!" );
184
+ continue ;
185
+ } else if (endTransmissionRC == 5 ) {
186
+ WS_DEBUG_PRINTLN (" [i2c] ERROR: I2C Bus has timed out!" );
187
+ scanResp.bus_response = wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_ERROR_HANG;
188
+ continue ;
189
+ } else {
190
+ WS_DEBUG_PRINTLN (" [i2c] ERROR: Unknown error!" );
191
+ continue ;
192
+ }
193
+ #endif
190
194
}
191
195
192
196
#ifndef ARDUINO_ARCH_ESP32
0 commit comments