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

New I2C Master driver i2c_master_probe() returning ESP_OK for all addresses (IDFGH-10967) #12159

Closed
3 tasks done
ammaree opened this issue Aug 30, 2023 · 73 comments
Closed
3 tasks done
Assignees
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally Type: Bug bugs in IDF

Comments

@ammaree
Copy link

ammaree commented Aug 30, 2023

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v5.2-dev-2383-g82cceabc6e

Operating System used.

macOS

How did you build your project?

Eclipse IDE

If you are using Windows, please specify command line type.

None

Development Kit.

Custom hardware

Power Supply used.

External 5V

What is the expected behavior?

API to return ESP_OK only when a device is found on a bus.

What is the actual behavior?

Returns ESP_OK for all addresses between 0x08 and 0x77

Steps to reproduce.

static int halI2C_CheckAddress(u8_t eCh, u16_t Addr) {
#if (buildI2C_MASTER_DRIVER == 0)
u8_t i2cBuf[I2C_LINK_RECOMMENDED_SIZE(1)];
i2c_cmd_handle_t i2cCmd = i2c_cmd_link_create_static(i2cBuf, sizeof(i2cBuf));
i2c_master_start(i2cCmd);
i2c_master_write_byte(i2cCmd, (Addr << 1) | I2C_MASTER_WRITE, ACK_CHECK_EN);
i2c_master_stop(i2cCmd);
int iRV = i2c_master_cmd_begin(eCh, i2cCmd, 10);
i2c_cmd_link_delete_static(i2cCmd);
return iRV;

#elif (buildI2C_MASTER_DRIVER == 1)
return i2c_master_probe(bus_handle[eCh], Addr, i2cTIMEOUT_DEFAULT);

#endif

}

int halI2C_CountDevices(u8_t eCh) {
u8_t DevCount = 0;
for (u16_t Addr = I2C_LOWEST_ADDR; Addr < I2C_TENBIT_ADDRESS; ++Addr) {
if (halI2C_CheckAddress(eCh, Addr) == ESP_OK) ++DevCount;
}
return DevCount;
}

Debug Logs.

No response

More Information.

No response

@ammaree ammaree added the Type: Bug bugs in IDF label Aug 30, 2023
@espressif-bot espressif-bot added the Status: Opened Issue is new label Aug 30, 2023
@github-actions github-actions bot changed the title New I2C Master driver i2c_master_probe() returning ESP_OK for all addresses New I2C Master driver i2c_master_probe() returning ESP_OK for all addresses (IDFGH-10967) Aug 30, 2023
@mythbuster5
Copy link
Collaborator

I noticed this issue already, will find time to fix it.

@mythbuster5
Copy link
Collaborator

BTW, you can use i2c_tool in example for probe an I2C device

@ammaree
Copy link
Author

ammaree commented Aug 30, 2023 via email

@ammaree
Copy link
Author

ammaree commented Sep 1, 2023

@mythbuster5
@o-marshmallow
@igrr

Any chance we can get some focus on this bug, sounds like it is known and simple.

We would really like to try the new I2C Master driver but due to our I2C device auto discovery process using the probe functionality, our testing has been very restricted.

Even if you can send me a patch to get it going, we will be able to stress test it on a wide range of platform and sensors.

Thanks

André

@mythbuster5
Copy link
Collaborator

@ammaree I have already merged changes in internal repo (it needs time to update on github). Let's see if it doesnt sync on github monday. I will append a patch here.

@o-marshmallow
Copy link
Collaborator

@ammaree In case you are really in a hurry, apply the patch that @mythbuster5 merged on master:
i2c_master.txt

@ammaree
Copy link
Author

ammaree commented Sep 3, 2023

@mythbuster5 @o-marshmallow

I have tried with the patches but now it hangs up earlier, around lines 882 or 883 of i2c_new_master_bus()

Previously my call to i2c_new_master_bus() passed perfectly and it only crashed later at the calls to i2c_master_probe()

I am happy to test more patches since I am under pressure to get the I2C fixed.

Thanks

@mythbuster5
Copy link
Collaborator

mythbuster5 commented Sep 4, 2023

Can I see how did you call the functions? I want to see the function calling order. Line 882 and 883 is easy inline functions, code shouldn't fail there. BTW, I want to see your log error as well.
image

@mythbuster5
Copy link
Collaborator

this is closed by commit command directly, feel free to reopen if you still have any problems

@ammaree
Copy link
Author

ammaree commented Sep 4, 2023

@mythbuster5 @o-marshmallow

I am not currently next to the device to enable a higher level of logging (currently INFO) but when tested last night no error messages were shown, device just hung as the lines indicated, never returned in spite of waiting ~15minutes

Entry point for the I2C device discovery is at halI2C_DevicesDiscover ().
Calling order as follows:

const halI2C_Init_t	halI2C_Init[halI2C_NUM] = {
	[halI2C_0] = {
		.i2c_port = I2C_NUM_0,
		.sda_io_num = GPIO_NUM_26,
		.scl_io_num = GPIO_NUM_27,
		.clk_source = I2C_CLK_SRC_DEFAULT,
		.flags.enable_internal_pullup = 1,
	},
}

int	halI2C_DevicesDiscover(void) {
	for (u8_t eCh = 0; eCh < halI2C_NUM; ++eCh) {
		halI2C_BusConfig(eCh);							// general bus init
		halI2C_GeneralCall(eCh, I2C_GENCALL_RESET_WRITE);
		for (u16_t Addr = I2C_LOWEST_ADDR; Addr < I2C_TENBIT_ADDRESS; ++Addr) {
			int iRV = halI2C_CheckAddress(eCh, Addr);
			if (iRV == ESP_OK) {
				if (i2cDevCount < i2cMAX_DEVICES) {
					i2c_di_t * psI2C = &sI2C_DI[i2cDevCount++];
					psI2C->Port = eCh;
					psI2C->Addr = Addr;
				} else {
					break;
				}
			}
		}
	}
	i2cDevCount = (i2cDevCount < i2cMAX_DEVICES) ? i2cDevCount : i2cMAX_DEVICES;
	return i2cDevCount;
}

void halI2C_BusConfig(u8_t eCh) {
	const halI2C_Init_t * psI2C_Init = &halI2C_Init[eCh];
	int iRV = i2c_new_master_bus(psI2C_Init, &hI2Cbus[eCh]);
        printfx("I2C Port:%d  SCL=%d  SDA=%d  PU%s iRV=%d\r\n",
		psI2C_Init->i2c_port, psI2C_Init->scl_io_num, psI2C_Init->sda_io_num,
		psI2C_Init->flags.enable_internal_pullup ? "en" : "dis", iRV);
}

void halI2C_GeneralCall(u8_t eCh, u8_t cCmd) {
	i2c_di_t * psI2C = &sI2C_DI[eCh];
	i2c_device_config_t dev_cfg = {
		.dev_addr_length = I2C_ADDR_BIT_LEN_7,
		.device_address = I2C_GENCALL_ADDRESS,
		.scl_speed_hz = 100000,
	};
	i2c_master_dev_handle_t hndl;
	ESP_ERROR_CHECK(i2c_master_bus_add_device(hI2Cbus[psI2C->Port], &dev_cfg, &hndl));
	ESP_ERROR_CHECK(i2c_master_transmit(hndl, &cCmd, sizeof(u8_t), i2cTIMEOUT_DEFAULT));
	ESP_ERROR_CHECK(i2c_master_bus_rm_device(hndl));
}

int halI2C_CheckAddress(u8_t eCh, u16_t Addr) {
	return i2c_master_probe(hI2Cbus[eCh], Addr, i2cTIMEOUT_DEFAULT);
}

@ammaree
Copy link
Author

ammaree commented Sep 4, 2023

@o-marshmallow @mythbuster5
Here is the complete log at highest level. As far as I can see not messages relating to I2C.
At the end the device is just hanging, not responding to console input, no output, no watchdog timeout.

