@@ -82,7 +82,6 @@ WipperSnapper_Component_I2C::WipperSnapper_Component_I2C(
82
82
} else {
83
83
_isInit = true ; // if the peripheral was configured incorrectly
84
84
}
85
- _i2c->setClock (50000 );
86
85
#elif defined(ARDUINO_ARCH_ESP8266)
87
86
_i2c = new TwoWire ();
88
87
_i2c->begin (msgInitRequest->i2c_pin_sda , msgInitRequest->i2c_pin_scl );
@@ -143,8 +142,6 @@ wippersnapper_i2c_v1_BusResponse WipperSnapper_Component_I2C::getBusStatus() {
143
142
/* ***********************************************************************/
144
143
wippersnapper_i2c_v1_I2CBusScanResponse
145
144
WipperSnapper_Component_I2C::scanAddresses () {
146
- uint8_t endTransmissionRC;
147
- uint16_t address;
148
145
wippersnapper_i2c_v1_I2CBusScanResponse scanResp =
149
146
wippersnapper_i2c_v1_I2CBusScanResponse_init_zero;
150
147
@@ -156,37 +153,45 @@ WipperSnapper_Component_I2C::scanAddresses() {
156
153
157
154
// Scan all I2C addresses between 0x08 and 0x7F inclusive and return a list of
158
155
// those that respond.
159
- WS_DEBUG_PRINTLN (" EXEC: I2C Scan" );
160
- for (address = 0x08 ; address < 0x7F ; address++) {
156
+ WS_DEBUG_PRINTLN (" [i2c]: Scanning I2C Bus for Devices..." );
157
+ for (uint8_t address = 1 ; address < 127 ; ++address) {
158
+ WS_DEBUG_PRINT (" [i2c] Scanning Address: 0x" );
159
+ WS_DEBUG_PRINTLN (address, HEX);
161
160
_i2c->beginTransmission (address);
162
- endTransmissionRC = _i2c->endTransmission ();
161
+ uint8_t endTransmissionRC = _i2c->endTransmission ();
163
162
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
163
if (endTransmissionRC == 0 ) {
184
- WS_DEBUG_PRINT (" Found I2C Device at 0x" );
185
- WS_DEBUG_PRINTLN (address);
164
+ WS_DEBUG_PRINTLN (" [i2c] Found Device!" );
186
165
scanResp.addresses_found [scanResp.addresses_found_count ] =
187
166
(uint32_t )address;
188
167
scanResp.addresses_found_count ++;
189
168
}
169
+ #if defined(ARDUINO_ARCH_ESP32)
170
+ // Check endTransmission()'s return code (Arduino-ESP32 ONLY)
171
+ else if (endTransmissionRC == 3 ) {
172
+ WS_DEBUG_PRINTLN (" [i2c] Did not find device: NACK on transmit of data!" );
173
+ continue ;
174
+ } else if (endTransmissionRC == 2 ) {
175
+ WS_DEBUG_PRINTLN (
176
+ " [i2c] Did not find device: NACK on transmit of address!" );
177
+ continue ;
178
+ } else if (endTransmissionRC == 1 ) {
179
+ WS_DEBUG_PRINTLN (
180
+ " [i2c] Did not find device: data too long to fit in xmit buffer!" );
181
+ continue ;
182
+ } else if (endTransmissionRC == 4 ) {
183
+ WS_DEBUG_PRINTLN (
184
+ " [i2c] Did not find device: Unspecified bus error occured!" );
185
+ continue ;
186
+ } else if (endTransmissionRC == 5 ) {
187
+ WS_DEBUG_PRINTLN (" [i2c] Did not find device: Bus timed out!" );
188
+ continue ;
189
+ } else {
190
+ WS_DEBUG_PRINTLN (
191
+ " [i2c] Did not find device: Unknown bus error has occured!" );
192
+ continue ;
193
+ }
194
+ #endif
190
195
}
191
196
192
197
#ifndef ARDUINO_ARCH_ESP32
@@ -195,8 +200,9 @@ WipperSnapper_Component_I2C::scanAddresses() {
195
200
WS.feedWDT ();
196
201
#endif
197
202
198
- WS_DEBUG_PRINT (" I2C Devices Found: " )
199
- WS_DEBUG_PRINTLN (scanResp.addresses_found_count );
203
+ WS_DEBUG_PRINT (" [i2c] Scan Complete! Found: " )
204
+ WS_DEBUG_PRINT (scanResp.addresses_found_count );
205
+ WS_DEBUG_PRINTLN (" Devices on bus." );
200
206
201
207
scanResp.bus_response = wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_SUCCESS;
202
208
return scanResp;
0 commit comments