add gain=2, non-blocking operation, led abstracted
This commit is contained in:
50
ads1210.cpp
50
ads1210.cpp
@ -13,8 +13,6 @@
|
||||
|
||||
|
||||
|
||||
ADS1210::ADS1210() {
|
||||
}
|
||||
|
||||
void ADS1210::enableCS() const {
|
||||
digitalWrite(m_csPin, LOW);
|
||||
@ -33,10 +31,6 @@ void ADS1210::waitForDRdy() const {
|
||||
}
|
||||
}
|
||||
|
||||
void ADS1210::waitForDRdyWOTimeout() const {
|
||||
while (0 != digitalRead(m_drdyPin)) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ADS1210::writeRegister(const uint8_t regAddr, const uint8_t value) const {
|
||||
@ -60,25 +54,26 @@ uint8_t ADS1210::readRegister(const uint8_t regAddr) const {
|
||||
return res;
|
||||
}
|
||||
|
||||
uint32_t ADS1210::readDataOutRegister() const {
|
||||
union {
|
||||
uint8_t in[4];
|
||||
uint32_t out;
|
||||
} res;
|
||||
void ADS1210::exec() {
|
||||
if (0 == digitalRead(m_drdyPin)) {
|
||||
union {
|
||||
uint8_t in[4];
|
||||
uint32_t out;
|
||||
} res;
|
||||
|
||||
waitForDRdy();
|
||||
enableCS();
|
||||
SPI.transfer(ADDR_DOR2 | INSR_MB1 | INSR_RW);
|
||||
res.in[2] = SPI.transfer(0);
|
||||
res.in[1] = SPI.transfer(0);
|
||||
res.in[0] = SPI.transfer(0);
|
||||
res.in[3] = 0;
|
||||
disableCS();
|
||||
enableCS();
|
||||
SPI.transfer(ADDR_DOR2 | INSR_MB1 | INSR_RW);
|
||||
res.in[2] = SPI.transfer(0);
|
||||
res.in[1] = SPI.transfer(0);
|
||||
res.in[0] = SPI.transfer(0);
|
||||
res.in[3] = 0;
|
||||
disableCS();
|
||||
|
||||
Serial << "DOR4x8: " << _HEX(res.in[3]) << " " << _HEX(res.in[2]) << " " << _HEX(res.in[1]) << " " << _HEX(res.in[0]) << endl;
|
||||
Serial << "DOR1x32: " << _HEX(res.out) << endl;
|
||||
|
||||
return res.out;
|
||||
Serial << "DOR4x8: " << _HEX(res.in[3]) << " " << _HEX(res.in[2]) << " " << _HEX(res.in[1]) << " " << _HEX(res.in[0]) << endl;
|
||||
Serial << "DOR1x32: " << _HEX(res.out) << endl;
|
||||
|
||||
value = res.out;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -129,14 +124,15 @@ void ADS1210::begin(uint8_t csPin, uint8_t drdyPin) {
|
||||
pinMode(m_drdyPin, INPUT);
|
||||
writeRegister(ADDR_CMR3, CMR_SDL | CMR_UB | CMR_REFO);
|
||||
Serial << "done." << endl;
|
||||
|
||||
Serial << "Set gain ... ";
|
||||
setGain(CMR_Gain_2);
|
||||
Serial << "done." << endl;
|
||||
|
||||
Serial << "SelfCalibration ... ";
|
||||
setMode(CMR_MD_SelfCalibration);
|
||||
waitForDRdyWOTimeout();
|
||||
waitForDRdy();
|
||||
Serial << "done." << endl;
|
||||
}
|
||||
|
||||
|
||||
uint32_t ADS1210::get() const {
|
||||
return readDataOutRegister();
|
||||
}
|
||||
|
Reference in New Issue
Block a user