108 lines
2.6 KiB
C++
108 lines
2.6 KiB
C++
#ifndef _ads1210_h_
|
|
#define _ads1210_h_
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
|
|
class ADS1210 {
|
|
public:
|
|
ADS1210() {};
|
|
void begin(uint8_t csPin, uint8_t drdyPin, bool initializeConfig, int eepromAddr);
|
|
void exec();
|
|
|
|
float getCalFactor() const { return m_calFactor; };
|
|
float getCalOffset() const { return m_calOffset; };
|
|
void setCalFactor(float calFactor);
|
|
void setCalOffset(float calOffset);
|
|
|
|
uint32_t getValue() const { return m_value; };
|
|
float getU() const { return m_u; };
|
|
float getRRaw() const { return m_rRaw; };
|
|
float getR() const { return m_r; };
|
|
private:
|
|
// register addresses
|
|
const uint8_t ADDR_DOR2 = 0x00;
|
|
const uint8_t ADDR_DOR1 = 0x01;
|
|
const uint8_t ADDR_DOR0 = 0x02;
|
|
|
|
const uint8_t ADDR_CMR3 = 0x04;
|
|
const uint8_t ADDR_CMR2 = 0x05;
|
|
const uint8_t ADDR_CMR1 = 0x06;
|
|
const uint8_t ADDR_CMR0 = 0x07;
|
|
|
|
const uint8_t ADDR_OCR2 = 0x08;
|
|
const uint8_t ADDR_OCR1 = 0x09;
|
|
const uint8_t ADDR_OCR0 = 0x0a;
|
|
|
|
const uint8_t ADDR_FCR2 = 0x0c;
|
|
const uint8_t ADDR_FCR1 = 0x0d;
|
|
const uint8_t ADDR_FCR0 = 0x0e;
|
|
|
|
// bit values
|
|
// CMR
|
|
const uint8_t CMR_BIAS = 0x80;
|
|
const uint8_t CMR_REFO = 0x40;
|
|
const uint8_t CMR_DF = 0x20;
|
|
const uint8_t CMR_UB = 0x10;
|
|
const uint8_t CMR_BD = 0x08;
|
|
const uint8_t CMR_MSB = 0x04;
|
|
const uint8_t CMR_SDL = 0x02;
|
|
const uint8_t CMR_DRDY = 0x01;
|
|
|
|
const uint8_t CMR_MD_Mask = 0xe0;
|
|
const uint8_t CMR_MD_NormalMode = 0x00;
|
|
const uint8_t CMR_MD_SelfCalibration = 0x20;
|
|
const uint8_t CMR_MD_SystemOffsetCalibration = 0x40;
|
|
const uint8_t CMR_MD_SystemFullScaleCalibration = 0x60;
|
|
const uint8_t CMR_MD_PseudoSystemCalibration = 0x80;
|
|
const uint8_t CMD_MD_BackgroundCalibration = 0xa0;
|
|
const uint8_t CMD_MD_Sleep = 0xc0;
|
|
|
|
const uint8_t CMR_Gain_Mask = (0x07 << 2);
|
|
const uint8_t CMR_Gain_1 = 0;
|
|
const uint8_t CMR_Gain_2 = (0x01 << 2);
|
|
const uint8_t CMR_Gain_4 = (0x02 << 2);
|
|
const uint8_t CMR_Gain_8 = (0x03 << 2);
|
|
const uint8_t CMR_Gain_16 = (0x04 << 2);
|
|
|
|
// bit values
|
|
// INSR
|
|
const uint8_t INSR_RW = 0x80;
|
|
const uint8_t INSR_MB1 = 0x40;
|
|
const uint8_t INSR_MB0 = 0x20;
|
|
const uint8_t INSR_ADDR = 0x0f;
|
|
|
|
const float U_REF = 2.5;
|
|
const uint32_t V_MAX = 0x3FFFFF;
|
|
const float R_REF = 3000.0;
|
|
|
|
const uint8_t SKIPPED_BITS = 4;
|
|
|
|
uint8_t m_csPin;
|
|
uint8_t m_drdyPin;
|
|
int m_eepromAddr;
|
|
|
|
float m_calFactor;
|
|
float m_calOffset;
|
|
|
|
uint32_t m_value;
|
|
float m_u;
|
|
float m_rRaw;
|
|
float m_r;
|
|
|
|
void enableCS() const;
|
|
void disableCS() const;
|
|
void writeRegister(const uint8_t regAddr, const uint8_t value) const;
|
|
uint8_t readRegister(const uint8_t regAddr) const;
|
|
void waitForDRdy() const;
|
|
void setMode(uint8_t mode) const;
|
|
void setGain(uint8_t gain) const;
|
|
};
|
|
|
|
|
|
#endif // _ads1210_h_
|