Skip to content

Commit 7a1eb75

Browse files
authored
Merge pull request #6 from sparkfun/release_candidate
v1.0.2
2 parents 05ba22c + 61974a1 commit 7a1eb75

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

keywords.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ getIDACcurrent KEYWORD2
5656
getIDAC1mux KEYWORD2
5757
getIDAC2mux KEYWORD2
5858
printADS122C04config KEYWORD2
59-
59+
getDeviceAddress KEYWORD2
60+
getWireMode KEYWORD2
6061

6162
#######################################
6263
# Constants (LITERAL1)

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun ADS122C04 ADC Arduino Library
2-
version=1.0.1
2+
version=1.0.2
33
author=SparkFun Electronics <[email protected]>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Arduino library for the TI ADS122C04

src/SparkFun_ADS122C04_ADC_Arduino_Library.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ boolean SFE_ADS122C04::begin(uint8_t deviceAddress, TwoWire &wirePort)
6969
}
7070

7171
// Configure the chip for the selected wire mode
72-
boolean SFE_ADS122C04::configureADCmode(uint8_t wire_mode)
72+
boolean SFE_ADS122C04::configureADCmode(uint8_t wire_mode, uint8_t rate)
7373
{
7474
ADS122C04_initParam initParams; // Storage for the chip parameters
7575

@@ -78,7 +78,7 @@ boolean SFE_ADS122C04::configureADCmode(uint8_t wire_mode)
7878
initParams.inputMux = ADS122C04_MUX_AIN1_AIN0; // Route AIN1 to AINP and AIN0 to AINN
7979
initParams.gainLevel = ADS122C04_GAIN_8; // Set the gain to 8
8080
initParams.pgaBypass = ADS122C04_PGA_ENABLED; // The PGA must be enabled for gains >= 8
81-
initParams.dataRate = ADS122C04_DATA_RATE_20SPS; // Set the data rate (samples per second) to 20
81+
initParams.dataRate = rate; // Set the data rate (samples per second). Defaults to 20
8282
initParams.opMode = ADS122C04_OP_MODE_NORMAL; // Disable turbo mode
8383
initParams.convMode = ADS122C04_CONVERSION_MODE_SINGLE_SHOT; // Use single shot mode
8484
initParams.selectVref = ADS122C04_VREF_EXT_REF_PINS; // Use the external REF pins
@@ -96,7 +96,7 @@ boolean SFE_ADS122C04::configureADCmode(uint8_t wire_mode)
9696
initParams.inputMux = ADS122C04_MUX_AIN1_AIN0; // Route AIN1 to AINP and AIN0 to AINN
9797
initParams.gainLevel = ADS122C04_GAIN_4; // Set the gain to 4
9898
initParams.pgaBypass = ADS122C04_PGA_ENABLED; // Enable the PGA
99-
initParams.dataRate = ADS122C04_DATA_RATE_20SPS; // Set the data rate (samples per second) to 20
99+
initParams.dataRate = rate; // Set the data rate (samples per second). Defaults to 20
100100
initParams.opMode = ADS122C04_OP_MODE_NORMAL; // Disable turbo mode
101101
initParams.convMode = ADS122C04_CONVERSION_MODE_SINGLE_SHOT; // Use single shot mode
102102
initParams.selectVref = ADS122C04_VREF_EXT_REF_PINS; // Use the external REF pins
@@ -114,7 +114,7 @@ boolean SFE_ADS122C04::configureADCmode(uint8_t wire_mode)
114114
initParams.inputMux = ADS122C04_MUX_AIN1_AIN0; // Route AIN1 to AINP and AIN0 to AINN
115115
initParams.gainLevel = ADS122C04_GAIN_8; // Set the gain to 8
116116
initParams.pgaBypass = ADS122C04_PGA_ENABLED; // The PGA must be enabled for gains >= 8
117-
initParams.dataRate = ADS122C04_DATA_RATE_20SPS; // Set the data rate (samples per second) to 20
117+
initParams.dataRate = rate; // Set the data rate (samples per second). Defaults to 20
118118
initParams.opMode = ADS122C04_OP_MODE_NORMAL; // Disable turbo mode
119119
initParams.convMode = ADS122C04_CONVERSION_MODE_SINGLE_SHOT; // Use single shot mode
120120
initParams.selectVref = ADS122C04_VREF_EXT_REF_PINS; // Use the external REF pins
@@ -132,7 +132,7 @@ boolean SFE_ADS122C04::configureADCmode(uint8_t wire_mode)
132132
initParams.inputMux = ADS122C04_MUX_AIN1_AIN0; // Route AIN1 to AINP and AIN0 to AINN
133133
initParams.gainLevel = ADS122C04_GAIN_4; // Set the gain to 4
134134
initParams.pgaBypass = ADS122C04_PGA_ENABLED; // Enable the PGA
135-
initParams.dataRate = ADS122C04_DATA_RATE_20SPS; // Set the data rate (samples per second) to 20
135+
initParams.dataRate = rate; // Set the data rate (samples per second). Defaults to 20
136136
initParams.opMode = ADS122C04_OP_MODE_NORMAL; // Disable turbo mode
137137
initParams.convMode = ADS122C04_CONVERSION_MODE_SINGLE_SHOT; // Use single shot mode
138138
initParams.selectVref = ADS122C04_VREF_EXT_REF_PINS; // Use the external REF pins
@@ -150,7 +150,7 @@ boolean SFE_ADS122C04::configureADCmode(uint8_t wire_mode)
150150
initParams.inputMux = ADS122C04_MUX_AIN1_AIN0; // Route AIN1 to AINP and AIN0 to AINN
151151
initParams.gainLevel = ADS122C04_GAIN_8; // Set the gain to 8
152152
initParams.pgaBypass = ADS122C04_PGA_ENABLED; // The PGA must be enabled for gains >= 8
153-
initParams.dataRate = ADS122C04_DATA_RATE_20SPS; // Set the data rate (samples per second) to 20
153+
initParams.dataRate = rate; // Set the data rate (samples per second). Defaults to 20
154154
initParams.opMode = ADS122C04_OP_MODE_NORMAL; // Disable turbo mode
155155
initParams.convMode = ADS122C04_CONVERSION_MODE_SINGLE_SHOT; // Use single shot mode
156156
initParams.selectVref = ADS122C04_VREF_EXT_REF_PINS; // Use the external REF pins
@@ -168,7 +168,7 @@ boolean SFE_ADS122C04::configureADCmode(uint8_t wire_mode)
168168
initParams.inputMux = ADS122C04_MUX_AIN1_AIN0; // Route AIN1 to AINP and AIN0 to AINN
169169
initParams.gainLevel = ADS122C04_GAIN_4; // Set the gain to 4
170170
initParams.pgaBypass = ADS122C04_PGA_ENABLED; // Enable the PGA
171-
initParams.dataRate = ADS122C04_DATA_RATE_20SPS; // Set the data rate (samples per second) to 20
171+
initParams.dataRate = rate; // Set the data rate (samples per second). Defaults to 20
172172
initParams.opMode = ADS122C04_OP_MODE_NORMAL; // Disable turbo mode
173173
initParams.convMode = ADS122C04_CONVERSION_MODE_SINGLE_SHOT; // Use single shot mode
174174
initParams.selectVref = ADS122C04_VREF_EXT_REF_PINS; // Use the external REF pins
@@ -186,7 +186,7 @@ boolean SFE_ADS122C04::configureADCmode(uint8_t wire_mode)
186186
initParams.inputMux = ADS122C04_MUX_AIN1_AIN0; // Route AIN1 to AINP and AIN0 to AINN
187187
initParams.gainLevel = ADS122C04_GAIN_1; // Set the gain to 1
188188
initParams.pgaBypass = ADS122C04_PGA_DISABLED;
189-
initParams.dataRate = ADS122C04_DATA_RATE_20SPS; // Set the data rate (samples per second) to 20
189+
initParams.dataRate = rate; // Set the data rate (samples per second). Defaults to 20
190190
initParams.opMode = ADS122C04_OP_MODE_NORMAL; // Disable turbo mode
191191
initParams.convMode = ADS122C04_CONVERSION_MODE_SINGLE_SHOT; // Use single shot mode
192192
initParams.selectVref = ADS122C04_VREF_INTERNAL; // Use the internal 2.048V reference
@@ -204,7 +204,7 @@ boolean SFE_ADS122C04::configureADCmode(uint8_t wire_mode)
204204
initParams.inputMux = ADS122C04_MUX_AIN1_AIN0; // Route AIN1 to AINP and AIN0 to AINN
205205
initParams.gainLevel = ADS122C04_GAIN_1; // Set the gain to 1
206206
initParams.pgaBypass = ADS122C04_PGA_DISABLED;
207-
initParams.dataRate = ADS122C04_DATA_RATE_20SPS; // Set the data rate (samples per second) to 20
207+
initParams.dataRate = rate; // Set the data rate (samples per second). Defaults to 20
208208
initParams.opMode = ADS122C04_OP_MODE_NORMAL; // Disable turbo mode
209209
initParams.convMode = ADS122C04_CONVERSION_MODE_SINGLE_SHOT; // Use single shot mode
210210
initParams.selectVref = ADS122C04_VREF_INTERNAL; // Use the internal 2.048V reference
@@ -373,16 +373,17 @@ float SFE_ADS122C04::readPT100Fahrenheit(void) // Read the temperature in Fahren
373373

374374
// Read the raw signed 24-bit ADC value as int32_t
375375
// The result needs to be multiplied by VREF / GAIN to convert to Volts
376-
int32_t SFE_ADS122C04::readRawVoltage(void)
376+
int32_t SFE_ADS122C04::readRawVoltage(uint8_t rate)
377377
{
378378
raw_voltage_union raw_v; // union to convert uint32_t to int32_t
379379
unsigned long start_time = millis(); // Record the start time so we can timeout
380380
boolean drdy = false; // DRDY (1 == new data is ready)
381381
uint8_t previousWireMode = _wireMode; // Record the previous wire mode so we can restore it
382+
uint8_t previousRate = ADS122C04_Reg.reg1.bit.DR; // Record the previous rate so we can restore it
382383

383384
// Configure the ADS122C04 for raw mode
384385
// Disable the IDAC, use the internal 2.048V reference and set the gain to 1
385-
if ((configureADCmode(ADS122C04_RAW_MODE)) == false)
386+
if ((configureADCmode(ADS122C04_RAW_MODE, rate)) == false)
386387
{
387388
if (_printDebug == true)
388389
{
@@ -408,7 +409,7 @@ int32_t SFE_ADS122C04::readRawVoltage(void)
408409
{
409410
_debugPort->println(F("readRawVoltage: checkDataReady timed out"));
410411
}
411-
configureADCmode(previousWireMode); // Attempt to restore the previous wire mode
412+
configureADCmode(previousWireMode, previousRate); // Attempt to restore the previous wire mode
412413
return(0);
413414
}
414415

@@ -419,12 +420,12 @@ int32_t SFE_ADS122C04::readRawVoltage(void)
419420
{
420421
_debugPort->println(F("readRawVoltage: ADS122C04_getConversionData failed"));
421422
}
422-
configureADCmode(previousWireMode); // Attempt to restore the previous wire mode
423+
configureADCmode(previousWireMode, previousRate); // Attempt to restore the previous wire mode
423424
return(0);
424425
}
425426

426427
// Restore the previous wire mode
427-
if ((configureADCmode(previousWireMode)) == false)
428+
if ((configureADCmode(previousWireMode, previousRate)) == false)
428429
{
429430
if (_printDebug == true)
430431
{
@@ -463,18 +464,19 @@ uint32_t SFE_ADS122C04::readADC(void)
463464
}
464465

465466
// Read the internal temperature
466-
float SFE_ADS122C04::readInternalTemperature(void)
467+
float SFE_ADS122C04::readInternalTemperature(uint8_t rate)
467468
{
468469
internal_temperature_union int_temp; // union to convert uint16_t to int16_t
469470
uint32_t raw_temp; // The raw temperature from the ADC
470471
unsigned long start_time = millis(); // Record the start time so we can timeout
471472
boolean drdy = false; // DRDY (1 == new data is ready)
472473
float ret_val = 0.0; // The return value
473474
uint8_t previousWireMode = _wireMode; // Record the previous wire mode so we can restore it
475+
uint8_t previousRate = ADS122C04_Reg.reg1.bit.DR; // Record the previous rate so we can restore it
474476

475477
// Enable the internal temperature sensor
476478
// Reading the ADC value will return the temperature
477-
if ((configureADCmode(ADS122C04_TEMPERATURE_MODE)) == false)
479+
if ((configureADCmode(ADS122C04_TEMPERATURE_MODE, rate)) == false)
478480
{
479481
if (_printDebug == true)
480482
{
@@ -500,7 +502,7 @@ float SFE_ADS122C04::readInternalTemperature(void)
500502
{
501503
_debugPort->println(F("readInternalTemperature: checkDataReady timed out"));
502504
}
503-
configureADCmode(previousWireMode); // Attempt to restore the previous wire mode
505+
configureADCmode(previousWireMode, previousRate); // Attempt to restore the previous wire mode
504506
return(ret_val);
505507
}
506508

@@ -511,12 +513,12 @@ float SFE_ADS122C04::readInternalTemperature(void)
511513
{
512514
_debugPort->println(F("readInternalTemperature: ADS122C04_getConversionData failed"));
513515
}
514-
configureADCmode(previousWireMode); // Attempt to restore the previous wire mode
516+
configureADCmode(previousWireMode, previousRate); // Attempt to restore the previous wire mode
515517
return(ret_val);
516518
}
517519

518520
// Restore the previous wire mode
519-
if ((configureADCmode(previousWireMode)) == false)
521+
if ((configureADCmode(previousWireMode, previousRate)) == false)
520522
{
521523
if (_printDebug == true)
522524
{

src/SparkFun_ADS122C04_ADC_Arduino_Library.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,21 +324,21 @@ class SFE_ADS122C04
324324
// Read the raw signed 24-bit ADC value as int32_t
325325
// This uses the internal 2.048V reference with the gain set to 1
326326
// The LSB is 2.048 / 2^23 = 0.24414 uV (0.24414 microvolts)
327-
int32_t readRawVoltage(void);
327+
int32_t readRawVoltage(uint8_t rate = ADS122C04_DATA_RATE_20SPS);
328328

329329
// Read the raw signed 24-bit ADC value as uint32_t
330330
// The ADC data is returned in the least-significant 24-bits
331331
uint32_t readADC(void);
332332

333333
// Read the internal temperature (C)
334-
float readInternalTemperature(void);
334+
float readInternalTemperature(uint8_t rate = ADS122C04_DATA_RATE_20SPS);
335335

336336
boolean reset(void); // Reset the ADS122C04
337337
boolean start(void); // Start a conversion
338338
boolean powerdown(void); // Put the chip into low power mode
339339

340340
// Default to using 'safe' settings (disable the IDAC current sources)
341-
boolean configureADCmode(uint8_t wire_mode = ADS122C04_RAW_MODE); // Configure the chip for the chosen mode
341+
boolean configureADCmode(uint8_t wire_mode = ADS122C04_RAW_MODE, uint8_t rate = ADS122C04_DATA_RATE_20SPS); // Configure the chip for the chosen mode
342342

343343
// Default to using 'safe' settings (disable the IDAC current sources)
344344
boolean setInputMultiplexer(uint8_t mux_config = ADS122C04_MUX_AIN1_AIN0); // Configure the input multiplexer
@@ -376,6 +376,10 @@ class SFE_ADS122C04
376376
// Print the ADS122C04 configuration (but only if enableDebugging has been called)
377377
void printADS122C04config(void);
378378

379+
// Requested in #5
380+
uint8_t getDeviceAddress(void) { return (_deviceAddress); }
381+
uint8_t getWireMode(void) { return (_wireMode); }
382+
379383
private:
380384
//Variables
381385
TwoWire *_i2cPort; //The generic connection to user's chosen I2C hardware

0 commit comments

Comments
 (0)