23const uint16_t OS_SINGLE = 0x8000;
24const uint16_t MUX_SINGLE0 = 0x4000;
25const uint16_t MODE_SINGLE = 0x0100;
26const uint16_t COMP_DISABLE = 0x0003;
29const uint16_t PGA_BITS[6] = {0x0000, 0x0200, 0x0400, 0x0600, 0x0800, 0x0A00};
30const int32_t FSR_UV[6] = {6144000, 4096000, 2048000, 1024000, 512000, 256000};
47 uint16_t cfg = OS_SINGLE;
48#if PC_ADS1115_DIFFERENTIAL
49 cfg |= (uint16_t)((uint16_t)channel << 12);
51 cfg |= (uint16_t)(MUX_SINGLE0 | ((uint16_t)channel << 12));
53 cfg |= PGA_BITS[gain];
55 cfg |= (uint16_t)((uint16_t)dr << 5);
66 return (int32_t)((int64_t)raw * FSR_UV[gain] / 32768);
85bool wr16(uint8_t reg, uint16_t v)
87 Wire.beginTransmission(s_ads.addr);
89 Wire.write((uint8_t)(v >> 8));
90 Wire.write((uint8_t)(v & 0xFF));
91 return Wire.endTransmission() == 0;
94bool rd16(uint8_t reg, uint16_t *v)
96 Wire.beginTransmission(s_ads.addr);
98 if (Wire.endTransmission(
false) != 0)
102 if (Wire.requestFrom((
int)s_ads.addr, 2) != 2)
106 uint8_t hi = (uint8_t)Wire.read();
107 uint8_t lo = (uint8_t)Wire.read();
108 *v = (uint16_t)(((uint16_t)hi << 8) | lo);
136 static const uint16_t pc_ads1115_sps[8] = {8, 16, 32, 64, 128, 250, 475, 860};
137 pcdelay(1000u / pc_ads1115_sps[dr] + 1);
TI ADS1115 16-bit ADC codec (PC_ENABLE_ADS1115).
bool pc_ads1115_begin(uint8_t addr)
Initialize the I2C bus for the ADS1115 at addr.
int32_t pc_ads1115_raw_to_uv(int16_t raw, uint8_t gain)
Convert a signed 16-bit sample to microvolts for gain's full-scale range.
bool pc_ads1115_read_raw(uint8_t channel, uint8_t gain, int16_t *raw)
Single-shot read of channel (0..3) at gain into raw.
#define ADS1115_REG_CONVERSION
conversion result register
uint16_t pc_ads1115_config_single(uint8_t channel, uint8_t gain, uint8_t dr)
Build the 16-bit config word for a single-shot, single-ended reading of channel (0....
#define ADS1115_REG_CONFIG
configuration register
bool pc_ads1115_read_uv(uint8_t channel, uint8_t gain, int32_t *microvolts)
Single-shot read of channel at gain, converted to microvolts in microvolts.
Pluggable monotonic clock for all library timing.
void pcdelay(uint32_t ms)
Block for at least ms milliseconds - the library's single delay primitive.
The one owner of the shared I2C bus bring-up for the peripheral drivers.
void pc_i2c_begin()
Bring up the shared I2C bus on PC_I2C_SDA_PIN / PC_I2C_SCL_PIN (-1 = default).
User-facing configuration for ProtoCore.
#define PC_ADS1115_I2C_ADDR
I2C address of the ADS1115 (0x48 with ADDR to GND; 0x49/0x4A/0x4B for VDD/SDA/SCL).
#define PC_ADS1115_DR
Default ADS1115 data-rate code (ADS1115_DR_*): 0=8, 1=16, 2=32, 3=64, 4=128 (default),...
#define PC_ADS1115_GAIN
Default ADS1115 PGA gain code (ADS1115_GAIN_*): 0=+/-6.144V, 1=+/-4.096V, 2=+/-2.048V (default),...
static constexpr uint8_t ADS1115_DR_128
128 SPS (default)
static constexpr uint8_t ADS1115_DR_860
860 SPS
static constexpr uint8_t ADS1115_GAIN_16
+/- 0.256 V