Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I2C scan in UART shell is not detecting any I2C devices on ESP32 #33954

Closed
tiborrr opened this issue Apr 1, 2021 · 0 comments · Fixed by #34926
Closed

I2C scan in UART shell is not detecting any I2C devices on ESP32 #33954

tiborrr opened this issue Apr 1, 2021 · 0 comments · Fixed by #34926
Assignees
Labels
area: I2C bug The issue is a bug, or the PR is fixing a bug platform: ESP32 Espressif ESP32 priority: low Low impact/importance bug

Comments

@tiborrr
Copy link

tiborrr commented Apr 1, 2021

Describe the bug
When using I2C scan in the UART console no I2C devices get detected

To Reproduce

  1. Connect I2C device to ESP32 using GPIO pin 21 for SDA and 22 for SCL
  2. Open wifi station example for esp32, found in zephyr/samples/boards/esp32/wifi_station
  3. Enable UART console by setting CONFIG_NET_SHELL to y in prj.conf
  4. Build the example with west build -p always -b esp32
  5. Flash and monitor with west flash;minicom
  6. Run i2c scan I2C_0 in the uart command line

Expected behavior
Using the following example using Arduino IDE detects my I2C devices:

#include <Wire.h>

#define SDA1 21
#define SCL1 22

#define SDA2 17
#define SCL2 16

TwoWire I2Cone = TwoWire(0);
TwoWire I2Ctwo = TwoWire(1);

void scan1() {
  Serial.println("Scanning I2C Addresses Channel 1");
  uint8_t cnt = 0;
  for (uint8_t i = 0; i < 128; i++) {
    I2Cone.beginTransmission(i);
    uint8_t ec = I2Cone.endTransmission(true);
    if (ec == 0) {
      if (i < 16)Serial.print('0');
      Serial.print(i, HEX);
      cnt++;
    }   else Serial.print("..");
    Serial.print(' ');
    if ((i & 0x0f) == 0x0f)Serial.println();
  }
  Serial.print("Scan Completed,");
  Serial.print(cnt);
  Serial.println("I2C Devices found.");
}

void scan2() {
  Serial.println("Scanning I2C Addresses Channel 2");
  uint8_t cnt = 0;
  for (uint8_t i = 0; i < 128; i++) {
    I2Ctwo.beginTransmission(i);
    uint8_t ec = I2Ctwo.endTransmission(true);
    if (ec == 0) {
      if (i < 16)Serial.print('0');
      Serial.print(i, HEX);
      cnt++;
    }   else Serial.print("..");
    Serial.print(' ');
    if ((i & 0x0f) == 0x0f)Serial.println();
  }
  Serial.print("Scan Completed,");
  Serial.print(cnt);
  Serial.println("I2C Devices found.");
}

void setup() {
  Serial.begin(115200);
  I2Cone.begin(SDA1, SCL1, 400000); // SDA pin 21, SCL pin 22 TTGO TQ
  I2Ctwo.begin(SDA2, SCL2, 400000); // SDA2 pin 17, SCL2 pin 16
}

void loop() {
  scan1();
  Serial.println();
  delay(100);
  scan2();
  Serial.println();
  delay(5000);
}

This returns:

Scanning I2C Addresses Channel 1
00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 
.. .. .. .. .. 45 .. .. .. .. .. .. .. .. .. .. 
.. .. .. .. .. .. .. .. 58 .. .. .. .. .. .. .. 
.. 61 .. .. .. .. .. .. .. .. .. .. .. .. .. .. 
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 
Scan Completed,4I2C Devices found.
Scanning I2C Addresses Channel 2
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 
Scan Completed,0I2C Devices found.

Impact
Showstopper because sensors do not get detected.

Logs and console output

uart:~$ i2c scan I2C_0                                                                                                                                                                     
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f                                                                                                                                        
00:             04 05 06 07 08 09 0a 0b 0c 0d 0e 0f                                                                                                                                        
10: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f                                                                                                                                        
20: 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f                                                                                                                                        
30: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f                                                                                                                                        
40: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f                                                                                                                                        
50: 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f                                                                                                                                        
60: 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f                                                                                                                                        
70: 70 71 72 73 74 75 76 77                                                                                                                                                                
116 devices found on I2C_0    

Environment (please complete the following information):

  • Ubuntu 20.04
  • Zephyr version: 2.5.99
@tiborrr tiborrr added the bug The issue is a bug, or the PR is fixing a bug label Apr 1, 2021
@sylvioalves sylvioalves self-assigned this Apr 1, 2021
@galak galak added priority: low Low impact/importance bug platform: ESP32 Espressif ESP32 area: I2C labels Apr 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: I2C bug The issue is a bug, or the PR is fixing a bug platform: ESP32 Espressif ESP32 priority: low Low impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants