@@ -143,8 +143,6 @@ wippersnapper_i2c_v1_BusResponse WipperSnapper_Component_I2C::getBusStatus() {
143143/* ***********************************************************************/
144144wippersnapper_i2c_v1_I2CBusScanResponse
145145WipperSnapper_Component_I2C::scanAddresses () {
146- uint8_t endTransmissionRC;
147- uint16_t address;
148146 wippersnapper_i2c_v1_I2CBusScanResponse scanResp =
149147 wippersnapper_i2c_v1_I2CBusScanResponse_init_zero;
150148
@@ -157,36 +155,42 @@ WipperSnapper_Component_I2C::scanAddresses() {
157155 // Scan all I2C addresses between 0x08 and 0x7F inclusive and return a list of
158156 // those that respond.
159157 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);
161161 _i2c->beginTransmission (address);
162- endTransmissionRC = _i2c->endTransmission ();
162+ uint8_t endTransmissionRC = _i2c->endTransmission ();
163163
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!
183164 if (endTransmissionRC == 0 ) {
184165 WS_DEBUG_PRINT (" Found I2C Device at 0x" );
185166 WS_DEBUG_PRINTLN (address);
186167 scanResp.addresses_found [scanResp.addresses_found_count ] =
187168 (uint32_t )address;
188169 scanResp.addresses_found_count ++;
189170 }
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
190194 }
191195
192196#ifndef ARDUINO_ARCH_ESP32
0 commit comments