`
0.017: #0 main vfs esp_vfs_register_fd_range is successful for range <54; 64) and VFS ID 4
0.020: #0 main wifi wifi driver task: 3ffd295c, prio:23, stack:3584, core=0
0.025: #0 wifi wifi wifi firmware version: 341633f
0.026: #0 wifi wifi wifi certification version: v7.0
0.027: #0 wifi wifi config NVS flash: enabled
0.028: #0 wifi wifi config nano formating: disabled
0.029: #0 wifi wifi Init data frame dynamic rx buffer num: 8
0.030: #0 wifi wifi Init management frame dynamic rx buffer num: 8
0.031: #0 wifi wifi Init management short buffer num: 32
0.032: #0 wifi wifi Init dynamic tx buffer num: 8
0.033: #0 wifi wifi Init static rx buffer size: 1600
0.034: #0 wifi wifi Init static rx buffer num: 4
0.034: #0 wifi wifi Init dynamic rx buffer num: 8
0.036: #0 wifi wifi hint=255, act_dur=<0,120>, pas_dur=360, nchans=14 history_num=0
0.037: #0 wifi wifi Set ps type: 0, coexist: 0

1.291: #0 wifi wifi clear blacklist
1.368: #0 wifi wifi ht40u freq=2422, chan=1
1.370: #0 wifi wifi filter: set rx policy=0
1.371: #0 wifi wifi mode : sta (c0:49:ef:c8:ad:84) + softAP (c0:49:ef:c8:ad:85)
1.373: #0 wifi wifi enable tsf
1.373: #0 wifi wifi filter: set rx policy=1
1.374: #0 wifi wifi connect status 0 -> 0
1.375: #0 wifi wifi filter: set rx policy=9
1.376: #0 wifi wifi ht40u freq=2422, chan=1
1.379: #0 wifi wifi Total power save buffer number: 4
1.380: #0 wifi wifi Init max length of beacon: 752/752
1.381: #1 wifi wifi Repeated 1x
1.382: #0 wifi wifi Start wifi connect
1.383: #1 main halRTC_GetTime IDF Time is 2023-09-04T09:39:42Z (SNTP flag=0)

1.383: #0 wifi wifi connect status 0 -> 0
1.385: #0 wifi wifi connect chan=0
1.386: #0 wifi wifi nvs=0, ssid=139Algernon, channel=255
1.386: #0 wifi wifi ssid=139Algernon match nvs 0, channel=255
1.386: #1 main SysFlag APrvrt BufOK LFS APP (x69)
1.387: #0 wifi wifi first chan=1
1.389: #1 main EvtFlag TIMER L1 (x801)
1.389: #0 wifi wifi connect status 0 -> 1
1.390: #1 main RunFlag 2/0x4 (x4)
1.391: #0 wifi wifi filter: set rx policy=3
1.392: #0 wifi wifi clear scan ap list
0x400fab90: cnx_start_handoff_cb at ??:?0f, priority=2, cb=0x400fab90, arg=0x00000000, ss_state=0x1, time=24702, index=0

1.395: #0 wifi wifi inter_channel_timeout: arg=0x00000000, ss_state=0x1
1.396: #0 wifi wifi perform scan: ss_state=0x9, chan<1,0>, dur<0,120>
1.397: #0 wifi wifi change: chan<1,0>, dur<0,120>
1.398: #0 wifi wifi enter start op, arg=0x3ffbaaf6
1.399: #0 wifi wifi scan operation: state=0x3, chan<1,0>, arg=0x3ffbaaf6, status=0
1.400: #0 wifi wifi scan specific ssid=139Algernon
1.401: #0 wifi wifi start max timer
1.492: #0 main RunFlag 2/0x4 1/0x2 (x6)
1.522: #0 wifi wifi scan end: arg=0x00000000, status=0, ss_state=0x3
1.523: #0 wifi wifi back home chan=<1,1>, current chan=<1,1>
1.524: #0 wifi wifi start scan timer
1.555: #0 wifi wifi oper_channel: arg=0x00000000 time=186913
1.556: #0 wifi wifi perform scan: ss_state=0x9, chan<2,0>, dur<0,120>
1.557: #0 wifi wifi change: chan<2,0>, dur<0,120>
1.558: #0 wifi wifi ht20 freq=2417, chan=2
1.559: #0 wifi wifi enter start op, arg=0x3ffbaaf6
1.560: #0 wifi wifi scan operation: state=0x3, chan<2,0>, arg=0x3ffbaaf6, status=0
1.562: #0 wifi wifi scan specific ssid=139Algernon
1.563: #0 wifi wifi start max timer
1.684: #0 wifi wifi scan end: arg=0x00000000, status=0, ss_state=0x3
1.685: #0 wifi wifi back home chan=<1,1>, current chan=<2,0>
1.686: #0 wifi wifi ht40u freq=2422, chan=1
1.687: #0 wifi wifi start scan timer
1.718: #0 wifi wifi oper_channel: arg=0x00000000 time=349789
1.719: #0 wifi wifi perform scan: ss_state=0x9, chan<3,0>, dur<0,120>
1.720: #0 wifi wifi change: chan<3,0>, dur<0,120>
1.721: #0 wifi wifi ht20 freq=2422, chan=3
1.722: #0 wifi wifi enter start op, arg=0x3ffbaaf6
1.723: #0 wifi wifi scan operation: state=0x3, chan<3,0>, arg=0x3ffbaaf6, status=0
1.725: #0 wifi wifi scan specific ssid=139Algernon
1.726: #0 wifi wifi start max timer
1.847: #0 wifi wifi scan end: arg=0x00000000, status=0, ss_state=0x3
1.848: #0 wifi wifi back home chan=<1,1>, current chan=<3,0>
1.849: #0 wifi wifi ht40u freq=2422, chan=1
1.850: #0 wifi wifi start scan timer
1.881: #0 wifi wifi oper_channel: arg=0x00000000 time=512672
1.882: #0 wifi wifi perform scan: ss_state=0x9, chan<4,0>, dur<0,120>
1.883: #0 wifi wifi change: chan<4,0>, dur<0,120>
1.884: #0 wifi wifi ht20 freq=2427, chan=4
1.885: #0 wifi wifi enter start op, arg=0x3ffbaaf6
1.886: #0 wifi wifi scan operation: state=0x3, chan<4,0>, arg=0x3ffbaaf6, status=0
1.887: #0 wifi wifi scan specific ssid=139Algernon
1.888: #0 wifi wifi start max timer
2.009: #0 wifi wifi scan end: arg=0x00000000, status=0, ss_state=0x3
2.010: #0 wifi wifi back home chan=<1,1>, current chan=<4,0>
2.011: #0 wifi wifi ht40u freq=2422, chan=1
2.013: #0 wifi wifi start scan timer
2.044: #0 wifi wifi oper_channel: arg=0x00000000 time=675502
2.045: #0 wifi wifi perform scan: ss_state=0x9, chan<5,0>, dur<0,120>
2.046: #0 wifi wifi change: chan<5,0>, dur<0,120>
2.047: #0 wifi wifi ht20 freq=2432, chan=5
2.048: #0 wifi wifi enter start op, arg=0x3ffbaaf6
2.049: #0 wifi wifi scan operation: state=0x3, chan<5,0>, arg=0x3ffbaaf6, status=0
2.050: #0 wifi wifi scan specific ssid=139Algernon
2.052: #0 wifi wifi start max timer
2.173: #0 wifi wifi scan end: arg=0x00000000, status=0, ss_state=0x3
2.174: #0 wifi wifi back home chan=<1,1>, current chan=<5,0>
2.175: #0 wifi wifi ht40u freq=2422, chan=1
2.176: #0 wifi wifi start scan timer
2.207: #0 wifi wifi oper_channel: arg=0x00000000 time=839058
2.208: #0 wifi wifi perform scan: ss_state=0x9, chan<6,0>, dur<0,120>
2.210: #0 wifi wifi change: chan<6,0>, dur<0,120>
2.211: #0 wifi wifi ht20 freq=2437, chan=6
2.212: #0 wifi wifi enter start op, arg=0x3ffbaaf6
2.213: #0 wifi wifi scan operation: state=0x3, chan<6,0>, arg=0x3ffbaaf6, status=0
2.214: #0 wifi wifi scan specific ssid=139Algernon
2.215: #0 wifi wifi start max timer
2.336: #0 wifi wifi scan end: arg=0x00000000, status=0, ss_state=0x3
2.337: #0 wifi wifi back home chan=<1,1>, current chan=<6,0>
2.338: #0 wifi wifi ht40u freq=2422, chan=1
2.340: #0 wifi wifi start scan timer
2.371: #0 wifi wifi oper_channel: arg=0x00000000 time=1002521
2.372: #0 wifi wifi perform scan: ss_state=0x9, chan<7,0>, dur<0,120>
2.373: #0 wifi wifi change: chan<7,0>, dur<0,120>
2.374: #0 wifi wifi ht20 freq=2442, chan=7
2.375: #0 wifi wifi enter start op, arg=0x3ffbaaf6
2.376: #0 wifi wifi scan operation: state=0x3, chan<7,0>, arg=0x3ffbaaf6, status=0
2.378: #0 wifi wifi scan specific ssid=139Algernon
2.379: #0 wifi wifi start max timer
2.500: #0 wifi wifi scan end: arg=0x00000000, status=0, ss_state=0x3
2.501: #0 wifi wifi back home chan=<1,1>, current chan=<7,0>
2.502: #0 wifi wifi ht40u freq=2422, chan=1
2.503: #0 wifi wifi start scan timer
2.534: #0 wifi wifi oper_channel: arg=0x00000000 time=1165826
2.535: #0 wifi wifi perform scan: ss_state=0x9, chan<8,0>, dur<0,120>
2.536: #0 wifi wifi change: chan<8,0>, dur<0,120>
2.537: #0 wifi wifi ht20 freq=2447, chan=8
2.539: #0 wifi wifi enter start op, arg=0x3ffbaaf6
2.540: #0 wifi wifi scan operation: state=0x3, chan<8,0>, arg=0x3ffbaaf6, status=0
2.541: #0 wifi wifi scan specific ssid=139Algernon
2.663: #0 wifi wifi scan end: arg=0x00000000, status=0, ss_state=0x3
2.664: #0 wifi wifi back home chan=<1,1>, current chan=<8,0>
2.665: #0 wifi wifi ht40u freq=2422, chan=1
2.667: #0 wifi wifi start scan timer
2.697: #0 wifi wifi oper_channel: arg=0x00000000 time=1329267
2.698: #0 wifi wifi perform scan: ss_state=0x9, chan<9,0>, dur<0,120>
2.700: #0 wifi wifi change: chan<9,0>, dur<0,120>
2.700: #0 wifi wifi ht20 freq=2452, chan=9
2.702: #0 wifi wifi enter start op, arg=0x3ffbaaf6
2.703: #0 wifi wifi scan operation: state=0x3, chan<9,0>, arg=0x3ffbaaf6, status=0
2.704: #0 wifi wifi scan specific ssid=139Algernon
2.705: #0 wifi wifi start max timer
2.760: #0 wifi wifi rsn valid: gcipher=3 ucipher=3 akm=5

2.761: #0 wifi wifi updated connection retries to 3
2.762: #0 wifi wifi profile match: ss_state=0x7
2.763: #0 wifi wifi scan histroy table is not full yet, add
2.764: #0 wifi wifi add ssid=139Algernon, chan=9 to scan history
2.785: #0 wifi wifi rsn valid: gcipher=3 ucipher=3 akm=5

2.787: #0 wifi wifi updated connection retries to 3
2.788: #0 wifi wifi profile match: ss_state=0x7
2.789: #0 wifi wifi update scan history ssid=139Algernon, channel=9
2.826: #0 wifi wifi scan end: arg=0x00000000, status=0, ss_state=0x7
2.827: #0 wifi wifi back home chan=<1,1>, current chan=<9,0>
2.828: #0 wifi wifi ht40u freq=2422, chan=1
2.829: #0 wifi wifi start scan timer
2.860: #0 wifi wifi oper_channel: arg=0x00000000 time=1492250
2.861: #0 wifi wifi perform scan: ss_state=0xd, chan<10,0>, dur<0,120>
2.863: #0 wifi wifi change: chan<10,0>, dur<0,120>
2.864: #0 wifi wifi ht20 freq=2457, chan=10
2.865: #0 wifi wifi enter start op, arg=0x3ffbaaf6
2.866: #0 wifi wifi scan operation: state=0x7, chan<10,0>, arg=0x3ffbaaf6, status=0
2.867: #0 wifi wifi scan specific ssid=139Algernon
2.869: #0 wifi wifi start max timer
2.989: #0 wifi wifi scan end: arg=0x00000000, status=0, ss_state=0x7
2.991: #0 wifi wifi back home chan=<1,1>, current chan=<10,0>
2.992: #0 wifi wifi ht40u freq=2422, chan=1
2.993: #0 wifi wifi start scan timer
3.024: #0 wifi wifi oper_channel: arg=0x00000000 time=1655664
3.025: #0 wifi wifi perform scan: ss_state=0xd, chan<11,0>, dur<0,120>
3.026: #0 wifi wifi change: chan<11,0>, dur<0,120>
3.027: #0 wifi wifi ht20 freq=2462, chan=11
3.028: #0 wifi wifi enter start op, arg=0x3ffbaaf6
3.030: #0 wifi wifi scan operation: state=0x7, chan<11,0>, arg=0x3ffbaaf6, status=0
3.031: #0 wifi wifi scan specific ssid=139Algernon
3.032: #0 wifi wifi start max timer
3.153: #0 wifi wifi scan end: arg=0x00000000, status=0, ss_state=0x7
3.154: #0 wifi wifi back home chan=<1,1>, current chan=<11,0>
3.155: #0 wifi wifi ht40u freq=2422, chan=1
3.156: #0 wifi wifi start scan timer
3.187: #0 wifi wifi oper_channel: arg=0x00000000 time=1819169
3.188: #0 wifi wifi perform scan: ss_state=0xd, chan<12,0>, dur<360,360>
3.190: #0 wifi wifi change: chan<12,0>, dur<360,360>
3.190: #0 wifi wifi ht20 freq=2467, chan=12
3.192: #0 wifi wifi enter start op, arg=0x3ffbaaf6
3.193: #0 wifi wifi scan operation: state=0x7, chan<12,0>, arg=0x3ffbaaf6, status=0
3.194: #0 wifi wifi passive scan, listen only
3.195: #0 wifi wifi start max timer
3.555: #0 wifi wifi scan end: arg=0x00000000, status=0, ss_state=0x7
3.557: #0 wifi wifi back home chan=<1,1>, current chan=<12,0>
3.558: #0 wifi wifi ht40u freq=2422, chan=1
3.559: #0 wifi wifi start scan timer
3.590: #0 wifi wifi oper_channel: arg=0x00000000 time=2221500
3.591: #0 wifi wifi perform scan: ss_state=0xd, chan<13,0>, dur<360,360>
3.592: #0 wifi wifi change: chan<13,0>, dur<360,360>
3.593: #0 wifi wifi ht20 freq=2472, chan=13
3.594: #0 wifi wifi enter start op, arg=0x3ffbaaf6
3.595: #0 wifi wifi scan operation: state=0x7, chan<13,0>, arg=0x3ffbaaf6, status=0
3.596: #0 wifi wifi passive scan, listen only
3.597: #0 wifi wifi start max timer
3.598: #0 wifi wifi rsn valid: gcipher=3 ucipher=3 akm=5

3.599: #0 wifi wifi updated connection retries to 3
3.601: #0 wifi wifi profile match: ss_state=0x7
3.601: #0 wifi wifi update scan history ssid=139Algernon, channel=13
3.701: #0 wifi wifi rsn valid: gcipher=3 ucipher=3 akm=5

3.702: #0 wifi wifi set max rate: from <rate=130, phy=3, sig=0> to <rate=144, phy=3 sig=0>
3.703: #0 wifi wifi sig_b=1, sig_g=0, sig_n=0, max_b=0, max_g=108, max_n=144
3.705: #0 wifi wifi profile match: ss_state=0x7
3.705: #0 wifi wifi update scan history ssid=139Algernon, channel=13
3.803: #0 wifi wifi rsn valid: gcipher=3 ucipher=3 akm=5

3.804: #0 wifi wifi profile match: ss_state=0x7
3.805: #0 wifi wifi update scan history ssid=139Algernon, channel=13
3.905: #0 wifi wifi rsn valid: gcipher=3 ucipher=3 akm=5

3.907: #0 wifi wifi profile match: ss_state=0x7
3.907: #0 wifi wifi update scan history ssid=139Algernon, channel=13
3.958: #0 wifi wifi scan end: arg=0x00000000, status=0, ss_state=0x7
3.959: #0 wifi wifi back home chan=<1,1>, current chan=<13,0>
3.960: #0 wifi wifi ht40u freq=2422, chan=1
3.961: #0 wifi wifi start scan timer
3.992: #0 wifi wifi oper_channel: arg=0x00000000 time=2623891
3.993: #0 wifi wifi perform scan: ss_state=0xd, chan<14,0>, dur<360,360>
3.994: #0 wifi wifi change: chan<14,0>, dur<360,360>
3.995: #0 wifi wifi ht20 freq=2484, chan=14
3.996: #0 wifi wifi enter start op, arg=0x3ffbaaf6
3.997: #0 wifi wifi scan operation: state=0x7, chan<14,0>, arg=0x3ffbaaf6, status=0
3.999: #0 wifi wifi passive scan, listen only
3.999: #0 wifi wifi start max timer
4.360: #0 wifi wifi scan end: arg=0x00000000, status=0, ss_state=0x7
4.361: #0 wifi wifi back home chan=<1,1>, current chan=<14,0>
4.362: #0 wifi wifi ht40u freq=2422, chan=1
4.363: #0 wifi wifi start scan timer
4.394: #0 wifi wifi oper_channel: arg=0x00000000 time=3026203
4.395: #0 wifi wifi back home chan=<1,1>, current chan=<1,1>
4.396: #0 wifi wifi filter: set rx policy=4
4.397: #0 wifi wifi first chan=1
4.398: #0 wifi wifi scan_done: arg=0x00000000, status=0, cur_time=3029865, scan_id=128, scan state=0
4.399: #0 wifi wifi call scan_done cb, arg=0x00000000
4.400: #0 wifi wifi handoff_cb: status=0
4.401: #0 wifi wifi best bss has set.
4.402: #0 wifi wifi ap found, mac=d4:ca:6d:96:fe:08
4.403: #0 wifi wifi bssid=d4:ca:6d:96:fe:08, LR=0
4.404: #0 wifi wifi new_bss=0x3ffc8b20, cur_bss=0x00000000, new_chan=<13,0>, cur_chan=1
4.405: #0 wifi wifi filter: set rx policy=5
4.407: #0 wifi wifi ap channel adjust o:1,1 n:13,2
4.408: #0 wifi wifi new:<13,0>, old:<1,1>, ap:<13,2>, sta:<13,0>, prof:1
4.409: #0 wifi wifi ht20 freq=2472, chan=13
4.410: #0 wifi wifi connect_op: status=0, auth=5, cipher=3
:5.727: #0 wifi wifi auth mode is not none
5.728: #0 wifi wifi connect_bss: auth=1, reconnect=0
5.728: #0 wifi wifi state: init -> auth (b0)
5.730: #0 wifi wifi start 1s AUTH timer
5.730: #0 wifi wifi clear scan ap list
5.733: #0 wifi wifi recv auth: seq=2, status=0
5.734: #0 wifi wifi state: auth -> assoc (0)
5.735: #0 wifi wifi restart connect 1s timer for assoc
5.748: #0 wifi wifi recv assoc: type=0x10
5.749: #0 wifi wifi filter: set rx policy=6
5.750: #0 wifi wifi state: assoc -> run (10)
5.751: #0 wifi wifi start 10s connect timer for 4 way handshake
5.754: #0 wifi wifi wpa_psk start
5.756: #0 wifi wifi wpa_psk handle succeed
5.765: #0 wifi wifi wpa_psk start
5.768: #0 wifi wifi wpa_psk handle succeed
5.770: #0 wifi wifi connected with 139Algernon, aid = 2, channel 13, BW20, bssid = d4:ca:6d:96:fe:08
5.771: #0 wifi wifi security: WPA2-PSK, phy: bgn, rssi: -49
5.772: #0 wifi wifi remove all except d4:ca:6d:96:fe:08 from rc list
5.774: #0 wifi wifi clear blacklist
5.774: #0 wifi wifi filter: set rx policy=7
5.775: #0 wifi wifi pm start, type: 0

5.776: #0 wifi wifi Send sta connected event
5.777: #0 wifi wifi connect status 1 -> 5
5.778: #0 wifi wifi obss scan is disabled
5.778: #0 wifi wifi start obss scan: obss scan is stopped
5.820: #0 main EvtFlag TIMER L2sta L1 (x803)
5.851: #0 wifi wifi AP's beacon interval = 102400 us, DTIM period = 1
6.286: #0 wifi wifi idx:0 (ifx:0, d4:ca:6d:96:fe:08), tid:0, ssn:3, winSize:64
`

