Commit 1d88e1f1 authored by aohui.li's avatar aohui.li

修复iic总线无法连接问题

parent d022f330
...@@ -91,17 +91,29 @@ void lis2dw12_init() ...@@ -91,17 +91,29 @@ void lis2dw12_init()
{ {
static uint8_t whoamI, rst; static uint8_t whoamI, rst;
uint8_t tx_buffer[1000]; uint8_t tx_buffer[1000];
esp_err_t ret;
ESP_LOGI(TAG, "LIS2DW12 Init"); ESP_LOGI(TAG, "LIS2DW12 Init");
gpio_set_direction(I2C_MASTER_SCL_IO, GPIO_MODE_INPUT_OUTPUT_OD); gpio_set_direction(I2C_MASTER_SCL_IO, GPIO_MODE_INPUT_OUTPUT_OD);
gpio_set_direction(I2C_MASTER_SDA_IO, GPIO_MODE_INPUT_OUTPUT_OD); gpio_set_direction(I2C_MASTER_SDA_IO, GPIO_MODE_INPUT_OUTPUT_OD);
gpio_set_pull_mode(I2C_MASTER_SCL_IO, GPIO_PULLUP_ONLY); gpio_set_pull_mode(I2C_MASTER_SCL_IO, GPIO_PULLUP_ONLY);
gpio_set_pull_mode(I2C_MASTER_SDA_IO, GPIO_PULLUP_ONLY); gpio_set_pull_mode(I2C_MASTER_SDA_IO, GPIO_PULLUP_ONLY);
vTaskDelay(pdMS_TO_TICKS(50)); vTaskDelay(pdMS_TO_TICKS(100));
i2c_master_init(&s_bus_handle, &s_dev_handle); i2c_master_init(&s_bus_handle, &s_dev_handle);
ESP_LOGI(TAG, "LIS2DW12 Init 2"); ESP_LOGI(TAG, "LIS2DW12 Init 2");
vTaskDelay(pdMS_TO_TICKS(50)); vTaskDelay(pdMS_TO_TICKS(50));
while(1)
{
ret = i2c_master_probe(s_bus_handle, SLAVE_ADDR, 1000);
if(ret == ESP_OK){
ESP_LOGI(TAG, "IIC OK");
break;
}
vTaskDelay(pdMS_TO_TICKS(10));
}
dev_ctx.handle = &s_dev_handle; dev_ctx.handle = &s_dev_handle;
dev_ctx.read_reg = lis2dw12_register_read; dev_ctx.read_reg = lis2dw12_register_read;
dev_ctx.write_reg = lis2dw12_register_write_byte; dev_ctx.write_reg = lis2dw12_register_write_byte;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment