Hi - I'm trying to get a simple I2C program to talk to a MSP23017 chip but the i2c_master_cmd_begin reports a time-out. If I move the sda/clk leads to my Raspberry the chip works fine so I'm probably doing something wrong with the ESP32. The code is
#define SDA_PIN 18
#define SCL_PIN 19
i2c_config_t conf;
conf.mode = I2C_MODE_MASTER;
conf.sda_io_num = SDA_PIN;
conf.scl_io_num = SCL_PIN;
conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
conf.master.clk_speed = 100000;
printf("call config\n");
vTaskDelay(5000/portTICK_PERIOD_MS);
i2c_param_config(I2C_NUM_0, &conf);
printf("after config\n");
vTaskDelay(1000/portTICK_PERIOD_MS);
espRc = i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);
printf("after driver install rc = %d\n", espRc);
vTaskDelay(1000/portTICK_PERIOD_MS);
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
ESP_ERROR_CHECK(i2c_master_start(cmd));
ESP_ERROR_CHECK(i2c_master_write_byte(cmd, (0x24 << 1) | I2C_MASTER_WRITE, 1 ));
// i2c_master_write_byte(cmd, 0x1, 1);
// i2c_master_write_byte(cmd, 0x0, 1); // set output bits
ESP_ERROR_CHECK(i2c_master_stop(cmd));
do{
espRc = i2c_master_cmd_begin(I2C_NUM_0, cmd, 1/portTICK_PERIOD_MS);
printf("after init begin rc = %d\n", espRc);
vTaskDelay(3000/portTICK_PERIOD_MS);
i2c_cmd_link_delete(cmd);
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
ESP_ERROR_CHECK(i2c_master_write_byte(cmd, (0x24 << 1) | I2C_MASTER_WRITE, 1 ));
} while (espRc != 0);
The output on the uart is
ets Jun 8 2016 00:22:57
rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0x00
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0008,len:8
load:0x3fff0010,len:3424
load:0x40078000,len:10384
load:0x40080000,len:252
entry 0x40080034
This is ESP32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 0, 4MB external flash
TM SDK version:v2.1-dirty
ESP32 chip ID:0x0
call config
after config
after driver install rc = 0
after init begin rc = 263
after init begin rc = 263
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x3 (DOWNLOAD_BOOT(UART0/UART1/SDIO_REI_REO_V2))
waiting for download
-- I pressed en/boot after 2 errors
I traced the leads with the following output
Any thoughts or suggestions would be much appreciated
Thanks
Tom
I2C time out
Re: I2C time out
Changing the GPIO pins to 12&14 or 21&22 does get the communication working; however, it runs for anywhere from 2 seconds to ~1 minute and then starts getting timeouts; sometimes, after several seconds it will start working again but then times out and usually never recovers.
Who is online
Users browsing this forum: dzungpv and 91 guests