@mythbuster5
Copy link
Collaborator

Oh, I reproduce the issue, the root cause is that one interrupt is lacked. The fix is on the way

@ammaree
Copy link
Author

ammaree commented Sep 5, 2023

I am very glad you found it. I have spent 4 days trying to make this work, gave up around 01h00 this morning.
Welcomer to send the patch and I will give it a try.

@mythbuster5
Copy link
Collaborator

mythbuster5 commented Sep 5, 2023

Feel very sorry and apologize for this.Try with this please~ @ammaree
i2c_master.txt

@ammaree
Copy link
Author

ammaree commented Sep 5, 2023 via email

@ammaree
Copy link
Author

ammaree commented Sep 5, 2023

Don't worry, very small, applied..

@mythbuster5
Copy link
Collaborator

i2c_master.txt
Yeah.. usually patch file needs two blank line at the end of file, but some sometime it might lack one line...BTW can i2c_master_probe work now?

@ammaree
Copy link
Author

ammaree commented Sep 5, 2023

It now runs through, does not hang anymore, but ...
It does not find any devices on a system where these are 3, 2x PCF8574 (0x22 & 0x24) and 1x DS1307 (0x68)

@mythbuster5
Copy link
Collaborator

let me check

@mythbuster5
Copy link
Collaborator

