Error detecting the state of the NAK I2C

Andy Korg
Posts: 4
Joined: Sat Jan 04, 2020 2:25 pm

Error detecting the state of the NAK I2C

Postby Andy Korg » Sun Apr 12, 2020 8:22 am

Good afternoon!
Trying to get an ESP_FAIL response for i2c device with wrong address. But always get ESP_OK
(And if the address is correct, then the code works fine.)
Please tell me what could be the matter?
port setup:

Code: Select all

		i2c_config_t conf = {
			.mode = I2C_MODE_MASTER,
			.sda_io_num = confSensor.sda,
			.sda_pullup_en = GPIO_PULLUP_ENABLE, //+ external resisor 10K
			.scl_io_num = confSensor.scl,
			.scl_pullup_en = GPIO_PULLUP_ENABLE, //+ external resisor 10K
			.master.clk_speed = i2c_frequency
		};
		// @formatter:on
		ret = i2c_param_config(confSensor.port, &conf);
build a command link :

Code: Select all

	uint8_t buf[SENSOR_VAL_LEN_BYTE];

	i2c_cmd_handle_t cmd = i2c_cmd_link_create();
	i2c_master_start(cmd);
	i2c_master_write_byte(cmd, (SENSOR_ADRESS << 1) | I2C_MASTER_READ, I2C_MASTER_ACK);
	i2c_master_read(cmd, buf, SENSOR_VAL_LEN_BYTE, I2C_MASTER_NACK);
	i2c_master_stop(cmd);
	esp_err_t ret = i2c_master_cmd_begin(sensors[sensor].port, cmd, 1000 / portTICK_RATE_MS);
	i2c_cmd_link_delete(cmd);
	if (ret == ESP_OK) {
		uint8_t i = 0;
		for (; i < SENSOR_VAL_LEN_BYTE; i++) {
			ESP_LOGI(TAG, "sensor Ok = %x", buf[i]);
		}
		*value = buf[0];
	}
	else{
		ESP_LOGI(TAG, "sensor err = %s", esp_err_to_name(ret));
	}

	return ret;
	
logic analyzer chart:
Attachments
lg.JPG
lg.JPG (40.38 KiB) Viewed 2048 times

Who is online

Users browsing this forum: Majestic-12 [Bot] and 127 guests