Function esp_idf_svc::sys::i2c_master_probe

source ·
pub unsafe extern "C" fn i2c_master_probe(
    bus_handle: *mut i2c_master_bus_t,
    address: u16,
    xfer_timeout_ms: i32,
) -> i32
Expand description

@brief Probe I2C address, if address is correct and ACK is received, this function will return ESP_OK.

@param[in] bus_handle I2C master device handle that created by i2c_master_bus_add_device. @param[in] address I2C device address that you want to probe. @param[in] xfer_timeout_ms Wait timeout, in ms. Note: -1 means wait forever (Not recommended in this function).

@attention Pull-ups must be connected to the SCL and SDA pins when this function is called. If you get ESP_ERR_TIMEOUT while xfer_timeout_mswas parsed correctly, you should check the pull-up resistors. If you do not have proper resistors nearby.flags.enable_internal_pullup` is also acceptable.

@note The principle of this function is to sent device address with a write command. If the device on your I2C bus, there would be an ACK signal and function returns ESP_OK. If the device is not on your I2C bus, there would be a NACK signal and function returns ESP_ERR_NOT_FOUND. ESP_ERR_TIMEOUT is not an expected failure, which indicated that the i2c probe not works properly, usually caused by pull-up resistors not be connected properly. Suggestion check data on SDA/SCL line to see whether there is ACK/NACK signal is on line when i2c probe function fails.

@note There are lots of I2C devices all over the world, we assume that not all I2C device support the behavior like device_address+nack/ack. So, if the on line data is strange and no ack/nack got respond. Please check the device datasheet.

@return - ESP_OK: I2C device probe successfully - ESP_ERR_NOT_FOUND: I2C probe failed, doesn’t find the device with specific address you gave. - ESP_ERR_TIMEOUT: Operation timeout(larger than xfer_timeout_ms) because the bus is busy or hardware crash.