I can't get my ESP32-WROOM-32 to send any data over SDA with the I2C libraries.
I'm using GPIO 21 for SDA, and GPIO 22 for SCL.
First, I wrote the functionality with the Arduino library, using just the pinMode(), digitalWrite(), etc.
That worked perfectly fine, and I could easily communicate with the slave device.
So, the pins SDA (21) and SCL (22) both work.
Then, I tried implementing that with the Arduino supplied library Wire.
The code was, in a nutshell, more or less this:
Code: Select all
#include <Wire.h>
Wire.begin();
Wire.beginTransmission(0x43);
Wire.write(0x0A);
Wire.endTransmission();
But the SCL (yellow) seems alright.
Not so visible in the image, but in the end of transmission SDA falls LOW before SCL raises HIGH.
Even that they seem to overlap, when zoomed out to this scale.
Now, I tried to implement it with the espidf framework (assuming that would help).
But I'm getting the exact same signal as output as with the Arduino Wire library.
platformio.ini
Code: Select all
[env:esp32dev]
platform = espressif32 # Version 6.4.0
board = esp32dev # ESP32 Dev Kit C V4, from AZdelivery
framework = espidf # Version 3.50101.230828
Code: Select all
#include <stdint.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "driver/i2c.h"
#define PIN_SDA 21
#define PIN_SCL 22
void main() {
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = PIN_SDA,
.scl_io_num = PIN_SCL,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master = { .clk_speed = 10000 }, // 10k, and I've tried also 100k
};
esp_err_t err1 = i2c_param_config(I2C_NUM_0, &conf);
esp_err_t err2 = i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);
// No errors, both err1 and err2 were OK
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
esp_err_t err1 = i2c_master_start(cmd);
esp_err_t err2 = i2c_master_write_byte(cmd, 0x55, false); // 0x55, or any uint8_t
esp_err_t err3 = i2c_master_stop(cmd);
esp_err_t err4 = i2c_master_cmd_begin(I2C_NUM_0, cmd, 1000 / portTICK_PERIOD_MS);
i2c_cmd_link_delete(cmd);
// err1, err2, err3 were all OK
// TIMEOUT with err4
// I tried adding various delays between the calls above, but no help
}
It seems to me the issue is in essence that the SDA is not able to write the data out.
Or that, instead, it would just always write 0xFF out.
I would really appreciate help, if someone could point me to the right direction here.
If there was something more I could do to debug it further...?