ESP32 IO扩展测试

一、I2C先初始化,扩展芯片为tca9554

复制代码
#define BSP_I2C_SCL_R8          (GPIO_NUM_48)
#define BSP_I2C_SDA_R8          (GPIO_NUM_47)

i2c_config_t i2c_conf = {
    .mode = I2C_MODE_MASTER,
    .sda_io_num = BSP_I2C_SDA_R8,
    .sda_pullup_en = GPIO_PULLUP_ENABLE,
    .scl_io_num = BSP_I2C_SCL_R8,
    .scl_pullup_en = GPIO_PULLUP_ENABLE,
    .master.clk_speed = CONFIG_BSP_I2C_CLK_SPEED_HZ
};
二、IO测试
复制代码
BSP_NULL_CHECK(expander = bsp_io_expander_init(), ESP_FAIL);
BSP_ERROR_CHECK_RETURN_ERR(esp_io_expander_set_dir(expander, IO_EXPANDER_PIN_NUM_0|IO_EXPANDER_PIN_NUM_1, IO_EXPANDER_OUTPUT));
BSP_ERROR_CHECK_RETURN_ERR(esp_io_expander_set_dir(expander, IO_EXPANDER_PIN_NUM_4|IO_EXPANDER_PIN_NUM_5, IO_EXPANDER_OUTPUT));
vTaskDelay(pdMS_TO_TICKS(1000));
while (1)
{

        ESP_LOGE(TAG, "low");
        esp_io_expander_set_level(expander, IO_EXPANDER_PIN_NUM_0|IO_EXPANDER_PIN_NUM_1|IO_EXPANDER_PIN_NUM_4|IO_EXPANDER_PIN_NUM_5, 0);
        esp_io_expander_print_state(expander);
        vTaskDelay(pdMS_TO_TICKS(5000));
        esp_io_expander_set_level(expander, IO_EXPANDER_PIN_NUM_0|IO_EXPANDER_PIN_NUM_1|IO_EXPANDER_PIN_NUM_4|IO_EXPANDER_PIN_NUM_5, 1);
        ESP_LOGE(TAG, "hight");
        esp_io_expander_print_state(expander);
        vTaskDelay(pdMS_TO_TICKS(5000));

}
三、注意事项

一定要用IO_EXPANDER_PIN_NUM_0这个进行IO配置,千万不要用GPIO_NUM_0差别很大

IO_EXPANDER_PIN定义

复制代码
/**
 * @brief IO Expander Pin Num
 *
 */
typedef enum {
    IO_EXPANDER_PIN_NUM_0  = (1ULL << 0),
    IO_EXPANDER_PIN_NUM_1  = (1ULL << 1),
    IO_EXPANDER_PIN_NUM_2  = (1ULL << 2),
    IO_EXPANDER_PIN_NUM_3  = (1ULL << 3),
    IO_EXPANDER_PIN_NUM_4  = (1ULL << 4),
    IO_EXPANDER_PIN_NUM_5  = (1ULL << 5),
    IO_EXPANDER_PIN_NUM_6  = (1ULL << 6),
    IO_EXPANDER_PIN_NUM_7  = (1ULL << 7),
    IO_EXPANDER_PIN_NUM_8  = (1ULL << 8),
    IO_EXPANDER_PIN_NUM_9  = (1ULL << 9),
    IO_EXPANDER_PIN_NUM_10 = (1ULL << 10),
    IO_EXPANDER_PIN_NUM_11 = (1ULL << 11),
    IO_EXPANDER_PIN_NUM_12 = (1ULL << 12),
    IO_EXPANDER_PIN_NUM_13 = (1ULL << 13),
    IO_EXPANDER_PIN_NUM_14 = (1ULL << 14),
    IO_EXPANDER_PIN_NUM_15 = (1ULL << 15),
    IO_EXPANDER_PIN_NUM_16 = (1ULL << 16),
    IO_EXPANDER_PIN_NUM_17 = (1ULL << 17),
    IO_EXPANDER_PIN_NUM_18 = (1ULL << 18),
    IO_EXPANDER_PIN_NUM_19 = (1ULL << 19),
    IO_EXPANDER_PIN_NUM_20 = (1ULL << 20),
    IO_EXPANDER_PIN_NUM_21 = (1ULL << 21),
    IO_EXPANDER_PIN_NUM_22 = (1ULL << 22),
    IO_EXPANDER_PIN_NUM_23 = (1ULL << 23),
    IO_EXPANDER_PIN_NUM_24 = (1ULL << 24),
    IO_EXPANDER_PIN_NUM_25 = (1ULL << 25),
    IO_EXPANDER_PIN_NUM_26 = (1ULL << 26),
    IO_EXPANDER_PIN_NUM_27 = (1ULL << 27),
    IO_EXPANDER_PIN_NUM_28 = (1ULL << 28),
    IO_EXPANDER_PIN_NUM_29 = (1ULL << 29),
    IO_EXPANDER_PIN_NUM_30 = (1ULL << 30),
    IO_EXPANDER_PIN_NUM_31 = (1ULL << 31),
} esp_io_expander_pin_num_t;

GPIO_NUM这个定义

复制代码
/**
 * @brief GPIO number
 */
