43#define CHIP_NAME "Texas Instruments ADS1115"
44#define MANUFACTURER_NAME "Texas Instruments"
45#define SUPPLY_VOLTAGE_MIN 2.0f
46#define SUPPLY_VOLTAGE_MAX 5.5f
47#define MAX_CURRENT 0.2f
48#define TEMPERATURE_MIN -40.0f
49#define TEMPERATURE_MAX 125.0f
50#define DRIVER_VERSION 2000
55#define ADS1115_REG_CONVERT 0x00
56#define ADS1115_REG_CONFIG 0x01
57#define ADS1115_REG_LOWRESH 0x02
58#define ADS1115_REG_HIGHRESH 0x03
63#define ADS1115_ADDRESS1 (0x48 << 1)
64#define ADS1115_ADDRESS2 (0x49 << 1)
65#define ADS1115_ADDRESS3 (0x4A << 1)
66#define ADS1115_ADDRESS4 (0x4B << 1)
78static uint8_t a_ads1115_iic_multiple_read(
ads1115_handle_t *handle, uint8_t reg, int16_t *data)
82 memset(buf, 0,
sizeof(uint8_t) * 2);
85 *data = (uint16_t)(((uint16_t)buf[0] << 8) | buf[1]);
105static uint8_t a_ads1115_iic_multiple_write(
ads1115_handle_t *handle, uint8_t reg, uint16_t data)
109 buf[0] = (data >> 8) & 0xFF;
110 buf[1] = data & 0xFF;
143 handle->
debug_print(
"ads1115: iic_init is null.\n");
149 handle->
debug_print(
"ads1115: iic_deinit is null.\n");
155 handle->
debug_print(
"ads1115: iic_read is null.\n");
161 handle->
debug_print(
"ads1115: iic_write is null.\n");
167 handle->
debug_print(
"ads1115: delay_ms is null.\n");
174 handle->
debug_print(
"ads1115: iic init failed.\n");
211 handle->
debug_print(
"ads1115: read config failed.\n");
215 conf &= ~(0x01 << 8);
220 handle->
debug_print(
"ads1115: write config failed.\n");
227 handle->
debug_print(
"ads1115: iic deinit failed.\n");
264 handle->
debug_print(
"ads1115: read config failed.\n");
268 conf &= ~(0x07 << 12);
269 conf |= (channel & 0x07) << 12;
273 handle->
debug_print(
"ads1115: write config failed.\n");
309 handle->
debug_print(
"ads1115: read config failed.\n");
346 handle->
debug_print(
"ads1115: read config failed.\n");
350 conf &= ~(0x07 << 9);
351 conf |= (range & 0x07) << 9;
355 handle->
debug_print(
"ads1115: write config failed.\n");
391 handle->
debug_print(
"ads1115: read config failed.\n");
428 handle->
debug_print(
"ads1115: read config failed.\n");
433 conf |= (pin & 0x01) << 3;
437 handle->
debug_print(
"ads1115: write config failed.\n");
473 handle->
debug_print(
"ads1115: read config failed.\n");
510 handle->
debug_print(
"ads1115: read config failed.\n");
515 conf |= (compare & 0x01) << 4;
519 handle->
debug_print(
"ads1115: write config failed.\n");
555 handle->
debug_print(
"ads1115: read config failed.\n");
592 handle->
debug_print(
"ads1115: read config failed.\n");
596 conf &= ~(0x07 << 5);
597 conf |= (rate & 0x07) << 5;
601 handle->
debug_print(
"ads1115: write config failed.\n");
637 handle->
debug_print(
"ads1115: read config failed.\n");
674 handle->
debug_print(
"ads1115: read config failed.\n");
678 conf &= ~(0x03 << 0);
679 conf |= (comparator_queue & 0x03) << 0;
683 handle->
debug_print(
"ads1115: write config failed.\n");
719 handle->
debug_print(
"ads1115: read config failed.\n");
763 handle->
debug_print(
"ads1115: addr_pin is invalid.\n");
806 handle->
debug_print(
"ads1115: addr_pin is invalid.\n");
831 uint32_t timeout = 500;
845 handle->
debug_print(
"ads1115: read config failed.\n");
856 handle->
debug_print(
"ads1115: write config failed.\n");
866 handle->
debug_print(
"ads1115: read config failed.\n");
870 if ((conf & (1 << 15)) == (1 << 15))
885 handle->
debug_print(
"ads1115: continues read failed.\n");
891 *v = (float)(*raw) * 6.144f / 32768.0f;
895 *v = (float)(*raw) * 4.096f / 32768.0f;
899 *v = (float)(*raw) * 2.048f / 32768.0f;
903 *v = (float)(*raw) * 1.024f / 32768.0f;
907 *v = (float)(*raw) * 0.512f / 32768.0f;
911 *v = (float)(*raw) * 0.256f / 32768.0f;
915 handle->
debug_print(
"ads1115: range is invalid.\n");
954 handle->
debug_print(
"ads1115: read config failed.\n");
962 handle->
debug_print(
"ads1115: continuous read failed.\n");
968 *v = (float)(*raw) * 6.144f / 32768.0f;
972 *v = (float)(*raw) * 4.096f / 32768.0f;
976 *v = (float)(*raw) * 2.048f / 32768.0f;
980 *v = (float)(*raw) * 1.024f / 32768.0f;
984 *v = (float)(*raw) * 0.512f / 32768.0f;
988 *v = (float)(*raw) * 0.256f / 32768.0f;
992 handle->
debug_print(
"ads1115: range is invalid.\n");
1027 handle->
debug_print(
"ads1115: read config failed.\n");
1031 conf &= ~(0x01 << 8);
1035 handle->
debug_print(
"ads1115: write config failed.\n");
1070 handle->
debug_print(
"ads1115: read config failed.\n");
1074 conf &= ~(0x01 << 8);
1079 handle->
debug_print(
"ads1115: write config failed.\n");
1115 handle->
debug_print(
"ads1115: read config failed.\n");
1119 conf &= ~(0x01 << 2);
1120 conf |= enable << 2;
1124 handle->
debug_print(
"ads1115: write config failed.\n");
1160 handle->
debug_print(
"ads1115: read config failed.\n");
1194 handle->
debug_print(
"ads1115: write high threshold failed.\n");
1200 handle->
debug_print(
"ads1115: write low threshold failed.\n");
1233 handle->
debug_print(
"ads1115: read high threshold failed.\n");
1239 handle->
debug_print(
"ads1115: read low threshold failed.\n");
1277 handle->
debug_print(
"ads1115: read config failed.\n");
1284 *reg = (int16_t)(s * 32768.0f / 6.144f);
1288 *reg = (int16_t)(s * 32768.0f / 4.096f);
1292 *reg = (int16_t)(s * 32768.0f / 2.048f);
1296 *reg = (int16_t)(s * 32768.0f / 1.024f);
1300 *reg = (int16_t)(s * 32768.0f / 0.512f);
1304 *reg = (int16_t)(s * 32768.0f / 0.256f);
1308 handle->
debug_print(
"ads1115: range is invalid.\n");
1346 handle->
debug_print(
"ads1115: read config failed.\n");
1353 *s = (float)(reg) * 6.144f / 32768.0f;
1357 *s = (float)(reg) * 4.096f / 32768.0f;
1361 *s = (float)(reg) * 2.048f / 32768.0f;
1365 *s = (float)(reg) * 1.024f / 32768.0f;
1369 *s = (float)(reg) * 0.512f / 32768.0f;
1373 *s = (float)(reg) * 0.256f / 32768.0f;
1377 handle->
debug_print(
"ads1115: range is invalid.\n");
1408 return a_ads1115_iic_multiple_write(handle, reg, value);
1434 return a_ads1115_iic_multiple_read(handle, reg, value);
#define ADS1115_REG_LOWRESH
#define ADS1115_ADDRESS1
iic address definition
#define SUPPLY_VOLTAGE_MAX
#define MANUFACTURER_NAME
#define ADS1115_REG_CONFIG
#define ADS1115_REG_HIGHRESH
#define SUPPLY_VOLTAGE_MIN
#define ADS1115_REG_CONVERT
chip register definition
#define CHIP_NAME
chip information definition
driver ads1115 header file
uint8_t ads1115_get_channel(ads1115_handle_t *handle, ads1115_channel_t *channel)
get the adc channel
uint8_t ads1115_set_addr_pin(ads1115_handle_t *handle, ads1115_address_t addr_pin)
set the iic address pin
uint8_t ads1115_get_addr_pin(ads1115_handle_t *handle, ads1115_address_t *addr_pin)
get the iic address pin
uint8_t ads1115_start_continuous_read(ads1115_handle_t *handle)
start the chip reading
ads1115_channel_t
ads1115 channel enumeration definition
uint8_t ads1115_init(ads1115_handle_t *handle)
initialize the chip
uint8_t ads1115_set_rate(ads1115_handle_t *handle, ads1115_rate_t rate)
set the sample rate
ads1115_address_t
ads1115 address enumeration definition
uint8_t ads1115_get_rate(ads1115_handle_t *handle, ads1115_rate_t *rate)
get the sample rate
uint8_t ads1115_deinit(ads1115_handle_t *handle)
close the chip
uint8_t ads1115_set_range(ads1115_handle_t *handle, ads1115_range_t range)
set the adc range
struct ads1115_info_s ads1115_info_t
ads1115 information structure definition
ads1115_rate_t
ads1115 channel rate enumeration definition
uint8_t ads1115_get_range(ads1115_handle_t *handle, ads1115_range_t *range)
get the adc range
uint8_t ads1115_single_read(ads1115_handle_t *handle, int16_t *raw, float *v)
read data from the chip once
ads1115_bool_t
ads1115 bool enumeration definition
struct ads1115_handle_s ads1115_handle_t
ads1115 handle structure definition
uint8_t ads1115_info(ads1115_info_t *info)
get chip's information
uint8_t ads1115_stop_continuous_read(ads1115_handle_t *handle)
stop the chip reading
ads1115_range_t
ads1115 range enumeration definition
uint8_t ads1115_set_channel(ads1115_handle_t *handle, ads1115_channel_t channel)
set the adc channel
uint8_t ads1115_continuous_read(ads1115_handle_t *handle, int16_t *raw, float *v)
read data from the chip continuously
uint8_t ads1115_get_reg(ads1115_handle_t *handle, uint8_t reg, int16_t *value)
get the chip register
uint8_t ads1115_set_reg(ads1115_handle_t *handle, uint8_t reg, int16_t value)
set the chip register
uint8_t ads1115_set_alert_pin(ads1115_handle_t *handle, ads1115_pin_t pin)
set the alert pin active status
uint8_t ads1115_get_alert_pin(ads1115_handle_t *handle, ads1115_pin_t *pin)
get the alert pin active status
uint8_t ads1115_set_compare(ads1115_handle_t *handle, ads1115_bool_t enable)
enable or disable the interrupt compare
uint8_t ads1115_get_comparator_queue(ads1115_handle_t *handle, ads1115_comparator_queue_t *comparator_queue)
get the interrupt comparator queue
uint8_t ads1115_convert_to_register(ads1115_handle_t *handle, float s, int16_t *reg)
convert a adc value to a register raw data
uint8_t ads1115_set_compare_threshold(ads1115_handle_t *handle, int16_t high_threshold, int16_t low_threshold)
set the interrupt compare threshold
uint8_t ads1115_set_compare_mode(ads1115_handle_t *handle, ads1115_compare_t compare)
set the interrupt compare mode
ads1115_comparator_queue_t
ads1115 comparator queue enumeration definition
uint8_t ads1115_set_comparator_queue(ads1115_handle_t *handle, ads1115_comparator_queue_t comparator_queue)
set the interrupt comparator queue
ads1115_compare_t
ads1115 compare mode enumeration definition
uint8_t ads1115_get_compare_threshold(ads1115_handle_t *handle, int16_t *high_threshold, int16_t *low_threshold)
get the interrupt compare threshold
uint8_t ads1115_get_compare_mode(ads1115_handle_t *handle, ads1115_compare_t *compare)
get the interrupt compare mode
uint8_t ads1115_get_compare(ads1115_handle_t *handle, ads1115_bool_t *enable)
get the interrupt compare status
uint8_t ads1115_convert_to_data(ads1115_handle_t *handle, int16_t reg, float *s)
convert a register raw data to a converted adc data
ads1115_pin_t
ads1115 pin enumeration definition
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_write)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_read)(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v