7 static const char *
const TAG =
"ads1118";
8 static const uint8_t ADS1118_DATA_RATE_860_SPS = 0b111;
11 ESP_LOGCONFIG(TAG,
"Setting up ads1118");
25 this->
config_ |= 0b0000000100000000;
29 this->
config_ |= ADS1118_DATA_RATE_860_SPS << 5;
33 this->
config_ |= 0b0000000000000000;
37 this->
config_ |= 0b0000000000001000;
41 this->
config_ |= 0b0000000000000010;
45 this->
config_ |= 0b0000000000000001;
49 ESP_LOGCONFIG(TAG,
"ADS1118:");
50 LOG_PIN(
" CS Pin:", this->
cs_);
54 uint16_t temp_config = this->
config_;
57 temp_config &= 0b1000111111111111;
58 temp_config |= (multiplexer & 0b111) << 12;
62 temp_config &= 0b1111000111111111;
63 temp_config |= (gain & 0b111) << 9;
65 if (temperature_mode) {
68 temp_config |= 0b0000000000010000;
72 temp_config &= 0b1111111111101111;
76 temp_config |= 0b1000000000000000;
86 uint8_t adc_first_byte = this->
read_byte();
87 uint8_t adc_second_byte = this->
read_byte();
89 uint16_t raw_conversion =
encode_uint16(adc_first_byte, adc_second_byte);
91 auto signed_conversion =
static_cast<int16_t
>(raw_conversion);
93 if (temperature_mode) {
94 return (signed_conversion >> 2) * 0.03125f;
97 float divider = 32768.0f;
100 millivolts = (signed_conversion * 6144) / divider;
103 millivolts = (signed_conversion * 4096) / divider;
106 millivolts = (signed_conversion * 2048) / divider;
109 millivolts = (signed_conversion * 1024) / divider;
112 millivolts = (signed_conversion * 512) / divider;
115 millivolts = (signed_conversion * 256) / divider;
121 return millivolts / 1e3f;
void spi_setup() override
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
float request_measurement(ADS1118Multiplexer multiplexer, ADS1118Gain gain, bool temperature_mode)
Helper method to request a measurement from a sensor.
void dump_config() override
Implementation of SPI Controller mode.
void write_byte16(uint16_t data)
Write 16 bit data.
void IRAM_ATTR HOT delay(uint32_t ms)