Then it's very weird. It works well on my board. I can show you the very simple testing code and result. (I connect two devices on one bus)

i2c_master_bus_config_t i2c_bus_config = {
        .clk_source = I2C_CLK_SRC_DEFAULT,
        .i2c_port = 0,
        .scl_io_num = 4,
        .sda_io_num = 5,
    };
    i2c_master_bus_handle_t bus_handle;

    ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_config, &bus_handle));

    esp_err_t ret;
    uint8_t i;
    for (i =0x01; i < 0x90; i++) {
        ret =i2c_master_probe(bus_handle, i, -1);
        if (ret == 0) {
            printf("bingo! addr: %x\n", i);
        }
    }

image

@mythbuster5
Copy link
Collaborator

What you can do maybe check on a logic analyzer and see if the sending address is exist, there should be an ack on the bus, otherwise, will be nack.

@ammaree
Copy link
Author

ammaree commented Sep 5, 2023

Don't have logic analyser or scope on hand but...
I have a compile time option to select the old vs the new driver, only difference between the 2 options are

  1. void halI2C_BusConfig(u8_t eCh)
  2. bool halI2C_CheckAddress(u8_t eCh, u16_t Addr)
    which are different for the 2 drivers.

Old driver output:
I2C -0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -a -b -c -d -e -f
0x: xx xx xx xx xx xx xx xx -- -- -- -- -- -- -- --
1x: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
2x: -- -- 22 -- 24 -- -- -- -- -- -- -- -- -- -- --
3x: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
4x: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
5x: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
6x: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
7x: -- -- -- -- -- -- -- --

