Updated examples of new I2C master/slave driver for IDF 5.2.x...

skiddd
Posts: 11
Joined: Sat May 28, 2022 8:58 am

Updated examples of new I2C master/slave driver for IDF 5.2.x...

Postby skiddd » Wed Mar 13, 2024 3:13 pm

Greetings esteemed colleagues,

I am currently migrating a project from IDF 5.1.3 into IDF 5.2.1 and I am having problems
using the new i2c_slave.c driver...

I already updated my source code accordingly to match the instructions in the API Reference here:
https://docs.espressif.com/projects/esp ... s/i2c.html

However, I get a early startup error + crash making my current project unusable:

Code: Select all

Waiting for the device to reconnect...
I (1441) esp_psram: SPI SRAM memory test OK
I (1450) cpu_start: Pro cpu start user code
I (1450) cpu_start: cpu freq: 240000000 Hz
I (1450) heap_init: Initializing. RAM available for dynamic allocation:
I (1451) heap_init: At 3FCA69F8 len 00042D18 (267 KiB): RAM
I (1451) heap_init: At 3FCE9710 len 00005724 (21 KiB): RAM
I (1451) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (1451) heap_init: At 600FE014 len 00001FD4 (7 KiB): RTCRAM
I (1452) esp_psram: Adding pool of 8192K of PSRAM memory to heap allocator
I (1453) spi_flash: detected chip: gd
I (1453) spi_flash: flash io: dio
I (1453) flash_encrypt: Flash encryption mode is RELEASE
E (1454) i2c: CONFLICT! driver_ng is not allowed to be used with this old driver
I am already using
#include "driver/i2c_slave.h"

and removed
#include "driver/i2c.h"

from my source code....

I also tried to manually add
CONFIG_SOC_I2C_SUPPORT_SLAVE=y

in sdkconfig because I could not find this option in the menuconfig GUI.


I then tried to check the i2c examples inside
C:\Espressif\frameworks\esp-idf-v5.2.1\examples\peripherals\i2c\

but it turns out that they are all still using the old (already deprecated) i2c driver.

Are there working examples using the new i2c_slave drivers available?

Should I hold off updating to the new i2c drivers?


Best Regards,

skiddd
Posts: 11
Joined: Sat May 28, 2022 8:58 am

Re: Updated examples of new I2C master/slave driver for IDF 5.2.x...

Postby skiddd » Wed Mar 27, 2024 3:30 pm

Can anybody from Espressif confirm that there are in fact no examples based on the new i2c driver from IDF 5.2 / 5.2.1 ?

User avatar
eccentricOrange
Posts: 1
Joined: Mon Jun 17, 2024 11:37 am

Re: Updated examples of new I2C master/slave driver for IDF 5.2.x...

Postby eccentricOrange » Fri Jun 21, 2024 3:38 pm

I'm also struggling with the example code provided in the documentation. https://docs.espressif.com/projects/esp ... slave-read.

After filling in some of the undefined variables and things, I'm not even able to get the following to compile. Please help me out, I'm on IDF 5.2.2.
  1. #pragma once
  2.  
  3. #include "driver/i2c_slave.h"
  4. #include "esp_err.h"
  5. #include "freertos/queue.h"
  6.  
  7. #define DATA_LENGTH 8
  8.  
  9. static IRAM_ATTR bool i2c_slave_rx_done_callback(i2c_slave_dev_handle_t channel, const i2c_slave_rx_done_event_data_t *edata, void *user_data)
  10. {
  11.     BaseType_t high_task_wakeup = pdFALSE;
  12.     QueueHandle_t receive_queue = (QueueHandle_t)user_data;
  13.     xQueueSendFromISR(receive_queue, edata, &high_task_wakeup);
  14.     return high_task_wakeup == pdTRUE;
  15. }
  16.  
  17. uint8_t *data_rd = (uint8_t *) malloc(DATA_LENGTH);
  18. uint32_t size_rd = 0;
  19.  
  20. i2c_slave_config_t i2c_slv_config = {
  21.     .addr_bit_len = I2C_ADDR_BIT_LEN_7,
  22.     .clk_source = I2C_CLK_SRC_DEFAULT,
  23.     .i2c_port = I2C_NUM_1,
  24.     .send_buf_depth = 256,
  25.     .scl_io_num = 15,
  26.     .sda_io_num = 13,
  27.     .slave_addr = 0x10,
  28. };
  29.  
  30. i2c_slave_dev_handle_t slave_handle;
  31. ESP_ERROR_CHECK(i2c_new_slave_device(&i2c_slv_config, &slave_handle));
  32.  
  33. s_receive_queue = xQueueCreate(1, sizeof(i2c_slave_rx_done_event_data_t));
  34. i2c_slave_event_callbacks_t cbs = {
  35.     .on_recv_done = i2c_slave_rx_done_callback,
  36. };
  37. ESP_ERROR_CHECK(i2c_slave_register_event_callbacks(slave_handle, &cbs, s_receive_queue));
  38.  
  39. i2c_slave_rx_done_event_data_t rx_data;
  40. ESP_ERROR_CHECK(i2c_slave_receive(slave_handle, data_rd, DATA_LENGTH));
  41. xQueueReceive(s_receive_queue, &rx_data, pdMS_TO_TICKS(10000));
  42. // Receive done.

Who is online

Users browsing this forum: No registered users and 68 guests