-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
i2c_master: Support I2C transaction failure notification because the new ESP32 I2C driver always returns ESP_OK (IDFGH-12075) #13136
Comments
(I'm adding mention of #13134, but I think that's a slightly different issue.) |
i2c_master_bus_t->status
because i2c_master_transmit_receive
always returns ESP_OK!i2c_master_bus_t->status
because i2c_master_transmit_receive
returns ESP_OK on device failure!
i2c_master_bus_t->status
because i2c_master_transmit_receive
returns ESP_OK on device failure!i2c_master_bus_t->status
because i2c_master_transmit_receive
returns ESP_OK on device failure! (IDFGH-12075)
I know there is no nack checking... Fine, I will add one... |
After some testing, the callback NACK checking does not work in async, either. It always returns IMHO, error handling is a critical consideration in microcontroller development: Maybe this should be escalated from Feature to BUG status. |
i2c_master_bus_t->status
because i2c_master_transmit_receive
returns ESP_OK on device failure! (IDFGH-12075)
@mythbuster5, I was going to write a PR for this issue, but it looks like esp-idf/components/esp_driver_i2c/i2c_master.c Lines 439 to 441 in 60a2bf6
However, esp-idf/components/esp_driver_i2c/i2c_master.c Lines 1064 to 1070 in 60a2bf6
Below is the diff we were working on, it's just a diff --git a/components/esp_driver_i2c/i2c_master.c b/components/esp_driver_i2c/i2c_master.c
index 175fb15703..5a50f048b4 100644
--- a/components/esp_driver_i2c/i2c_master.c
+++ b/components/esp_driver_i2c/i2c_master.c
@@ -967,6 +967,11 @@ esp_err_t i2c_master_bus_reset(i2c_master_bus_handle_t bus_handle)
return ESP_OK;
}
+i2c_master_status_t i2c_master_bus_status(i2c_master_bus_handle_t i2c_master)
+{
+ return i2c_master->status;
+}
+
esp_err_t i2c_master_transmit(i2c_master_dev_handle_t i2c_dev, const uint8_t *write_buffer, size_t write_size, int xfer_timeout_ms)
{
ESP_RETURN_ON_FALSE(i2c_dev != NULL, ESP_ERR_INVALID_ARG, TAG, "i2c handle not initialized");
diff --git a/components/esp_driver_i2c/include/driver/i2c_master.h b/components/esp_driver_i2c/include/driver/i2c_master.h
index 228f64fcc9..b8b9bb0abf 100644
--- a/components/esp_driver_i2c/include/driver/i2c_master.h
+++ b/components/esp_driver_i2c/include/driver/i2c_master.h
@@ -196,6 +196,18 @@ esp_err_t i2c_master_register_event_callbacks(i2c_master_dev_handle_t i2c_dev, c
*/
esp_err_t i2c_master_bus_reset(i2c_master_bus_handle_t bus_handle);
+/**
+ * @brief Return the status of the last I2C transaction.
+ *
+ * @param bus_handle I2C bus handle.
+ * @return
+ * - I2C_STATUS_DONE: I2C command done
+ * - I2C_STATUS_TIMEOUT: I2C bus status error, and operation timeout
+ * - I2C_STATUS_ACK_ERROR: ack error status for current master command
+ * - Otherwise: transaction in progress (see `i2c_master_status_t`)
+ */
+i2c_master_status_t i2c_master_bus_status(i2c_master_bus_handle_t i2c_master);
+
/**
* @brief Wait for all pending I2C transactions done
* |
@mythbuster5 |
It should be done already, I forgot to close it. |
Is your feature request related to a problem?
Originally posted here: Why does i2c_master_transmit_receive return ESP_OK when the device is unplugged?
I can successfully read from an I2C device (its an RTC clock) and it works. However, if the device is disconnected from the bus, the
i2c_master_transmit_receive()
function always returnsESP_OK
.Digging through the code, it appears that synchronous requests will set (or rather, pass-through) any of these in
i2c_master_bus_t->status
:as shown in esp_driver_i2c/i2c_master.c:
Describe the solution you'd like.
Provide an API accessor, something like this:
and expose these enums publically (if they are not already):
Describe alternatives you've considered.
Could try using the async code and work with thei2c_master_event_t
enum values in the i2c_master event callback. According to the forum response, that should work, but I've not tried it yet. However, it would be nice to trivially query the status of the previous i2c request for sync requests without setting up everything needed for async.Update: I tried the async code using this simple test project but it provides no mechanism to get a bus read failure status of any kind. There appears to be no alternative: neither sync nor async can provide an indication of i2c request failure.
Additional context.
No response
The text was updated successfully, but these errors were encountered: