@meowsqueak I think @mikemoy is referring to my last post.
To reply his questions:
- I'm talking to a TCA9535 port expander
-I'm using ESP-IDF v3.0 (77eae33a7ec6c4d42552b07f3dc2f51d0ff4e49c)
-I use 1k8 resistor as pull-up. I had 10k but checking with oscilloscope the slope was very poor. Now the signals are ok (not too much ringing on the edge). From hardware side I think everything is OK.
-my code to write and read the port expander is based on the example provided in the esp-idf folders (just adapted for TCA9535):
Code: Select all
static void i2c_example_master_init()
{
int i2c_master_port = I2C_EXAMPLE_MASTER_NUM;
i2c_config_t conf;
conf.mode = I2C_MODE_MASTER;
conf.sda_io_num = I2C_EXAMPLE_MASTER_SDA_IO;
conf.sda_pullup_en = GPIO_PULLUP_DISABLE;
conf.scl_io_num = I2C_EXAMPLE_MASTER_SCL_IO;
conf.scl_pullup_en = GPIO_PULLUP_DISABLE;
conf.master.clk_speed = I2C_EXAMPLE_MASTER_FREQ_HZ;
i2c_param_config(i2c_master_port, &conf);
// i2c_hw_fsm_reset(i2c_master_port);
//ATTENTION: in function i2c_driver_install has been inserted i2c_hw_fsm_reset to reset state machine
i2c_driver_install(i2c_master_port, conf.mode,
I2C_EXAMPLE_MASTER_RX_BUF_DISABLE,
I2C_EXAMPLE_MASTER_TX_BUF_DISABLE, 0);
}
static esp_err_t PORT_readBack(i2c_port_t i2c_num, uint8_t* data_h, uint8_t* data_l)
{
int ret;
//Read back sensor
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, TCA9535_ADDR << 1 | WRITE_BIT, ACK_CHECK_EN);
i2c_master_write_byte(cmd, TCA9535_CMD_READ_PORTS, ACK_CHECK_EN);
i2c_master_start(cmd);
i2c_master_write_byte(cmd, TCA9535_ADDR << 1 | READ_BIT, ACK_CHECK_EN);
i2c_master_read_byte(cmd, data_h, ACK_VAL);
i2c_master_read_byte(cmd, data_l, NACK_VAL);
i2c_master_stop(cmd);
ret = i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
return ret;
}
static esp_err_t PORT_write(i2c_port_t i2c_num, uint8_t port0, uint8_t port1)
{
int ret;
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, TCA9535_ADDR << 1 | WRITE_BIT, ACK_CHECK_EN);
i2c_master_write_byte(cmd, TCA9535_CMD_WRITE_PORTS, ACK_CHECK_EN);
i2c_master_write_byte(cmd, port0, ACK_CHECK_EN); //high byte (output)
i2c_master_write_byte(cmd, port1, ACK_CHECK_EN); //low byte (output)
i2c_master_stop(cmd);
ret = i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
return ret;
}
In another task I call this function every 250ms the PORT_readBack function and every 500ms the PORT_write function.
I have also modified "i2c_driver_install" function inserting the "i2c_hw_fsm_reset" to reset the state machine.
This night I had another crash due to I2C..check below:
Code: Select all
xtensa-esp32-elf-gdb ./build/AviorWiFiESP32.elf -b 115200 -ex 'target remote COM6'
GNU gdb (crosstool-NG crosstool-ng-1.22.0-80-g6c4433a5) 7.10
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-host_pc-mingw32 --target=xtensa-esp32-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./build/AviorWiFiESP32.elf...done.
Remote debugging using COM6
0x4000c2da in ?? ()
(gdb) bt
#0 0x4000c2da in ?? ()
#1 0x4008b319 in prvCopyDataToQueue (pxQueue=0x3ffd4f24,
pvItemToQueue=0x3ffb05b4, xPosition=2)
at C:/msys32/home/Davide/esp/esp-idf/components/freertos/queue.c:1900
#2 0x4008b7d4 in xQueueGenericSendFromISR (xQueue=0x3ffd4f24,
pvItemToQueue=0x3ffb05b4, pxHigherPriorityTaskWoken=0x3ffb05b0,
xCopyPosition=2)
at C:/msys32/home/Davide/esp/esp-idf/components/freertos/queue.c:1193
#3 0x400840e9 in i2c_master_cmd_begin_static (i2c_num=<optimized out>)
at C:/msys32/home/Davide/esp/esp-idf/components/driver/i2c.c:1048
#4 0x400844f0 in i2c_isr_handler_default (arg=0x3ffd4e60)
at C:/msys32/home/Davide/esp/esp-idf/components/driver/i2c.c:378
#5 0x4008261c in _xt_lowint1 ()
at C:/msys32/home/Davide/esp/esp-idf/components/freertos\xtensa_vectors.S:1105
(gdb)
I guess Espressif guys knows about this issue. I would like to understand if they are going to fix it soon or I have to think about
implementing by myself.
Thanks