Skip to content

Commit

Permalink
Merge pull request #678 from k-korn/master
Browse files Browse the repository at this point in the history
Add ADS1015 support to ads111x lib.
  • Loading branch information
UncleRus authored Aug 24, 2018
2 parents 47cc177 + b5b0528 commit f82a420
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions extras/ads111x/ads111x.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ int16_t ads111x_get_value(i2c_dev_t *dev)
return read_reg(dev, REG_CONVERSION);
}

int16_t ads101x_get_value(i2c_dev_t *dev)
{
uint16_t res = read_reg(dev, REG_CONVERSION) >> 4;
if (res > 0x07FF)
{
// negative number - extend the sign to 16th bit
res |= 0xF000;
}
return (int16_t)res;
}


ads111x_gain_t ads111x_get_gain(i2c_dev_t *dev)
{
return read_conf_bits(dev, PGA_OFFSET, PGA_MASK);
Expand Down
17 changes: 17 additions & 0 deletions extras/ads111x/ads111x.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ extern "C" {
#define ADS111X_ADDR_SCL 0x4b

#define ADS111X_MAX_VALUE 0x7fff
#define ADS101X_MAX_VALUE 0x7ff

// ADS101X overrides
#define ADS101X_DATA_RATE_128 ADS111X_DATA_RATE_8
#define ADS101X_DATA_RATE_250 ADS111X_DATA_RATE_16
#define ADS101X_DATA_RATE_490 ADS111X_DATA_RATE_32
#define ADS101X_DATA_RATE_920 ADS111X_DATA_RATE_64
#define ADS101X_DATA_RATE_1600 ADS111X_DATA_RATE_128
#define ADS101X_DATA_RATE_2400 ADS111X_DATA_RATE_250
#define ADS101X_DATA_RATE_3300 ADS111X_DATA_RATE_475

/**
* Gain amplifier
Expand Down Expand Up @@ -140,6 +150,13 @@ void ads111x_start_conversion(i2c_dev_t *dev);
*/
int16_t ads111x_get_value(i2c_dev_t *dev);

/**
* Read last conversion result for 101x
* @param addr
* @return Last conversion result
*/
int16_t ads101x_get_value(i2c_dev_t *dev);

/**
* Read the programmable gain amplifier configuration
* (ADS1114 and ADS1115 only).
Expand Down

0 comments on commit f82a420

Please sign in to comment.