IDF i2c issues, unable to find device on bus

JeffWilliams
Posts: 17
Joined: Thu Mar 09, 2017 2:06 am

IDF i2c issues, unable to find device on bus

Postby JeffWilliams » Wed Jan 17, 2018 2:13 am

Hello,

I know there are several I2C threads here, I am looking for suggestions for my issue. Unfortunately I don't have a logic analyzer at the moment to see what the signals look like between the working and the not working.

Background, I was using a Teensy 3.6 with external Wifi and BT for a project and when the ESP32 came out I thought I would move to it as it removed several external modules from my project. And it let me play with a new board and move to RTOS which I was thinking of doing anyhow. The project is a data logger for my track motorcycle.

I have a BNO055 (https://learn.adafruit.com/adafruit-bno ... r/overview) sensor on my i2c bus and no matter what I do I can't see it with my ESP32. On the same bus are 2 TMP006 (temp) sensors and they are picked up fine. I even added a different IMU to the I2C bus and ESP32 can see it. I am just using simple i2c scanner logic to list addresses on the bus. I have configured the bus for 400K though changing it to 100K speed didn't change anything.

If I remove the ESP32 and connect the identical I2C bus up to a Teensy 3.2 I have spare and run an I2C scanner there I see all the devices on the bus.

I am currently using HEAD/master of IDF for ESP32. All of my I2C modules have had the resisters removed and the pull-up resisters of the ESP32 are disabled. I have external pull-up resister (4.7K) installed on the bus. This configuration worked just fine for all last season on the bike though I am testing on my desk so all wires are standard jumper length on 1 breadboard currently. I have switched out the BNO055 with the one I know works from my motorcycle and same result.

I have never had issues with I2C on any other microcontroller and it concerns me to see the number of items when I Google 'ESP32 I2C issues'. Is I2C on ESP32 stable? Is there something I am missing to get the BNO055 working?

I am waiting on the logic analyzer (in the mail) so maybe that will explain something when it gets here.
Thanks, jeff

User avatar
Gfast2
Posts: 182
Joined: Fri Aug 11, 2017 1:52 am

Re: IDF i2c issues, unable to find device on bus

Postby Gfast2 » Wed Jan 17, 2018 4:38 am

Hi jeff,

I have a quick idea for you: try this I2C scanner which will list all available living I2C device. :lol:

I'm playing with a BOSH bmp280 temperature/airpressure sensor pretty intensive recently. I think I2C on ESP32 is most of the time stable.

Tell us what your I2C scanner said!

Cheers

Gfast2

JeffWilliams
Posts: 17
Joined: Thu Mar 09, 2017 2:06 am

Re: IDF i2c issues, unable to find device on bus

Postby JeffWilliams » Wed Jan 17, 2018 11:20 am

Hello,

Yes, I am only showing addresses that appear on the bus 'alive'

ESP32 IDF log messages:
Starting scan
Found device at ID 0x40
Found device at ID 0x69
Scan complete

Teensy Arduino log mesages:
Scanning ...
I2C device found at address 0x29
I2C device found at address 0x40
I2C device found at address 0x69
done

The 0x29 is the BNO055. Obviously just printing out the addresses doesn't make sense which I believe you are implying.

My scanner is based on nkolban's I just have a different output since I didn't want the table like output that he uses. I have his book as well.

Jeff


scanner code:

Code: Select all

#include "freertos/FreeRTOS.h"
#include "esp_wifi.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_event_loop.h"
#include "nvs_flash.h"
#include "driver/gpio.h"
#include <driver/i2c.h>
#include <esp_log.h>
#include <freertos/task.h>
#include <stdio.h>


#define SDA_PIN 21
#define SCL_PIN 22

static char tag[] = "i2cscanner";



void app_main(void)
{
	ESP_LOGD(tag, ">> i2cScanner");
	i2c_config_t conf;
	conf.mode = I2C_MODE_MASTER;
	conf.sda_io_num = SDA_PIN;
	conf.scl_io_num = SCL_PIN;
	conf.sda_pullup_en = GPIO_PULLUP_DISABLE;
	conf.scl_pullup_en = GPIO_PULLUP_DISABLE;
	conf.master.clk_speed = 400000;
	i2c_param_config(I2C_NUM_0, &conf);

	i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);

	int i;
	esp_err_t espRc;
	printf("Starting scan\n");
	for (i=3; i< 0x78; i++) {
		i2c_cmd_handle_t cmd = i2c_cmd_link_create();
		i2c_master_start(cmd);
		i2c_master_write_byte(cmd, (i << 1) | I2C_MASTER_WRITE, 1 /* expect ack */);
		i2c_master_stop(cmd);

		espRc = i2c_master_cmd_begin(I2C_NUM_0, cmd, 100/portTICK_PERIOD_MS);
		if (espRc == 0) {
			printf("Found device at ID 0x%.2x\n", i);
		}
		i2c_cmd_link_delete(cmd);
	}
	printf("Scan complete \n");
}


JeffWilliams
Posts: 17
Joined: Thu Mar 09, 2017 2:06 am

Re: IDF i2c issues, unable to find device on bus

Postby JeffWilliams » Thu Jan 18, 2018 2:02 am

Hello,

Re-read that thread in the arduino-esp32 as I found it before but didn't really read it since it was arduino based. So I updated my Arduino dev environment with the ESP32 stuff. So I have confirmed that the changes they made in arduino allow my arduino i2c scanner logic to find all the devices on my i2c.

What it also means I guess is that the ESP32 and I guess IDF should be able to work with the BNO055 just fine. I guess I need to try to figure out the IDF code I need to use by digging into the Arduino HAL a bit and figure out the difference.

I guess my other option is keep my project in Arduino even on the ESP32 and use some of the IDF aspects for tasks etc within the Arduino, or use the Arduino stuff as a component within IDF.

Jeff

User avatar
Gfast2
Posts: 182
Joined: Fri Aug 11, 2017 1:52 am

Re: IDF i2c issues, unable to find device on bus

Postby Gfast2 » Thu Jan 18, 2018 5:31 am

JeffWilliams wrote:Hello,

Re-read that thread in the arduino-esp32 as I found it before but didn't really read it since it was arduino based. So I updated my Arduino dev environment with the ESP32 stuff. So I have confirmed that the changes they made in arduino allow my arduino i2c scanner logic to find all the devices on my i2c.

What it also means I guess is that the ESP32 and I guess IDF should be able to work with the BNO055 just fine. I guess I need to try to figure out the IDF code I need to use by digging into the Arduino HAL a bit and figure out the difference.

I guess my other option is keep my project in Arduino even on the ESP32 and use some of the IDF aspects for tasks etc within the Arduino, or use the Arduino stuff as a component within IDF.

Jeff
Hi JeffWilliams,

Because I come from Arduino Land, so I fully understand the feeling in ESP-IDF

ESP-IDF -> Jungle, much fun, 1000% more powerful
Arduino -> Perfect Start Point, gives every kids more then enough good feeling and confidence :P

Cheers

Gfast2

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: IDF i2c issues, unable to find device on bus

Postby WiFive » Thu Jan 18, 2018 6:31 am

There were two hints in the Arduino issue, increase timeout and when to use stop vs end.

trustmiao
Posts: 42
Joined: Mon Aug 06, 2018 5:16 am

Re: IDF i2c issues, unable to find device on bus

Postby trustmiao » Thu Mar 21, 2019 7:50 am

Though this is an old post, I wish very much to know whether/what solution did you find.

I've experienced exactly the same trouble while I am trying connecting to BNO 080. I also found i2c in arduino ide, but not idf.
here is the post I described my scenario, but no lock no answer.
https://www.esp32.com/viewtopic.php?f=2&t=9724

trustmiao
Posts: 42
Joined: Mon Aug 06, 2018 5:16 am

Re: IDF i2c issues, unable to find device on bus

Postby trustmiao » Thu Mar 21, 2019 9:05 am

trustmiao wrote:
Thu Mar 21, 2019 7:50 am
Though this is an old post, I wish very much to know whether/what solution did you find.

I've experienced exactly the same trouble while I am trying connecting to BNO 080. I also found i2c in arduino ide, but not idf.
here is the post I described my scenario, but no lock no answer.
https://www.esp32.com/viewtopic.php?f=2&t=9724
as a record, I solve the problem by adjusting
I2C[i2c_num]->timeout.tout = 200000;
in driver/i2c.c - i2c_param_config:

I got answer from

Who is online

Users browsing this forum: No registered users and 91 guests