New driver output:
I2C -0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -a -b -c -d -e -f
0x: xx xx xx xx xx xx xx xx -- -- -- -- -- -- -- --
1x: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
2x: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
3x: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
4x: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
5x: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
6x: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
7x: -- -- -- -- -- -- -- --

And this situation is 100% consistent

@mythbuster5
Copy link
Collaborator

Which esp chip are you using. I tried esp32c3 and esp32 on my side. Both of them work pretty well..

@ammaree
Copy link
Author

ammaree commented Sep 6, 2023 via email

@espressif-bot espressif-bot added the Status: Done Issue is done internally label Sep 21, 2023
@puppy112358
Copy link

@puppy112358 have you checked if your pins are pulled high?

yeah,
image

@puppy112358
Copy link

    gpio_set_pull_mode(GPIO_NUM_4,GPIO_PULLUP_ONLY);
    gpio_set_pull_mode(GPIO_NUM_5,GPIO_PULLUP_ONLY);

I also have these codes above .

@puppy112358
Copy link

@R0nyx Actually, I can run the "i2c tools" in the examples normally . I have checked my codes and it ,cannot find where the problem is.

@R0nyx
Copy link

R0nyx commented Feb 29, 2024

@puppy112358 i've attached how my current i2c_master.c
i2c_lib_updated.txt
You can try giving it a go, see if it solves your issue

@puppy112358
Copy link

@R0nyx No, it did not change anything.

@R0nyx
Copy link

R0nyx commented Feb 29, 2024

@puppy112358 are you sure that your hardware setup is connected correctly?

@puppy112358
Copy link

@R0nyx Other part of my project can run normally. I think my hardware setup is connected correctly maybe.

@R0nyx
Copy link

R0nyx commented Feb 29, 2024

@puppy112358
i've tried your provided code with few modifications:
image

  i2c_master_bus_handle_t iic_bus_handle[1];

    ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_config_handle1, &iic_bus_handle[0]));
    for (uint8_t i = 0x10; i < 0x90; i++)
    {
        esp_err_t ret1 = i2c_master_probe(iic_bus_handle[0], i, 100);
        if (ret1 == ESP_OK)
        {
            ESP_LOGI(TAG, "address: %x", i);

        }
        else
        {
            ESP_LOGE(TAG, "address %x failed", i);
        }
    }

I'm new to development myself so i cannot provide you with a good answer
I would make sure that your sda pin is connected to sda pin on the slave, and same for the scl

@puppy112358
Copy link

@puppy112358 i've tried your provided code with few modifications: image

  i2c_master_bus_handle_t iic_bus_handle[1];

    ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_config_handle1, &iic_bus_handle[0]));
    for (uint8_t i = 0x10; i < 0x90; i++)
    {
        esp_err_t ret1 = i2c_master_probe(iic_bus_handle[0], i, 100);
        if (ret1 == ESP_OK)
        {
            ESP_LOGI(TAG, "address: %x", i);

        }
        else
        {
            ESP_LOGE(TAG, "address %x failed", i);
        }
    }

I'm new to development myself so i cannot provide you with a good answer I would make sure that your sda pin is connected to sda pin on the slave, and same for the scl

Actually , if the connection is wrong, it should return NOT FOUND instead every address is ESP_OK. @R0nyx

@R0nyx
Copy link

R0nyx commented Feb 29, 2024

@puppy112358 I know, but if you are using the same library as i do and follow espressif implementation guide, then you shouldn't be having any issues.
make sure your:

  gpio_set_direction(GPIO_NUM_4, GPIO_MODE_INPUT_OUTPUT); 
  gpio_set_direction(GPIO_NUM_5, GPIO_MODE_INPUT_OUTPUT);

@puppy112358
Copy link

@puppy112358 I know, but if you are using the same library as i do and follow espressif implementation guide, then you shouldn't be having any issues. make sure your:

  gpio_set_direction(GPIO_NUM_4, GPIO_MODE_INPUT_OUTPUT); 
  gpio_set_direction(GPIO_NUM_5, GPIO_MODE_INPUT_OUTPUT);

I have add these codes , while it did not change anything ...

@R0nyx
Copy link

R0nyx commented Feb 29, 2024

@puppy112358 then code wise it seems like you are doing everything correctly. I would make sure your lines are pulled high with multi meter or logic analyzer. Also check if Esp32 SDA pin is connected to your slave SDA pin and the same for SCL.

Oh and try this before setting pin configurations:

    gpio_reset_pin(GPIO_NUM_4);
    gpio_reset_pin(GPIO_NUM_5);

@puppy112358
Copy link

@puppy112358 then code wise it seems like you are doing everything correctly. I would make sure your lines are pulled high with multi meter or logic analyzer. Also check if Esp32 SDA pin is connected to your slave SDA pin and the same for SCL.

Oh and try this before setting pin configurations:

    gpio_reset_pin(GPIO_NUM_4);
    gpio_reset_pin(GPIO_NUM_5);

Oh ,the pins are not pulled high as I use the multi meter! but I have config the pin as it should be .

@R0nyx
Copy link

R0nyx commented Feb 29, 2024

@puppy112358 Try using the gpio_reset_pin() command before setting pins to high:

    gpio_reset_pin(GPIO_NUM_4);
    gpio_reset_pin(GPIO_NUM_5);
    gpio_set_direction(GPIO_NUM_4, GPIO_MODE_INPUT_OUTPUT); 
    gpio_set_direction(GPIO_NUM_5, GPIO_MODE_INPUT_OUTPUT);
    gpio_set_pull_mode(GPIO_NUM_4,GPIO_PULLUP_ONLY);
    gpio_set_pull_mode(GPIO_NUM_5,GPIO_PULLUP_ONLY);

@puppy112358
Copy link

@puppy112358 then code wise it seems like you are doing everything correctly. I would make sure your lines are pulled high with multi meter or logic analyzer. Also check if Esp32 SDA pin is connected to your slave SDA pin and the same for SCL.
Oh and try this before setting pin configurations:

    gpio_reset_pin(GPIO_NUM_4);
    gpio_reset_pin(GPIO_NUM_5);

Oh ,the pins are not pulled high as I use the multi meter! but I have config the pin as it should be .

Should I add other codes to pull up the pins?

@R0nyx
Copy link

R0nyx commented Feb 29, 2024

@puppy112358

@puppy112358 Try using the gpio_reset_pin() command before setting pins to high:

    gpio_reset_pin(GPIO_NUM_4);
    gpio_reset_pin(GPIO_NUM_5);
    gpio_set_direction(GPIO_NUM_4, GPIO_MODE_INPUT_OUTPUT); 
    gpio_set_direction(GPIO_NUM_5, GPIO_MODE_INPUT_OUTPUT);
    gpio_set_pull_mode(GPIO_NUM_4,GPIO_PULLUP_ONLY);
    gpio_set_pull_mode(GPIO_NUM_5,GPIO_PULLUP_ONLY);

@puppy112358
Copy link

image
My earlier codes has included these ....

@R0nyx
Copy link

R0nyx commented Feb 29, 2024

@puppy112358 does it work then?

@puppy112358
Copy link

No ,,,,how wired!!!
And as I said ,I can use the i2ctools in the i2c examples with the same ESP32-S3 and the same device .

@R0nyx
Copy link

R0nyx commented Feb 29, 2024

But are the SDA and SCL pins High when you meassure them now?

@puppy112358
Copy link

But are the SDA and SCL pins High when you meassure them now?

no, they are not high .

@R0nyx
Copy link

R0nyx commented Feb 29, 2024

it might be a dumb idea but try and see if the pin is still not high:

    gpio_reset_pin(GPIO_NUM_4);
    gpio_reset_pin(GPIO_NUM_5);
    gpio_set_direction(GPIO_NUM_4, GPIO_MODE_INPUT_OUTPUT); 
    gpio_set_direction(GPIO_NUM_5, GPIO_MODE_INPUT_OUTPUT);
    gpio_set_pull_mode(GPIO_NUM_4,GPIO_PULLUP_ONLY);
    gpio_set_pull_mode(GPIO_NUM_5,GPIO_PULLUP_ONLY);
gpio_set_level(GPIO_NUM4, 1);
gpio_set_level(GPIO_NUM5, 1);

@ammaree
Copy link
Author

ammaree commented Feb 29, 2024

I am not an I2C expert but have the new I2C master working on at least 7 different hardware platforms and with a total of 18 different I2C devices attached to the various platforms.

In all our configurations the initialisation is as follows:

const halI2C_Init_t halI2C_Init = {
	.i2c_port = I2C_NUM_0,
	.sda_io_num = GPIO_NUM_21,
	.scl_io_num = GPIO_NUM_22,
	.clk_source = I2C_CLK_SRC_DEFAULT,
	.glitch_ignore_cnt = 7,
	.intr_priority = 0,								// driver select default 1/2/3 etc
	.trans_queue_depth = 10,						// required to enable callbacks
	.flags.enable_internal_pullup = 1,                                // GPIO pull-ups enable
};
	ESP_ERROR_CHECK(i2c_new_master_bus(&halI2C_Init, &hI2Cbus));

