is there any issue using io0/io4 for i2c?

stoikos
Posts: 31
Joined: Mon Aug 06, 2018 4:38 am

is there any issue using io0/io4 for i2c?

Postby stoikos » Tue Apr 09, 2019 5:24 am

I am trying to use IO0 for SDA and IO4 for SCL in I2C. I have tried with 4.7k external pullups in both pins and no pullups as well. I2cscanners fail to connect to sensors. When I am using other pins everything works fine. Any ideas?

username
Posts: 477
Joined: Thu May 03, 2018 1:18 pm

Re: is there any issue using io0/io4 for i2c?

Postby username » Tue Apr 09, 2019 12:08 pm

IO0 is a special pin that already has a pullup on it. Its used to program the part. I suggest looking at the data sheet first so you can understand what pins to use and not to.

stoikos
Posts: 31
Joined: Mon Aug 06, 2018 4:38 am

Re: is there any issue using io0/io4 for i2c?

Postby stoikos » Tue Apr 09, 2019 2:18 pm

Hi,
I know how they function, nevertheless in the esp32 docs they say that after boot they behave like normal pins. I do use them for the boot process but it doesnt seem to be working, while the same software when its using other pins is working

username
Posts: 477
Joined: Thu May 03, 2018 1:18 pm

Re: is there any issue using io0/io4 for i2c?

Postby username » Tue Apr 09, 2019 2:25 pm

Not sure, Personally I steer clear of using GPIO0. Throw a scope on the SCL/SDA lines and have a look.

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: is there any issue using io0/io4 for i2c?

Postby fly135 » Tue Apr 09, 2019 3:11 pm

Pretty sure that GPIO 0 is available after boot. If you are going work on stuff like this it's worth getting a cheap scope to analyze these kinds of problems.

John A

stoikos
Posts: 31
Joined: Mon Aug 06, 2018 4:38 am

Re: is there any issue using io0/io4 for i2c?

Postby stoikos » Wed Apr 10, 2019 3:24 am

there are not enough pins on esp32. I am already using port expanders, multiple multiplexers on that pcb. I need to make them work :) I will look with my trusted rigol. I was trying to determine if there is something internal that prohibits them to be used as i2c. they have internal pullups, they are IO (unlike >io34). so after boot they should work. right? the same software on different pins works like a charm

stoikos
Posts: 31
Joined: Mon Aug 06, 2018 4:38 am

Re: is there any issue using io0/io4 for i2c?

Postby stoikos » Mon May 06, 2019 6:14 pm

This is the code that I am running. I put a scope on IO0 and I get the attached signal. the same program on another pin works like a charm.

Code: Select all

void task_i2cscanner(void *ignore) 
{
	vTaskDelay(1000 / portTICK_PERIOD_MS);
	ESP_LOGD("Sensor", ">> i2cScanner");
	i2c_config_t conf;
	conf.mode = I2C_MODE_MASTER;
	conf.sda_io_num =  SCL_PIN;
	conf.scl_io_num =  SDA_PIN; 
		
	
	
	conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
	conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
		
	conf.master.clk_speed = 400000;
	i2c_param_config(I2C_NUM_0, &conf);

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

	while (true)
	{
		vTaskDelay(1);	
		int i;
		esp_err_t espRc;
		printf("    SDA_PIN %i  SCL_PIN %i\n", conf.sda_io_num, conf.scl_io_num);
		printf("     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f\n");
		printf("00:         ");
		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, 1000 / portTICK_PERIOD_MS);
			if (i % 16 == 0) {
				printf("\n%.2x:", i);
			}
			if (espRc == 0) {
				printf(" %.2x", i);
			}
			else {
				printf(" --");
			}
			//ESP_LOGD(tag, "i=%d, rc=%d (0x%x)", i, espRc, espRc);
			i2c_cmd_link_delete(cmd);
		}
		printf("\n");		
		
	}
	//vTaskDelete(NULL);
}[Codebox=cpp file=Untitled.cpp][/Codebox]
Attachments
io0_i2c.jpg
io0_i2c.jpg (155.66 KiB) Viewed 9195 times

username
Posts: 477
Joined: Thu May 03, 2018 1:18 pm

Re: is there any issue using io0/io4 for i2c?

Postby username » Tue May 07, 2019 3:56 pm

You never want to use internal pullups for I2C on ANY device. They will all be too weak to do the job properly.

Who is online

Users browsing this forum: No registered users and 90 guests