esp32 wrrom 32E with esp idf I2C master

Gaston1980
Posts: 28
Joined: Sun Oct 06, 2024 10:26 am

esp32 wrrom 32E with esp idf I2C master

Postby Gaston1980 » Mon Oct 07, 2024 11:30 am

m using a esp32wroom 32E with the IDE and I'm trying to write to the slave some data, I write the code :

Code: Select all

  
      i2c_master_bus_config_t master_cfg={
        .i2c_port = I2C_NUM_0,
        .scl_io_num = MASTER_I2C_SCL,
        .sda_io_num = MASTER_I2C_SDA,
        .glitch_ignore_cnt = 0,
        .clk_source = I2C_CLK_SRC_DEFAULT
    };
    i2c_master_bus_handle_t bus_handle;
    ESP_ERROR_CHECK(i2c_new_master_bus(&master_cfg,&bus_handle));
    //ESP_ERROR_CHECK(i2c_master_probe(bus_handle, 0x21, -1));    
    ESP_LOGD(TAG,"I2C master probe");
    //config device slave
    i2c_device_config_t device_cfg={
        .device_address = 0x21,
        .dev_addr_length = I2C_ADDR_BIT_LEN_7,
        .scl_speed_hz = MASTER_I2C_CLOCK
    };
    i2c_master_dev_handle_t dev_handle;
    ESP_ERROR_CHECK(i2c_master_bus_add_device(bus_handle,&device_cfg,&dev_handle));
    
Which works OK if I just use the master probe to test if the slave device is detected....now if I use

Code: Select all

ESP_ERROR_CHECK(i2c_master_transmit_receive(dev_handle, PID, sizeof(PID), sizeof(data), 1, -1));
I got nothing on the scope, nothing and a bunch of warning just like this old thread http://esp32.io/viewtopic.php?p=133297
the esp32 reboot again and again......
the PID and data are uint8_t variables
why?
why the master transmite recibe is not working if the master probe detect the slave?
Regards
Gastón

MicroController
Posts: 1725
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: esp32 wrrom 32E with esp idf I2C master

Postby MicroController » Mon Oct 07, 2024 10:38 pm

You're passing the wrong arguments to i2c_master_transmit_receive().
Both the data to transmit and receive are defined by a pointer to their location and the length of the data to transfer from/to that location.

Try this:

Code: Select all

ESP_ERROR_CHECK(i2c_master_transmit_receive(dev_handle, &PID, sizeof(PID), &data, sizeof(data), -1));

Who is online

Users browsing this forum: VinayDand and 411 guests