typedef enum {
    GPIO_NUM_NC = -1,    /*!< Use to signal not connected to S/W */
    GPIO_NUM_0 = 0,     /*!< GPIO0, input and output */
    GPIO_NUM_1 = 1,     /*!< GPIO1, input and output */
    GPIO_NUM_2 = 2,     /*!< GPIO2, input and output */
    GPIO_NUM_3 = 3,     /*!< GPIO3, input and output */
    GPIO_NUM_4 = 4,     /*!< GPIO4, input and output */
    GPIO_NUM_5 = 5,     /*!< GPIO5, input and output */
    GPIO_NUM_6 = 6,     /*!< GPIO6, input and output */
    GPIO_NUM_7 = 7,     /*!< GPIO7, input and output */
    GPIO_NUM_8 = 8,     /*!< GPIO8, input and output */
    GPIO_NUM_9 = 9,     /*!< GPIO9, input and output */
    GPIO_NUM_10 = 10,   /*!< GPIO10, input and output */
    GPIO_NUM_11 = 11,   /*!< GPIO11, input and output */
    GPIO_NUM_12 = 12,   /*!< GPIO12, input and output */
    GPIO_NUM_13 = 13,   /*!< GPIO13, input and output */
    GPIO_NUM_14 = 14,   /*!< GPIO14, input and output */
    GPIO_NUM_15 = 15,   /*!< GPIO15, input and output */
    GPIO_NUM_16 = 16,   /*!< GPIO16, input and output */
    GPIO_NUM_17 = 17,   /*!< GPIO17, input and output */
    GPIO_NUM_18 = 18,   /*!< GPIO18, input and output */
    GPIO_NUM_19 = 19,   /*!< GPIO19, input and output */
    GPIO_NUM_20 = 20,   /*!< GPIO20, input and output */
    GPIO_NUM_21 = 21,   /*!< GPIO21, input and output */
    GPIO_NUM_26 = 26,   /*!< GPIO26, input and output */
    GPIO_NUM_27 = 27,   /*!< GPIO27, input and output */
    GPIO_NUM_28 = 28,   /*!< GPIO28, input and output */
    GPIO_NUM_29 = 29,   /*!< GPIO29, input and output */
    GPIO_NUM_30 = 30,   /*!< GPIO30, input and output */
    GPIO_NUM_31 = 31,   /*!< GPIO31, input and output */
    GPIO_NUM_32 = 32,   /*!< GPIO32, input and output */
    GPIO_NUM_33 = 33,   /*!< GPIO33, input and output */
    GPIO_NUM_34 = 34,   /*!< GPIO34, input and output */
    GPIO_NUM_35 = 35,   /*!< GPIO35, input and output */
    GPIO_NUM_36 = 36,   /*!< GPIO36, input and output */
    GPIO_NUM_37 = 37,   /*!< GPIO37, input and output */
    GPIO_NUM_38 = 38,   /*!< GPIO38, input and output */
    GPIO_NUM_39 = 39,   /*!< GPIO39, input and output */
    GPIO_NUM_40 = 40,   /*!< GPIO40, input and output */
    GPIO_NUM_41 = 41,   /*!< GPIO41, input and output */
    GPIO_NUM_42 = 42,   /*!< GPIO42, input and output */
    GPIO_NUM_43 = 43,   /*!< GPIO43, input and output */
    GPIO_NUM_44 = 44,   /*!< GPIO44, input and output */
    GPIO_NUM_45 = 45,   /*!< GPIO45, input and output */
    GPIO_NUM_46 = 46,   /*!< GPIO46, input and output */
    GPIO_NUM_47 = 47,   /*!< GPIO47, input and output */
    GPIO_NUM_48 = 48,   /*!< GPIO48, input and output */
    GPIO_NUM_MAX,
} gpio_num_t;
相关推荐
无人装备硬件开发爱好者7 天前
硬核技术解析|MCP 协议实现语音 AI 与 ESP32 软 / 硬件的标准化对接:从火山引擎豆包认证到全链路落地——中
人工智能·esp32·火山引擎·mcp
无人装备硬件开发爱好者7 天前
硬核技术解析|MCP 协议实现语音 AI 与 ESP32 软 / 硬件的标准化对接:从火山引擎豆包认证到全链路落地——上
人工智能·esp32·火山引擎·mcp
嵌入式×边缘AI:打怪升级日志8 天前
基于ESP32S3的智能终端项目--5.显示时间和天气功能
笔记·esp32·freertos·天气·日历
飞睿科技9 天前
乐鑫ESP32-S3-Korvo-2开发板:面向多媒体应用的AIoT解决方案
物联网·esp32·乐鑫科技·产品开发
小刘同学-很乖9 天前
ESP32从入门到精通(全)
mcu·物联网·esp32·c·iot
小灰灰搞电子9 天前
ESP32 使用ESP-IDF实现Modbus TCP主机通信源码分享
网络·modbustcp·网络协议·tcp/ip·esp32
小灰灰搞电子10 天前
ESP32 使用ESP-IDF实现Modbus TCP从机通信源码分享
modbustcp·tcp/ip·esp32
小灰灰搞电子10 天前
ESP32 使用ESP-IDF驱动DS1302时钟芯片源码分享
esp32·ds1302
戏舟的嵌入式开源笔记11 天前
ESP32电子相册
esp32·嵌入式软件
tokepson12 天前
关于 MicroPython + ESP32-S3 的使用流程
嵌入式·esp32·micropython·技术