ADS1015 library
ads1015.h@0:b3c2afab9578, 2017-01-26 (annotated)
- Committer:
- YJ_Kim
- Date:
- Thu Jan 26 17:00:38 2017 +0000
- Revision:
- 0:b3c2afab9578
- Child:
- 1:fa7b90993eb3
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
YJ_Kim | 0:b3c2afab9578 | 1 | #ifndef _ADS1015_H_ |
YJ_Kim | 0:b3c2afab9578 | 2 | #define _ADS1015_H_ |
YJ_Kim | 0:b3c2afab9578 | 3 | |
YJ_Kim | 0:b3c2afab9578 | 4 | #include "mbed.h" |
YJ_Kim | 0:b3c2afab9578 | 5 | |
YJ_Kim | 0:b3c2afab9578 | 6 | /*============================================================================= |
YJ_Kim | 0:b3c2afab9578 | 7 | |
YJ_Kim | 0:b3c2afab9578 | 8 | Conversion delay (in ms) |
YJ_Kim | 0:b3c2afab9578 | 9 | |
YJ_Kim | 0:b3c2afab9578 | 10 | =============================================================================*/ |
YJ_Kim | 0:b3c2afab9578 | 11 | #define ADS1015_CONVERSIONDELAY 1 |
YJ_Kim | 0:b3c2afab9578 | 12 | |
YJ_Kim | 0:b3c2afab9578 | 13 | /*============================================================================= |
YJ_Kim | 0:b3c2afab9578 | 14 | |
YJ_Kim | 0:b3c2afab9578 | 15 | Register Map |
YJ_Kim | 0:b3c2afab9578 | 16 | |
YJ_Kim | 0:b3c2afab9578 | 17 | =============================================================================*/ |
YJ_Kim | 0:b3c2afab9578 | 18 | #define ADS1015_REG_CONVERSION 0x00 |
YJ_Kim | 0:b3c2afab9578 | 19 | #define ADS1015_REG_CONFIG 0x01 |
YJ_Kim | 0:b3c2afab9578 | 20 | #define ADS1015_REG_LOWTHRESH 0x02 |
YJ_Kim | 0:b3c2afab9578 | 21 | #define ADS1015_REG_HITHRESH 0X03 |
YJ_Kim | 0:b3c2afab9578 | 22 | |
YJ_Kim | 0:b3c2afab9578 | 23 | /*============================================================================= |
YJ_Kim | 0:b3c2afab9578 | 24 | |
YJ_Kim | 0:b3c2afab9578 | 25 | Config Register Field Descriptions |
YJ_Kim | 0:b3c2afab9578 | 26 | |
YJ_Kim | 0:b3c2afab9578 | 27 | =============================================================================*/ |
YJ_Kim | 0:b3c2afab9578 | 28 | #define ADS1015_CONFIG_OS_START_CONV 0x8000 |
YJ_Kim | 0:b3c2afab9578 | 29 | |
YJ_Kim | 0:b3c2afab9578 | 30 | #define ADS1015_CONFIG_MUX_DIFF_0_1 0x0000 |
YJ_Kim | 0:b3c2afab9578 | 31 | #define ADS1015_CONFIG_MUX_DIFF_0_3 0x1000 |
YJ_Kim | 0:b3c2afab9578 | 32 | #define ADS1015_CONFIG_MUX_DIFF_1_3 0x2000 |
YJ_Kim | 0:b3c2afab9578 | 33 | #define ADS1015_CONFIG_MUX_DIFF_2_3 0x3000 |
YJ_Kim | 0:b3c2afab9578 | 34 | #define ADS1015_CONFIG_MUX_SINGLE_0 0X4000 |
YJ_Kim | 0:b3c2afab9578 | 35 | #define ADS1015_CONFIG_MUX_SINGLE_1 0x5000 |
YJ_Kim | 0:b3c2afab9578 | 36 | #define ADS1015_CONFIG_MUX_SINGLE_2 0x6000 |
YJ_Kim | 0:b3c2afab9578 | 37 | #define ADS1015_CONFIG_MUX_SINGLE_3 0x7000 |
YJ_Kim | 0:b3c2afab9578 | 38 | |
YJ_Kim | 0:b3c2afab9578 | 39 | #define ADS1015_CONFIG_MODE_CONT 0x0000 |
YJ_Kim | 0:b3c2afab9578 | 40 | #define ADS1015_CONFIG_MODE_SINGLE 0x0100 |
YJ_Kim | 0:b3c2afab9578 | 41 | |
YJ_Kim | 0:b3c2afab9578 | 42 | #define ADS1015_CONFIG_DR_128SPS 0x0000 |
YJ_Kim | 0:b3c2afab9578 | 43 | #define ADS1015_CONFIG_DR_250SPS 0x0020 |
YJ_Kim | 0:b3c2afab9578 | 44 | #define ADS1015_CONFIG_DR_490SPS 0x0040 |
YJ_Kim | 0:b3c2afab9578 | 45 | #define ADS1015_CONFIG_DR_920SPS 0x0060 |
YJ_Kim | 0:b3c2afab9578 | 46 | #define ADS1015_CONFIG_DR_1600SPS 0x0080 |
YJ_Kim | 0:b3c2afab9578 | 47 | #define ADS1015_CONFIG_DR_2400SPS 0x00A0 |
YJ_Kim | 0:b3c2afab9578 | 48 | #define ADS1015_CONFIG_DR_3300SPS 0x00C0 |
YJ_Kim | 0:b3c2afab9578 | 49 | |
YJ_Kim | 0:b3c2afab9578 | 50 | #define ADS1015_CONFIG_COMP_MODE_TRAD 0x0000 |
YJ_Kim | 0:b3c2afab9578 | 51 | #define ADS1015_CONFIG_COMP_MODE_WINDOW 0x0010 |
YJ_Kim | 0:b3c2afab9578 | 52 | |
YJ_Kim | 0:b3c2afab9578 | 53 | #define ADS1015_CONFIG_COMP_POL_ACTVLOW 0x0000 |
YJ_Kim | 0:b3c2afab9578 | 54 | #define ADS1015_CONFIG_COMP_POL_ACTVHI 0x0008 |
YJ_Kim | 0:b3c2afab9578 | 55 | |
YJ_Kim | 0:b3c2afab9578 | 56 | #define ADS1015_CONFIG_COMP_LAT_NONE 0x0000 |
YJ_Kim | 0:b3c2afab9578 | 57 | #define ADS1015_CONFIG_COMP_LAT_LATCH 0x0004 |
YJ_Kim | 0:b3c2afab9578 | 58 | |
YJ_Kim | 0:b3c2afab9578 | 59 | #define ADS1015_CONFIG_COMP_QUE_1CONV 0x0000 |
YJ_Kim | 0:b3c2afab9578 | 60 | #define ADS1015_CONFIG_COMP_QUE_2CONV 0X0001 |
YJ_Kim | 0:b3c2afab9578 | 61 | #define ADS1015_CONFIG_COMP_QUE_4CONV 0x0002 |
YJ_Kim | 0:b3c2afab9578 | 62 | #define ADS1015_CONFIG_COMP_QUE_NONE 0x0003 |
YJ_Kim | 0:b3c2afab9578 | 63 | |
YJ_Kim | 0:b3c2afab9578 | 64 | /*============================================================================= |
YJ_Kim | 0:b3c2afab9578 | 65 | |
YJ_Kim | 0:b3c2afab9578 | 66 | GAIN |
YJ_Kim | 0:b3c2afab9578 | 67 | |
YJ_Kim | 0:b3c2afab9578 | 68 | =============================================================================*/ |
YJ_Kim | 0:b3c2afab9578 | 69 | #define ADS1015_GAIN_TWOTHRIDS 0x0000 |
YJ_Kim | 0:b3c2afab9578 | 70 | #define ADS1015_GAIN_ONE 0x0200 |
YJ_Kim | 0:b3c2afab9578 | 71 | #define ADS1015_GAIN_TWO 0x0400 |
YJ_Kim | 0:b3c2afab9578 | 72 | #define ADS1015_GAIN_FOUR 0x0600 |
YJ_Kim | 0:b3c2afab9578 | 73 | #define ADS1015_GAIN_EIGHT 0x0800 |
YJ_Kim | 0:b3c2afab9578 | 74 | #define ADS1015_GAIN_SIXTEEN 0x0A00 |
YJ_Kim | 0:b3c2afab9578 | 75 | |
YJ_Kim | 0:b3c2afab9578 | 76 | class ADS1015{ |
YJ_Kim | 0:b3c2afab9578 | 77 | public: |
YJ_Kim | 0:b3c2afab9578 | 78 | ADS1015(uint8_t i2c_addr, I2C* i2c_object, uint16_t adc_gain); |
YJ_Kim | 0:b3c2afab9578 | 79 | void write_16(uint8_t reg, uint16_t msg); |
YJ_Kim | 0:b3c2afab9578 | 80 | char read_8(uint8_t reg); |
YJ_Kim | 0:b3c2afab9578 | 81 | |
YJ_Kim | 0:b3c2afab9578 | 82 | private: |
YJ_Kim | 0:b3c2afab9578 | 83 | uint8_t ADS1015_ADDR; |
YJ_Kim | 0:b3c2afab9578 | 84 | uint16_t m_gain; |
YJ_Kim | 0:b3c2afab9578 | 85 | I2C* i2c; |
YJ_Kim | 0:b3c2afab9578 | 86 | } |
YJ_Kim | 0:b3c2afab9578 | 87 | |
YJ_Kim | 0:b3c2afab9578 | 88 | #endif |