Hello,
I am evaluating the 7" display with ESP32-S3 :
- project based on the demo of the TWAI (CAN) protocole: all good, I can get the data via Serial.print
- project based on tutorials to create a nice UI via Squareline: all good as well.
But when I merge both projects, I have an issue with the IO Expander. Here is the message I get on the Serial:
"Initialize IO expander
E (611) i2c: i2c driver install error
E (611) ESP_IOExpander: [ESP_IOExpander.cpp:47] init(): Check error -1 (ESP_FAIL)
Driver installed
Driver started"
Here is the beginning of the code:
// Libraries TWAI
#include "driver/twai.h"
#include <ESP_IOExpander_Library.h>
//Libraries display
#include <Arduino.h>
#include <Waveshare_ST7262_LVGL.h>
#include <lvgl.h>
#include "ui.h"
// Pins used to connect to CAN bus transceiver:
#define RX_PIN 19
#define TX_PIN 20
// Extend IO Pin define
#define TP_RST 1
#define LCD_BL 2
#define LCD_RST 3
#define SD_CS 4
#define USB_SEL 5
// I2C Pin define
#define I2C_MASTER_NUM I2C_NUM_0
#define I2C_MASTER_SDA_IO 8
#define I2C_MASTER_SCL_IO 9
// Intervall:
#define POLLING_RATE_MS 1000
static bool driver_installed = false;
int isOn = 1;
void setup() {
// Start Serial:
Serial.begin(115200);
lcd_init();
// Lock the mutex due to the LVGL APIs are not thread-safe
lvgl_port_lock(-1);
ui_init();
Serial.println("Initialize IO expander");
/* Initialize IO expander */
ESP_IOExpander *expander = new ESP_IOExpander_CH422G((i2c_port_t)I2C_MASTER_NUM, ESP_IO_EXPANDER_I2C_CH422G_ADDRESS_000, I2C_MASTER_SCL_IO, I2C_MASTER_SDA_IO);
// ESP_IOExpander *expander = new ESP_IOExpander_CH422G(I2C_MASTER_NUM, ESP_IO_EXPANDER_I2C_CH422G_ADDRESS_000);
expander->init();
expander->begin();
expander->multiPinMode(TP_RST | LCD_BL | LCD_RST | SD_CS | USB_SEL, OUTPUT);
expander->multiDigitalWrite(TP_RST | LCD_BL | LCD_RST | SD_CS, HIGH);
// When USB_SEL is HIGH, it enables FSUSB42UMX chip and gpio19,gpio20 wired CAN_TX CAN_RX, and then dont use USB Function
expander->digitalWrite(USB_SEL, HIGH);
// Initialize configuration structures using macro initializers
twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT((gpio_num_t)TX_PIN, (gpio_num_t)RX_PIN, TWAI_MODE_LISTEN_ONLY);
twai_timing_config_t t_config = TWAI_TIMING_CONFIG_1MBITS(); //Look in the api-reference for other speed sets.
//twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL();
twai_filter_config_t f_config = {
.acceptance_code = (0x125 << 21),
.acceptance_mask = (0x125 << 21),
.single_filter = true
};
// Install TWAI driver
if (twai_driver_install(&g_config, &t_config, &f_config) == ESP_OK) {
Serial.println("Driver installed");
} else {
Serial.println("Failed to install driver");
return;
}
// Start TWAI driver
if (twai_start() == ESP_OK) {
Serial.println("Driver started");
} else {
Serial.println("Failed to start driver");
return;
}
// Reconfigure alerts to detect frame receive, Bus-Off error and RX queue full states
uint32_t alerts_to_enable = TWAI_ALERT_RX_DATA | TWAI_ALERT_ERR_PASS | TWAI_ALERT_BUS_ERROR | TWAI_ALERT_RX_QUEUE_FULL;
if (twai_reconfigure_alerts(alerts_to_enable, NULL) == ESP_OK) {
Serial.println("CAN Alerts reconfigured");
} else {
Serial.println("Failed to reconfigure alerts");
return;
}
// TWAI driver is now successfully installed and started
driver_installed = true;
}
I imagine there is something (pin, i2c...) used by display and TWAI, generating conflict, but I can't find what is wrong.
