- 
                Notifications
    You must be signed in to change notification settings 
- Fork 7.7k
Description
Board
esp32s3
Device Description
ESP32S3 WROOM 1 N16R8 plain module.
Hardware Configuration
#define SDA_M                       GPIO_NUM_47  // GPIO 47
#define SCL_M                       GPIO_NUM_48  // GPIO 48
Version
v3.3.2
Type
Task
IDE Name
Arduino IDE ver 2.3.6
Operating System
Windows 10
Flash frequency
80Mhz
PSRAM enabled
yes
Upload speed
921600
Description
i2c_master_transmit() fails with an error synchronous_transaction(945): I2C transaction failed when .trans_queue_depth = 0; but when .trans_queue_depth is set to non zero (doesnt matter the number) number the quee is filled to the brim and transaction fails.
It seems it attempting to do asynchronous transaction since there is also this error
i2c_master_multi_buffer_transmit(1214): I2C transaction failed just after the first one. Attempting to restrict the transaction with i2c_master_register_event_callbacks(ads->_dev_handle, NULL, NULL); and .trans_queue_depth = 0; the program crashes completely.
I am developing a custom library for ads1015. I will attach the .cpp files here
Sketch
#include "driver/i2c_master.h"
#include "esp_log.h"
#include "driver/gpio.h"
#include <ads1015_esp32.h>
// --- Master Bus 1 Definitions ---
#define SDA_M                       GPIO_NUM_47  // GPIO 47
#define SCL_M                       GPIO_NUM_48  // GPIO 48
#define I2C_MASTER_NUM              I2C_NUM_0     // I2C port 0
#define I2C_MASTER_FREQ_HZ          400000        // 400kHz
#define I2C_MASTER_TIMEOUT_MS       100
#define I2C_MASTER_TX_BUF_DISABLE   0             // I2C master does not need buffer
#define I2C_MASTER_RX_BUF_DISABLE   0             // I2C master does not need buffer
ADS1015 ads_device;
esp_err_t ret;
i2c_slave_dev_handle_t slave_bus_handle;
static const char *TAG = "I2C_INIT";
float
  TS1 = 0.0000,            
  TS2 = 0.0000; 
  const int baudRat = 115200; 
  /**
 * @brief Initialize the I2C Master bus
 */
 i2c_master_bus_handle_t i2c_master_init(void) {
  gpio_set_pull_mode(SDA_M, GPIO_FLOATING);
  gpio_set_pull_mode(SCL_M, GPIO_FLOATING);
  // 1. Configure the I2C bus parameters
    i2c_master_bus_config_t i2c_master_bus_config = {
        .i2c_port = I2C_NUM_0, // Use I2C port 0
        .sda_io_num = SDA_M,
        .scl_io_num = SCL_M,
        .clk_source = I2C_CLK_SRC_DEFAULT,
        .glitch_ignore_cnt = 7,
    };
    i2c_master_bus_config.trans_queue_depth = 0;
    i2c_master_bus_config.intr_priority = 0;
    // 2. Create the I2C Master Bus instance
    i2c_master_bus_handle_t big_bus_handle;
    esp_err_t err = i2c_new_master_bus(&i2c_master_bus_config, &big_bus_handle);
    if (err != ESP_OK) {
        // Handle error: ESP_LOGE("I2C", "Failed to init I2C bus: %s", esp_err_to_name(err));
        return NULL; 
    }
    ESP_LOGI("I2C", "I2C Master bus initialized successfully on port %d", I2C_NUM_0);
    return big_bus_handle;
}
void setup() {
  Serial.begin(baudRat);  //Our lovely cereal
  
  ESP_LOGI(TAG, "Initializing I2C Master on Port 0 (SDA:47, SCL:48)...");
    i2c_master_bus_handle_t master_bus_handle = i2c_master_init();
    if(master_bus_handle == NULL) {
      ESP_LOGI(TAG, "Master bus initialized Unsuccessful.");
      while(1);
    }
      ADS1015_init(&ads_device, 0x48);
    // 3. Begin Communication
    esp_err_t err = ADS1015_begin(&ads_device, I2C_MASTER_FREQ_HZ, master_bus_handle, 0);
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "Failed to initialize ADS1015. Stopping application.");
        return;
    }
    // Optional: Change the Gain (PGA) to +/- 2.048V for finer resolution
    err = ADS1015_setGain(&ads_device, ADS1015_PGA_4_096V);
    if (err == ESP_OK) {
        ESP_LOGI(TAG, "Set PGA to +/- 2.048V.");
    }
        Serial.println("Setup finished.");
  }
  void loop() {
    //ElegantOTA.loop();
   // server.handleClient();
   int16_t hold;
  esp_err_t err;
   for (int i = 0; i < 4; i++) {
      err = ADS1015_readADC_SingleEnded(&ads_device, 0, &hold);
        
      if (err == ESP_OK) {
        hold = ADS1015_voltageFromADC(hold, ads_device._config & ADS1015_PGA_MASK); 
          TS1 = TS1 + hold;
      } else {
          ESP_LOGE(TAG, "Error reading ADC: %s", esp_err_to_name(err));
      }
      if (err == ESP_OK) {
          TS2 = TS2 + hold;
      } else {
          ESP_LOGE(TAG, "Error reading ADC: %s", esp_err_to_name(err));
      }
      //sampleStoreTS++;
    vTaskDelay(20);
  }
  }Debug Message
09:53:06.921 -> E (33622) i2c.master: s_i2c_synchronous_transaction(945): I2C transaction failed
09:53:06.921 -> E (33622) i2c.master: i2c_master_multi_buffer_transmit(1214): I2C transaction failed
09:53:06.921 -> E (33626) ADS1015: Failed to write to register 0x01: ESP_ERR_INVALID_STATE
09:53:06.921 -> [ 33651][E][sketch_oct25a.ino:100] loop(): [I2C_INIT] Error reading ADC: ESP_ERR_INVALID_STATE
09:53:06.957 -> [ 33671][E][sketch_oct25a.ino:106] loop(): [I2C_INIT] Error reading ADC: ESP_ERR_INVALID_STATE
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.