some more initialization code

This commit is contained in:
2014-11-03 17:18:30 +01:00
parent f506f9a2c2
commit 473eb035b1
3 changed files with 63 additions and 12 deletions

View File

@ -1,7 +1,22 @@
#include "Arduino.h"
#include <Streaming.h>
#include "ads1210.h"
ADS1210 ads1210;
void setup() {
Serial.begin(9600);
delay(1000);
pinMode(13, OUTPUT);
ads1210.begin(10);
}
void loop() {
@ -9,4 +24,6 @@ void loop() {
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
Serial << "Tick" << endl;
}

View File

@ -7,9 +7,10 @@
// #include <Arduino.h>
#include <SPI.h>
#include <Streaming.h>
#include "ads1210.h"
ADS1210::ADS1210(uint8_t csPin) : m_csPin(csPin) {
ADS1210::ADS1210() {
}
void ADS1210::enableCS() const {
@ -19,21 +20,33 @@ void ADS1210::disableCS() const {
digitalWrite(m_csPin, HIGH);
}
void ADS1210::writeCMR (const uint8_t cmr3, const uint8_t cmr2,
const uint8_t cmr1, const uint8_t cmr0) const {
void ADS1210::writeCMR () const {
uint8_t instr = INSR_MB1 | INSR_MB0 | ADDR_CMR3;
enableCS();
SPI.transfer(instr);
SPI.transfer(cmr3);
SPI.transfer(cmr2);
SPI.transfer(cmr1);
SPI.transfer(cmr0);
SPI.transfer(m_cmrShadow[3]);
SPI.transfer(m_cmrShadow[2]);
SPI.transfer(m_cmrShadow[1]);
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();
}
void ADS1210::begin() const {
void ADS1210::begin(uint8_t csPin) {
m_csPin = csPin;
// initialization of SPI
pinMode(m_csPin, OUTPUT);
digitalWrite(m_csPin, HIGH);
@ -43,5 +56,8 @@ void ADS1210::begin() const {
SPI.setDataMode(SPI_MODE0);
// 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;
}

View File

@ -10,8 +10,8 @@
class ADS1210 {
public:
ADS1210(uint8_t csPin);
void begin() const;
ADS1210();
void begin(uint8_t csPin);
uint32_t get();
private:
// register addresses
@ -43,6 +43,22 @@ private:
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 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
// INSR
const uint8_t INSR_RW = 0x80;
@ -52,10 +68,12 @@ private:
uint8_t m_csPin;
uint8_t m_cmrShadow[4];
void enableCS() const;
void disableCS() const;
void writeCMR (const uint8_t cmr3, const uint8_t cmr2,
const uint8_t cmr1, const uint8_t cmr0) const;
void writeCMR() const;
void readCMR();
};