esp32 - I2C

Posts: 5
Joined: Tue Feb 16, 2021 2:37 pm

esp32 - I2C

Postby kurtwerbrouck » Fri Jun 18, 2021 3:34 pm


i am trying to run the next example from the i2c api datasheet @ - API I2C.

#include ""driver/i2c.h""

#define I2C_SCL_IO 22
#define I2C_SDA_IO 21
#define I2C_FREQ_HZ 100000
#define I2C_PORT_NUM I2C_NUM_0
#define I2C_TX_BUF_DISABLE 0
#define I2C_RX_BUF_DISABLE 0
#define I2C_FREQ_HZ 100000

int i2c_master_port = I2C_PORT_NUM;
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = I2C_SDA_IO,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_io_num = I2C_SCL_IO,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = I2C_FREQ_HZ,

in the arduino , when Verify/Compile i got the next error:
ESP32-MQTT-ESP32:71:1: error: expected primary-expression before '.' token
.master.clk_speed = I2C_FREQ_HZ,

Does someone has any idea what is wrong?


Posts: 178
Joined: Mon Jul 22, 2019 3:20 pm

Re: esp32 - I2C

Postby lbernstone » Fri Jun 18, 2021 9:27 pm

This sort of variable assignment is C. The C++ compiler will not accept elements out of order or missing, which makes it fail with unions or other compound elements. Change them into individual direct assignments (e.g. conf.master.clk_speed = I2C_FREQ_HZ;). You will likely also need to cast many of those constants to the type the structure expects (C does this implicitly).

Return to “ESP32 Arduino”

Who is online

Users browsing this forum: dimake and 9 guests