We are not doing any other GPIO pin initialisation related to the I2C SD/SCL pins, everything is done within the i2c_new_master_bus() API.

To add a specific device, the following is all that is required.

	i2c_device_config_t dev_cfg = {
		.dev_addr_length = I2C_ADDR_BIT_LEN_7,
		.device_address = 0x38,                                    // device address
		.scl_speed_hz = 100000,                                   // bus speed for device
	};
	ESP_ERROR_CHECK(i2c_master_bus_add_device(hI2Cbus, &dev_cfg, &dev_hndl));

@Ownezx
Copy link

Ownezx commented Jun 3, 2024

Hi there, I'm also running in the same issue as previously described here.

I'm running on ESP-ADF 5.2.1, a devkit-C V4 with a ESP32-WROVER-E, and compiling my code in cpp.

i2c_master_bus_config_t i2c_bus_config;
i2c_bus_config.clk_source = I2C_CLK_SRC_DEFAULT;
i2c_bus_config.i2c_port = I2C_NUM_0;
i2c_bus_config.scl_io_num = gpio_num_t::GPIO_NUM_23;
i2c_bus_config.sda_io_num = gpio_num_t::GPIO_NUM_18;
i2c_bus_config.intr_priority = 0;
i2c_bus_config.trans_queue_depth = 10;
i2c_bus_config.glitch_ignore_cnt = 7;
i2c_bus_config.flags.enable_internal_pullup = 1;

i2c_master_bus_handle_t bus_handle;

ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_config, &bus_handle));

esp_err_t ret;
uint8_t i;
for (i = 0x01; i < 0x90; i++)
{
    ret = i2c_master_probe(bus_handle, i, 100);
    if (ret == ESP_OK)
    {
        printf("bingo! addr: %x\n", i);
    }
}

In the logs I have the following, so I would suppose that the GPIO pins are set up properly. I also verified with a voltmeter on pin 18 and 23 that they were at 3.3V.

I (314) main_task: Started on CPU0
I (324) main_task: Calling app_main()
I (324) gpio: GPIO[18]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0 
I (324) gpio: GPIO[23]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0 
bingo! addr: 1
bingo! addr: 2
bingo! addr: 3
bingo! addr: 4

Theoretically I should only find a device on addresses 0x28 and 0x50, but all address return an ESP_OK (0). The devices on are both detected and interfaced using external tools, so we know that it is active.

Does anybody have an idea why a pin at 3.3V would return an ESP_OK on a probe on all addresses?
From my understanding, if no ack is received it should return ESP_ERR_NOT_FOUND?

EDIT : To double check if Cpp compiling was the issue, I modified my code compile using C and I get the same result.
EDIT2 : I tried to change the pins to unused ones and unconnected ones to see if that was the issue I switched to 21/22 who have no connections whatsoever. I still get a device found on every single address.
EDIT3 : I created a new project using platformio to the esp on arduino framework. This led to the detection of the two devices at 0x28 and 0x50.

Here is the code used and the log output Code :
  // SPDX-FileCopyrightText: 2023 Carter Nelson for Adafruit Industries
  //
  // SPDX-License-Identifier: MIT
  // --------------------------------------
  // i2c_scanner
  //
  // Modified from https://playground.arduino.cc/Main/I2cScanner/
  // --------------------------------------
  
  #include <Arduino.h>
  #include <Wire.h>
  
  #define I2C_SDA 18
  #define I2C_SCL 23
  
  void setup()
  {
      Wire.begin(I2C_SDA, I2C_SCL);
  
      Serial.begin(115200);
      while (!Serial)
          delay(10);
      Serial.println("\nI2C Scanner");
  }
  
  void loop()
  {
      byte error, address;
      int nDevices;
  
      Serial.println("Scanning...");
  
      nDevices = 0;
      for (address = 1; address < 127; address++)
      {
          // The i2c_scanner uses the return value of
          // the Write.endTransmisstion to see if
          // a device did acknowledge to the address.
          Wire.beginTransmission(address);
          error = Wire.endTransmission();
  
          if (error == 0)
          {
              Serial.print("I2C device found at address 0x");
              if (address < 16)
                  Serial.print("0");
              Serial.print(address, HEX);
              Serial.println("  !");
  
              nDevices++;
          }
          else if (error == 4)
          {
              Serial.print("Unknown error at address 0x");
              if (address < 16)
                  Serial.print("0");
              Serial.println(address, HEX);
          }
      }
      if (nDevices == 0)
          Serial.println("No I2C devices found\n");
      else
          Serial.println("done\n");
  
      delay(5000); // wait 5 seconds for next scan
  }

Log :

Scanning...
I2C device found at address 0x28  !
I2C device found at address 0x50  !
done

EDIT 4 : As a workaround I have switched to the older i2c.h drivers and the devices are detected.

@voicevon
Copy link

I (314) main_task: Started on CPU0
I (324) main_task: Calling app_main()
I (324) gpio: GPIO[18]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0 
I (324) gpio: GPIO[23]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0 
bingo! addr: 1
bingo! addr: 2
bingo! addr: 3
bingo! addr: 4

Exactly same to me! on ESP32 Wroom

@tivetdb
Copy link

tivetdb commented Jul 22, 2024

Is this fixed or not?

@Ownezx
Copy link

Ownezx commented Jul 22, 2024

Considering there has been no activity since we both reported the issue perhaps not.

@mythbuster5, would it be possible to reopen this issue?

@mythbuster5
Copy link
Collaborator

I think if there still problem, you need to update the idf version. Because we already have automatically test toward this in internal CI https://github.com/espressif/esp-idf/blob/master/components/esp_driver_i2c/test_apps/i2c_test_apps/main/test_i2c_common.c#L150

@Ownezx
Copy link

Ownezx commented Jul 23, 2024

Thanks for the clarification, I'll update to 5.2.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

9 participants