some more initialization code
This commit is contained in:
@ -1,7 +1,22 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
#include <Streaming.h>
|
||||||
|
|
||||||
|
#include "ads1210.h"
|
||||||
|
|
||||||
|
|
||||||
|
ADS1210 ads1210;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
Serial.begin(9600);
|
||||||
|
delay(1000);
|
||||||
|
|
||||||
pinMode(13, OUTPUT);
|
pinMode(13, OUTPUT);
|
||||||
|
|
||||||
|
ads1210.begin(10);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@ -9,4 +24,6 @@ void loop() {
|
|||||||
delay(1000); // wait for a second
|
delay(1000); // wait for a second
|
||||||
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
|
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
|
||||||
delay(1000); // wait for a second
|
delay(1000); // wait for a second
|
||||||
|
|
||||||
|
Serial << "Tick" << endl;
|
||||||
}
|
}
|
||||||
|
32
ads1210.cpp
32
ads1210.cpp
@ -7,9 +7,10 @@
|
|||||||
|
|
||||||
// #include <Arduino.h>
|
// #include <Arduino.h>
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
|
#include <Streaming.h>
|
||||||
#include "ads1210.h"
|
#include "ads1210.h"
|
||||||
|
|
||||||
ADS1210::ADS1210(uint8_t csPin) : m_csPin(csPin) {
|
ADS1210::ADS1210() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ADS1210::enableCS() const {
|
void ADS1210::enableCS() const {
|
||||||
@ -19,21 +20,33 @@ void ADS1210::disableCS() const {
|
|||||||
digitalWrite(m_csPin, HIGH);
|
digitalWrite(m_csPin, HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ADS1210::writeCMR (const uint8_t cmr3, const uint8_t cmr2,
|
void ADS1210::writeCMR () const {
|
||||||
const uint8_t cmr1, const uint8_t cmr0) const {
|
|
||||||
uint8_t instr = INSR_MB1 | INSR_MB0 | ADDR_CMR3;
|
uint8_t instr = INSR_MB1 | INSR_MB0 | ADDR_CMR3;
|
||||||
enableCS();
|
enableCS();
|
||||||
SPI.transfer(instr);
|
SPI.transfer(instr);
|
||||||
SPI.transfer(cmr3);
|
SPI.transfer(m_cmrShadow[3]);
|
||||||
SPI.transfer(cmr2);
|
SPI.transfer(m_cmrShadow[2]);
|
||||||
SPI.transfer(cmr1);
|
SPI.transfer(m_cmrShadow[1]);
|
||||||
SPI.transfer(cmr0);
|
SPI.transfer(m_cmrShadow[0]);
|
||||||
|
disableCS();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ADS1210::readCMR () {
|
||||||
|
uint8_t instr = INSR_MB1 | INSR_MB0 | ADDR_CMR3 | INSR_RW;
|
||||||
|
enableCS();
|
||||||
|
SPI.transfer(instr);
|
||||||
|
m_cmrShadow[3] = SPI.transfer(0);
|
||||||
|
m_cmrShadow[2] = SPI.transfer(0);
|
||||||
|
m_cmrShadow[1] = SPI.transfer(0);
|
||||||
|
m_cmrShadow[0] = SPI.transfer(0);
|
||||||
disableCS();
|
disableCS();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ADS1210::begin() const {
|
void ADS1210::begin(uint8_t csPin) {
|
||||||
|
m_csPin = csPin;
|
||||||
|
|
||||||
// initialization of SPI
|
// initialization of SPI
|
||||||
pinMode(m_csPin, OUTPUT);
|
pinMode(m_csPin, OUTPUT);
|
||||||
digitalWrite(m_csPin, HIGH);
|
digitalWrite(m_csPin, HIGH);
|
||||||
@ -43,5 +56,8 @@ void ADS1210::begin() const {
|
|||||||
SPI.setDataMode(SPI_MODE0);
|
SPI.setDataMode(SPI_MODE0);
|
||||||
|
|
||||||
// initialization of the ADS1210
|
// initialization of the ADS1210
|
||||||
|
readCMR();
|
||||||
|
|
||||||
|
Serial << "CMR3: " << _HEX(m_cmrShadow[3]) << ", CMR2: " << _HEX(m_cmrShadow[2]) << ", CMR1: " << _HEX(m_cmrShadow[1]) << ", CMR0: " << _HEX(m_cmrShadow[0]) << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
26
ads1210.h
26
ads1210.h
@ -10,8 +10,8 @@
|
|||||||
|
|
||||||
class ADS1210 {
|
class ADS1210 {
|
||||||
public:
|
public:
|
||||||
ADS1210(uint8_t csPin);
|
ADS1210();
|
||||||
void begin() const;
|
void begin(uint8_t csPin);
|
||||||
uint32_t get();
|
uint32_t get();
|
||||||
private:
|
private:
|
||||||
// register addresses
|
// register addresses
|
||||||
@ -42,6 +42,22 @@ private:
|
|||||||
const uint8_t CMR_MSB = 0x04;
|
const uint8_t CMR_MSB = 0x04;
|
||||||
const uint8_t CMR_SDL = 0x02;
|
const uint8_t CMR_SDL = 0x02;
|
||||||
const uint8_t CMR_DRDY = 0x01;
|
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 CMD_Gain_1 = 0;
|
||||||
|
const uint8_t CMD_Gain_2 = (0x01 << 2);
|
||||||
|
const uint8_t CMD_Gain_4 = (0x02 << 2);
|
||||||
|
const uint8_t CMD_Gain_8 = (0x03 << 2);
|
||||||
|
const uint8_t CMD_Gain_16 = (0x04 << 2);
|
||||||
|
|
||||||
// bit values
|
// bit values
|
||||||
// INSR
|
// INSR
|
||||||
@ -52,10 +68,12 @@ private:
|
|||||||
|
|
||||||
uint8_t m_csPin;
|
uint8_t m_csPin;
|
||||||
|
|
||||||
|
uint8_t m_cmrShadow[4];
|
||||||
|
|
||||||
void enableCS() const;
|
void enableCS() const;
|
||||||
void disableCS() const;
|
void disableCS() const;
|
||||||
void writeCMR (const uint8_t cmr3, const uint8_t cmr2,
|
void writeCMR() const;
|
||||||
const uint8_t cmr1, const uint8_t cmr0) const;
|
void readCMR();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user