UncleRus / esp-idf-lib

Component library for ESP32-xx and ESP8266
https://esp-idf-lib.readthedocs.io/en/latest/
1.37k stars 426 forks source link

esp8266 + ads111x doesn't work at all #502

Closed hellvesper closed 1 year ago

hellvesper commented 1 year ago

The issue

ads111x driver and ESP8266 with rtos-sdk (master v.3.4) doesn't work in my case. I'm using an example code. My hardware is wemos d1 mini (esp8266) + ads1115 connected to GPIO 4 and 5. I know that wiring is correct and all modules is working properly because it works with another driver:

I (3313) system_api: Base MAC address is not set, read default base MAC address from EFUSE
I (3329) main: Other event id:7
I (3335) main: Turn ON charging, voltage level is below 90%: 12.382940
I (3605) main: MQTT_EVENT_CONNECTED
I (4335) main: Turn ON charging, voltage level is below 90%: 12.382940
I (5335) main: Turn ON charging, voltage level is below 90%: 12.383628
I (6335) main: Turn ON charging, voltage level is below 90%: 12.381565
I (7335) main: Turn ON charging, voltage level is below 90%: 12.382940
I (8336) main: Turn ON charging, voltage level is below 90%: 12.382940

But with ads111x driver I got panic and bootloops, here the console output:

I (378) esp_image: segment 4: paddr=0x00038388 vaddr=0x40100080 size=0x04850 ( 18512) load
V (391) esp_image: image start 0x00010000 end of last section 0x0003cbd8
I (401) boot: Loaded app from partition at offset 0x10000
Task watchdog got triggered.

Guru Meditation Error: Core  0 panic'ed (unknown). Exception was unhandled.
Core 0 register dump:
PC      : 0x40100926  PS      : 0x00000030  A0      : 0x4021a352  A1      : 0x3ffec950  
0x40100926: vPortExitCritical at /Users/vesper/Develop/ESP8266_RTOS_SDK/components/freertos/port/esp8266/port.c:263

0x4021a352: i2c_master_cmd_begin at /Users/vesper/Develop/ESP8266_RTOS_SDK/components/esp8266/driver/i2c.c:619 (discriminator 2)

A2      : 0x00000020  A3      : 0x00000000  A4      : 0x00000000  A5      : 0x60000300  
A6      : 0x3ffe8a91  A7      : 0x00000003  A8      : 0x3ffec970  A9      : 0x00000004  
A10     : 0x00000000  A11     : 0x00337f6d  A12     : 0x3ffecb68  A13     : 0x00000000  
A14     : 0x00000000  A15     : 0x3ffe8a68  SAR     : 0x0000001b  EXCCAUSE: 0x3ffec9e0  

Backtrace: 0x40100926:0x3ffec950 0x4021a352:0x3ffec960 0x402149b7:0x3ffec980 0x40214b6a:0x3ffec9c0 0x40214bac:0x3ffec9e0 0x40214c0b:0x3ffeca00 0x40214dad:0x3ffeca40 0x40214525:0x3ffeca60 0x40214648:0x3ffeca80 
0x40100926: vPortExitCritical at /Users/vesper/Develop/ESP8266_RTOS_SDK/components/freertos/port/esp8266/port.c:263

0x4021a352: i2c_master_cmd_begin at /Users/vesper/Develop/ESP8266_RTOS_SDK/components/esp8266/driver/i2c.c:619 (discriminator 2)

0x402149b7: i2c_dev_read at /Users/vesper/Develop/esp8266-rtos-acid-battery-bms/components/i2cdev/i2cdev.c:293

0x40214b6a: i2c_dev_read_reg at /Users/vesper/Develop/esp8266-rtos-acid-battery-bms/components/i2cdev/i2cdev.c:333

0x40214bac: read_reg at /Users/vesper/Develop/esp8266-rtos-acid-battery-bms/components/ads111x/ads111x.c:92

0x40214c0b: read_conf_bits at /Users/vesper/Develop/esp8266-rtos-acid-battery-bms/components/ads111x/ads111x.c:123 (discriminator 2)

0x40214dad: ads111x_is_busy at /Users/vesper/Develop/esp8266-rtos-acid-battery-bms/components/ads111x/ads111x.c:193 (discriminator 2)

0x40214525: measure at /Users/vesper/Develop/esp8266-rtos-acid-battery-bms/main/main.c:35 (discriminator 1)

0x40214648: ads111x_test at /Users/vesper/Develop/esp8266-rtos-acid-battery-bms/main/main.c:66 (discriminator 3)

When I set log level to DEBUG, I got this:

I (139) esp_image: segment 1: paddr=0x00031afc vaddr=0x40231af4 size=0x06810 ( 26640) map
I (153) esp_image: segment 2: paddr=0x00038314 vaddr=0x3ffe8000 size=0x003e4 (   996) load
I (166) esp_image: segment 3: paddr=0x00038700 vaddr=0x40100000 size=0x00080 (   128) load
I (180) esp_image: segment 4: paddr=0x00038788 vaddr=0x40100080 size=0x04850 ( 18512) load
I (194) boot: Loaded app from partition at offset 0x10000
D (208) phy_init: loading PHY init data from application binary
D (225) nvs: nvs_open_from_partition backup_mac 0
D (228) nvs: nvs_get_str_or_blob backup_mac_data
D (231) nvs: nvs_close 1
D (233) system_api: Load MAC from NVS error=0
D (235) reset_reason: RTC reset 2 wakeup 0 store 0, reason is 2
D (242) wdt: Enable task watch dog panic, panic time parameter is 11
D (252) wdt: task watch dog trigger time parameter is 15
D (259) i2cdev: Reconfiguring I2C driver on port 0
D (266) i2cdev: I2C driver successfully reconfigured on port 0
D (275) i2cdev: Reconfiguring I2C driver on port 0
D (281) i2cdev: I2C driver successfully reconfigured on port 0
D (290) i2cdev: Reconfiguring I2C driver on port 0
D (297) i2cdev: I2C driver successfully reconfigured on port 0
D (305) i2cdev: Reconfiguring I2C driver on port 0
D (312) i2cdev: I2C driver successfully reconfigured on port 0
D (321) i2cdev: Reconfiguring I2C driver on port 0
D (328) i2cdev: I2C driver successfully reconfigured on port 0
D (336) i2cdev: Reconfiguring I2C driver on port 0
D (343) i2cdev: I2C driver successfully reconfigured on port 0
D (352) i2cdev: Reconfiguring I2C driver on port 0
D (359) i2cdev: I2C driver successfully reconfigured on port 0
D (367) i2cdev: Reconfiguring I2C driver on port 0
D (374) i2cdev: I2C driver successfully reconfigured on port 0
D (383) i2cdev: Reconfiguring I2C driver on port 0
D (389) i2cdev: I2C driver successfully reconfigured on port 0
D (398) ads111x: Got config value: 0x0443
D (403) i2cdev: Reconfiguring I2C driver on port 0
D (411) i2cdev: I2C driver successfully reconfigured on port 0
D (419) ads111x: Got config value: 0x0443
D (425) i2cdev: Reconfiguring I2C driver on port 0
D (432) i2cdev: I2C driver successfully reconfigured on port 0
D (441) ads111x: Got config value: 0x0443
D (446) i2cdev: Reconfiguring I2C driver on port 0
D (453) i2cdev: I2C driver successfully reconfigured on port 0
D (462) ads111x: Got config value: 0x0443
D (467) i2cdev: Reconfiguring I2C driver on port 0
D (474) i2cdev: I2C driver successfully reconfigured on port 0
D (483) ads111x: Got config value: 0x0443
D (488) i2cdev: Reconfiguring I2C driver on port 0
D (495) i2cdev: I2C driver successfully reconfigured on port 0
D (504) ads111x: Got config value: 0x0443
....
D (2864) i2cdev: I2C driver successfully reconfigured on port 0
V (2873) i2cdev: [0x48 at 0] giving mutex
D (2878) ads111x: Got config value: 0x4443
V (2884) i2cdev: [0x48 at 0] taking mutex
D (2890) i2cdev: Reconfiguring I2C driver on port 0
D (2897) i2cdev: I2C driver successfully reconfigured on port 0
V (2906) i2cdev: [0x48 at 0] giving mutex
D (2911) ads111x: Got config value: 0x4443
V (2917) i2cdev: [0x48 at 0] taking mutex
D (2923) i2cdev: Reconfiguring I2C driver on port 0
D (2930) i2cdev: I2C driver successfully reconfigured on port 0
V (2939) i2cdev: [0x48 at 0] giving mutex
D (2945) ads111x: Got config value: 0x4443
V (2950) i2cdev: [0x48 at 0] taking mutex
D (2956) i2cdev: Reconfiguring I2C driver on port 0
D (2964) i2cdev: I2C driver successfully reconfigured on port 0
V (2973) i2cdev: [0x48 at 0] giving mutex
D (2978) ads111x: Got config value: 0x4443
V (2984) i2cdev: [0x48 at 0] taking mutex
D (2989) i2cdev: Reconfiguring I2C driver on port 0
D (2997) i2cdev: I2C driver successfully reconfigured on port 0
V (3006) i2cdev: [0x48 at 0] giving mutex
D (3011) ads111x: Got config value: 0x4443
V (3017) i2cdev: [0x48 at 0] taking mutex
D (3022) i2cdev: Reconfiguring I2C driver on port 0
D (3030) i2cdev: I2C driver successfully reconfigured on port 0
V (3039) i2cdev: [0x48 at 0] giving mutex
D (3044) ads111x: Got config value: 0x4443
V (3050) i2cdev: [0x48 at 0] taking mutex
D (3055) i2cdev: Reconfiguring I2C driver on port 0

Looks like an isssue with I2C bus

Which SDK are you using?

ESP8266 RTOS SDK

Which version of SDK are you using?

master (3.4)

Which build target have you used?

Component causing the issue

ads111x

Anything in the logs that might be useful for us?

No response

Additional information or context

No response

Confirmation

jmpmscorp commented 1 year ago

Hi.

Maybe, this issue it's not related with ads111x driver or esp8266 but with default example. I found same error working with esp32. Default example has a little "bug" in measure function.

static void measure(size_t n)
{
    // wait for conversion end
    bool busy;
    do
    {
         ads111x_is_busy(&devices[n], &busy);
    }
    while (busy);

    // Read result
    int16_t raw = 0;
    if (ads111x_get_value(&devices[n], &raw) == ESP_OK)
    {
        float voltage = gain_val / ADS111X_MAX_VALUE * raw;
        printf("[%u] Raw ADC value: %d, voltage: %.04f volts\n", n, raw, voltage);
    }
    else
        printf("[%u] Cannot read ADC value\n", n);
}

Problem raises in this lines:

   bool busy;
    do
    {
         ads111x_is_busy(&devices[n], &busy);
    }
    while (busy);

Every time you want to read an input ADC value, code waits for OS bit in CONFIG register to be setted however that never occurs.

If you see example code, the devices are configured to run in continuos mode. In this mode, OS bit is never used internally by device (it is not setted/cleared every conversion cycle) so example enters in a non finish loop. To solve it, remove or comment this do while loop.

When working in continuos mode, the only way to know when a conversion is completed is to use RDY/ALERT pin.