ESP32 i2c_driver_install error

eshkor
Posts: 2
Joined: Thu Jun 13, 2019 7:59 am

ESP32 i2c_driver_install error

Postby eshkor » Thu Jun 13, 2019 1:31 pm

Hello there,

I'm trying to use ESP32 I2C to communicate with an external RTC (DS1337). I get an error with this line of code i2c_driver_install(I2C_MASTER_PORT, conf.mode, 0, 0, 0);

The code for i2c init
  1. i2c_config_t conf;
  2.     conf.mode = I2C_MODE_MASTER;
  3.     conf.sda_io_num = I2C_MASTER_SDA_GPIO;
  4.     conf.sda_pullup_en = GPIO_PULLUP_DISABLE;
  5.     conf.scl_io_num = I2C_MASTER_SCL_GPIO;
  6.     conf.scl_pullup_en = GPIO_PULLUP_DISABLE;
  7.     conf.master.clk_speed = I2C_MASTER_FREQ_HZ;
  8.     i2c_param_config(I2C_MASTER_PORT, &conf);
  9.     ESP_ERROR_CHECK(i2c_driver_install(I2C_MASTER_PORT, conf.mode, 0, 0, 0)); //problem here
  10.  
  11.     rtcIsResponding = setup_registers();
  12.     rtcIsValidOnStart = false;
  13.     if (rtcIsResponding)
  14.     {
  15.         rtcIsValidOnStart = set_default_rtc_state();
  16.     }
I2C_MASTER_PORT is used as port 1
I2C_MASTER_SDA_GPIO is GPIO16
I2C_MASTER_SCL_GPIO is GPIO17
IDF version is 3.3

The error I get is:
  1. Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.
  2. Core 0 register dump:
  3. PC      : 0x40096f9b  PS      : 0x00060730  A0      : 0x80095783  A1      : 0x3ffe3a60
  4. A2      : 0x3ffb64ec  A3      : 0x0000001c  A4      : 0x00060720  A5      : 0x00000000
  5. A6      : 0x00000000  A7      : 0x00000000  A8      : 0x000000fe  A9      : 0x00000001
  6. A10     : 0x00000001  A11     : 0x00000000  A12     : 0x00000000  A13     : 0x00000000
  7. A14     : 0x00000000  A15     : 0x3ffb654d  SAR     : 0x0000001b  EXCCAUSE: 0x0000001c
  8. EXCVADDR: 0x0000001c  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0xffffffff
  9.  
  10. ELF file SHA256: 1138d6f2018262c1e3dba836115ecc3f7c91ab06acc22b4646dae7bb256ca631
  11.  
  12. Backtrace: 0x40096f9b:0x3ffe3a60 0x40095780:0x3ffe3a80 0x40096a2b:0x3ffe3aa0 0x40175712:0x3ffe3ae0 0x4010843f:0x3ffe3b20 0x40108903:0x3ffe3b40 0x400d220d:0x3ffe3b80 0x40080fb4:0x3ffe3bc0 0x40081319:0x3ffe3bf0 0x400792f7:0x3ffe3c30 0x400793a9:0x3ffe3c60 0x400793c7:0x3ffe3ca0 0x400796ad:0x3ffe3cc0 0x40080796:0x3ffe3df0 0x40007c31:0x3ffe3eb0 0x4000073d:0x3ffe3f20
  13.  
  14. Rebooting...
I have some printf's as 'starting...' in the beginning and they tend not to show up. It seems as the main isn't even called.
Also, when commented the line i2c_driver_install or I'm setting the device as a slave and not as a master the crash isn't there anymore and the messages are shown but the I2C is not usable.

Is there a way to fix this issue? I might have left something obvious behind, but after a few days I cannot see where the problem is. Could use a couple of fresh eyes!

Thank you

ESP_Sprite
Posts: 8999
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 i2c_driver_install error

Postby ESP_Sprite » Fri Jun 14, 2019 1:33 am

Your config struct is on the stack so it may contain crap in the members you don't initialize. i2c_config_t conf={0}; in line 1 should fix that.

eshkor
Posts: 2
Joined: Thu Jun 13, 2019 7:59 am

Re: ESP32 i2c_driver_install error

Postby eshkor » Fri Jun 14, 2019 8:39 am

Thank you for the response ESP_Sprite. I tried to set all the to 0 but it didn't do anything.

Code: Select all

void rtc_init()
{
	PRINTFW("I2C starting...\n");
	i2c_config_t conf = {0};
	conf.mode = I2C_MODE_MASTER;
	conf.sda_io_num = I2C_MASTER_SDA_GPIO;
	conf.sda_pullup_en = GPIO_PULLUP_DISABLE;
	conf.scl_io_num = I2C_MASTER_SCL_GPIO;
	conf.scl_pullup_en = GPIO_PULLUP_DISABLE;
	conf.master.clk_speed = I2C_MASTER_FREQ_HZ;
	ESP_ERROR_CHECK(i2c_param_config(I2C_MASTER_PORT, &conf));
	ESP_ERROR_CHECK(i2c_driver_install(I2C_MASTER_PORT, conf.mode, 0, 0, 0)); //TODO, problem with this
	ESP_ERROR_CHECK(i2c_driver_delete(I2C_MASTER_PORT));
	//ESP_ERROR_CHECK(i2c_driver_install(I2C_MASTER_PORT, conf.mode, 0, 0, 0));

	PRINTFW("I2C installed...\n");
	rtcIsResponding = setup_registers();
	rtcIsValidOnStart = false;
	if (rtcIsResponding)
	{
		rtcIsValidOnStart = set_default_rtc_state();
	}
}
I've added a couple of lines: i2c_driver_delete and after i2c_driver_install so that It would install again. But a strange thing is seen when I comment the second i2c_driver_install everything (apart the i2c) is working, all the messages are printed out, but when uncommented back again, the same error messages came up with none of my added messages:

Who is online

Users browsing this forum: No registered users and 76 guests