42#define CHIP_NAME "Texas Instruments ADS1118"
43#define MANUFACTURER_NAME "Texas Instruments"
44#define SUPPLY_VOLTAGE_MIN 2.0f
45#define SUPPLY_VOLTAGE_MAX 5.5f
46#define MAX_CURRENT 0.3f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 125.0f
49#define DRIVER_VERSION 1000
54#define COMMAND_VALID (1 << 1)
78 *data = (uint16_t)((uint16_t)(rx_buf[2]) << 8) | rx_buf[3];
92static uint8_t a_ads1118_spi_read_data(
ads1118_handle_t *handle, int16_t *data)
103 *data = (int16_t)((uint16_t)(rx_buf[0]) << 8) | rx_buf[1];
122 tx_buf[0] = (data >> 8) & 0xFF;
123 tx_buf[1] = (data >> 0) & 0xFF;
154 handle->
debug_print(
"ads1118: spi_init is null.\n");
160 handle->
debug_print(
"ads1118: spi_deinit is null.\n");
166 handle->
debug_print(
"ads1118: spi_transmit is null.\n");
172 handle->
debug_print(
"ads1118: delay_ms is null.\n");
179 handle->
debug_print(
"ads1118: spi init failed.\n");
213 res = a_ads1118_spi_read(handle, (uint16_t *)&conf);
216 handle->
debug_print(
"ads1118: read config failed.\n");
220 conf &= ~(0x01 << 8);
222 res = a_ads1118_spi_write(handle, conf);
225 handle->
debug_print(
"ads1118: write config failed.\n");
232 handle->
debug_print(
"ads1118: spi deinit failed.\n");
266 res = a_ads1118_spi_read(handle, (uint16_t *)&conf);
269 handle->
debug_print(
"ads1118: read config failed.\n");
273 conf &= ~(0x07 << 12);
274 conf |= (channel & 0x07) << 12;
277 res = a_ads1118_spi_write(handle, conf);
280 handle->
debug_print(
"ads1118: write config failed.\n");
313 res = a_ads1118_spi_read(handle, (uint16_t *)&conf);
316 handle->
debug_print(
"ads1118: read config failed.\n");
350 res = a_ads1118_spi_read(handle, (uint16_t *)&conf);
353 handle->
debug_print(
"ads1118: read config failed.\n");
357 conf &= ~(0x07 << 9);
358 conf |= (range & 0x07) << 9;
361 res = a_ads1118_spi_write(handle, conf);
364 handle->
debug_print(
"ads1118: write config failed.\n");
397 res = a_ads1118_spi_read(handle, (uint16_t *)&conf);
400 handle->
debug_print(
"ads1118: read config failed.\n");
434 res = a_ads1118_spi_read(handle, (uint16_t *)&conf);
437 handle->
debug_print(
"ads1118: read config failed.\n");
441 conf &= ~(0x07 << 5);
442 conf |= (rate & 0x07) << 5;
445 res = a_ads1118_spi_write(handle, conf);
448 handle->
debug_print(
"ads1118: write config failed.\n");
481 res = a_ads1118_spi_read(handle, (uint16_t *)&conf);
484 handle->
debug_print(
"ads1118: read config failed.\n");
518 res = a_ads1118_spi_read(handle, (uint16_t *)&conf);
521 handle->
debug_print(
"ads1118: read config failed.\n");
529 res = a_ads1118_spi_write(handle, conf);
532 handle->
debug_print(
"ads1118: write config failed.\n");
565 res = a_ads1118_spi_read(handle, (uint16_t *)&conf);
568 handle->
debug_print(
"ads1118: read config failed.\n");
602 res = a_ads1118_spi_read(handle, (uint16_t *)&conf);
605 handle->
debug_print(
"ads1118: read config failed.\n");
613 res = a_ads1118_spi_write(handle, conf);
616 handle->
debug_print(
"ads1118: write config failed.\n");
649 res = a_ads1118_spi_read(handle, (uint16_t *)&conf);
652 handle->
debug_print(
"ads1118: read config failed.\n");
689 res = a_ads1118_spi_read(handle, (uint16_t *)&conf);
692 handle->
debug_print(
"ads1118: read config failed.\n");
700 res = a_ads1118_spi_write(handle, conf);
703 handle->
debug_print(
"ads1118: write config failed.\n");
707 rate = (conf >> 5) & 0x7;
765 res = a_ads1118_spi_read_data(handle, raw);
768 handle->
debug_print(
"ads1118: continues read failed.\n");
774 *v = (float)(*raw) * 6.144f / 32768.0f;
778 *v = (float)(*raw) * 4.096f / 32768.0f;
782 *v = (float)(*raw) * 2.048f / 32768.0f;
786 *v = (float)(*raw) * 1.024f / 32768.0f;
790 *v = (float)(*raw) * 0.512f / 32768.0f;
794 *v = (float)(*raw) * 0.256f / 32768.0f;
798 handle->
debug_print(
"ads1118: range is invalid.\n");
834 res = a_ads1118_spi_read(handle, (uint16_t *)&conf);
837 handle->
debug_print(
"ads1118: read config failed.\n");
842 res = a_ads1118_spi_read_data(handle, raw);
845 handle->
debug_print(
"ads1118: continuous read failed.\n");
851 *v = (float)(*raw) * 6.144f / 32768.0f;
855 *v = (float)(*raw) * 4.096f / 32768.0f;
859 *v = (float)(*raw) * 2.048f / 32768.0f;
863 *v = (float)(*raw) * 1.024f / 32768.0f;
867 *v = (float)(*raw) * 0.512f / 32768.0f;
871 *v = (float)(*raw) * 0.256f / 32768.0f;
875 handle->
debug_print(
"ads1118: range is invalid.\n");
907 res = a_ads1118_spi_read(handle, (uint16_t *)&conf);
910 handle->
debug_print(
"ads1118: read config failed.\n");
914 conf &= ~(0x01 << 8);
915 res = a_ads1118_spi_write(handle, conf);
918 handle->
debug_print(
"ads1118: write config failed.\n");
950 res = a_ads1118_spi_read(handle, (uint16_t *)&conf);
953 handle->
debug_print(
"ads1118: read config failed.\n");
957 conf &= ~(0x01 << 8);
959 res = a_ads1118_spi_write(handle, conf);
962 handle->
debug_print(
"ads1118: write config failed.\n");
992 *deg = (float)(raw) * 0.03125f / 4.0f;
#define COMMAND_VALID
command definition
#define SUPPLY_VOLTAGE_MAX
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define CHIP_NAME
chip information definition
driver ads1118 header file
uint8_t ads1118_stop_continuous_read(ads1118_handle_t *handle)
stop the chip reading
uint8_t ads1118_single_read(ads1118_handle_t *handle, int16_t *raw, float *v)
read data from the chip once
uint8_t ads1118_get_channel(ads1118_handle_t *handle, ads1118_channel_t *channel)
get the adc channel
uint8_t ads1118_set_channel(ads1118_handle_t *handle, ads1118_channel_t channel)
set the adc channel
uint8_t ads1118_set_range(ads1118_handle_t *handle, ads1118_range_t range)
set the adc range
uint8_t ads1118_info(ads1118_info_t *info)
get chip's information
ads1118_mode_t
ads1118 mode enumeration definition
uint8_t ads1118_continuous_read(ads1118_handle_t *handle, int16_t *raw, float *v)
read data from the chip continuously
ads1118_bool_t
ads1118 bool enumeration definition
uint8_t ads1118_get_mode(ads1118_handle_t *handle, ads1118_mode_t *mode)
get the chip mode
struct ads1118_info_s ads1118_info_t
ads1118 information structure definition
ads1118_range_t
ads1118 range enumeration definition
uint8_t ads1118_init(ads1118_handle_t *handle)
initialize the chip
uint8_t ads1118_set_dout_pull_up(ads1118_handle_t *handle, ads1118_bool_t enable)
enable or disable dout pull up
uint8_t ads1118_deinit(ads1118_handle_t *handle)
close the chip
struct ads1118_handle_s ads1118_handle_t
ads1118 handle structure definition
uint8_t ads1118_set_rate(ads1118_handle_t *handle, ads1118_rate_t rate)
set the sample rate
uint8_t ads1118_get_rate(ads1118_handle_t *handle, ads1118_rate_t *rate)
get the sample rate
ads1118_channel_t
ads1118 channel enumeration definition
uint8_t ads1118_temperature_convert(ads1118_handle_t *handle, int16_t raw, float *deg)
temperature convert
ads1118_rate_t
ads1118 channel rate enumeration definition
uint8_t ads1118_start_continuous_read(ads1118_handle_t *handle)
start the chip reading
uint8_t ads1118_set_mode(ads1118_handle_t *handle, ads1118_mode_t mode)
set the chip mode
uint8_t ads1118_get_dout_pull_up(ads1118_handle_t *handle, ads1118_bool_t *enable)
get dout pull up status
uint8_t ads1118_get_range(ads1118_handle_t *handle, ads1118_range_t *range)
get the adc range
uint8_t ads1118_transmit(ads1118_handle_t *handle, uint8_t *tx, uint8_t *rx, uint16_t len)
chip transmit
uint8_t(* spi_init)(void)
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* spi_transmit)(uint8_t *tx, uint8_t *rx, uint16_t len)
uint8_t(* spi_deinit)(void)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v