UncleRus / esp-idf-lib

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

Write to config register triggers start conversion on ADS1115 #593

Closed corecell closed 5 months ago

corecell commented 5 months ago

The issue

Example (POR settings, no one changed before): ads111x_set_comp_high_thresh(&ads1115, -32768); ads111x_set_comp_low_thresh(&ads1115, 32767); ads111x_set_comp_queue(&ads1115, ADS111X_COMP_QUEUE_1)

Triggers start conversion, and after about 7.8-7.9ms interrupt line ALLERT/RDY pulled down by ADS1115 as excepted for default rate.

DS1Z_QuickPrint25

This seems happens in read-modify-write operation in function write_conf_bits:133. 15 bit of ADS1115 config register shows device status when reading, but when writing 1<<15 bit into it's performs start of conversion.

write_conf_bits reads this 15 bit as 1 due to idle, no conversion, and writes it back to config register which triggers start of a conversion.

If we mask 15 bit state when writting to config register, I2C_DEV_CHECK(dev, write_reg(dev, REG_CONFIG, ((old & ~0x8000) & ~(mask << offs)) | (val << offs))); interrupt line will be changed immediately after comparator queue changed to ADS111X_COMP_QUEUE_1.

DS1Z_QuickPrint32

For continuous conversion this is seems not a problem, writting 15 bit when conversion currently performing have no effect.

DS1Z_QuickPrint28 DS1Z_QuickPrint29 DS1Z_QuickPrint30

Which SDK are you using?

esp-idf

Which version of SDK are you using?

master

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