ADS1282 Example C Code  1.0.0
Functions | Variables
ads1282.c File Reference

ADS1282 Example Code. More...

#include "ads1282.h"
Include dependency graph for ads1282.c:

Functions

static int32_t _signExtendData (const uint8_t dataBytes[])
 
uint8_t getRegisterValue (const uint8_t address)
 
void adcStartupRoutine (void)
 
uint8_t readSingleRegister (const uint8_t address)
 
void readMultipleRegisters (const uint8_t startAddress, const uint8_t count)
 
void writeSingleRegister (const uint8_t address, const uint8_t data)
 
void writeMultipleRegisters (const uint8_t startAddress, const uint8_t count, const uint8_t dataArray[])
 
void sendCommand (const uint8_t op_code)
 
int32_t readData (void)
 
void _restoreRegisterDefaults (void)
 

Variables

static uint8_t registerMap [((uint8_t) 11)]
 Internal register map array (to recall current configuration) More...
 
static bool readContinuousMode = false
 Flag to track if device is in SDATAC mode (false) or RDATAC mode (true) More...
 

Detailed Description

ADS1282 Example Code.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

Neither the name of Texas Instruments Incorporated nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Function Documentation

void _restoreRegisterDefaults ( void  )

Reverts internal variables to default state after a reset.

Warning
This function should only be called if the ADS1282 is reset by some external method (other than calling "sendCommand(OPCODE_RESET)" or "adcStartupRoutine()", such as a hardware reset OR power-cycle).

NOTES:

  • If the MCU keeps a copy of the ADC register settings in memory, then it is important to ensure that these values remain in sync with the actual hardware settings. In order to help facilitate this, this function should be called after powering up or resetting the device (either by toggling the nRESET pin or sending the SPI "RESET" command). Whenever possible, the "ads1282.c" module automatically handles this requirement.
Returns
None.
static int32_t _signExtendData ( const uint8_t  dataBytes[])
static

Combines ADC data bytes into a single signed 32-bit word To convert from an integer value to a voltage, multiply the return value of this function by the "LSB size" = FSR / 2^31, where: Full-scale range (FSR) = VREF / PGA 2^31 = total number of ADC output codes

Parameters
[in]dataBytesis a pointer to uint8_t[] where the first element is the MSB.
Returns
Returns the signed-extend 32-bit result.
void adcStartupRoutine ( void  )

Example start up sequence.

Before calling this function, the device must be powered, the SPI/GPIO pins of the MCU must have already been configured, and the external clock source provided to CLKIN.

Returns
None.

Here is the call graph for this function:

uint8_t getRegisterValue ( const uint8_t  address)

Getter function to access registerMap array from outside of this module.

NOTE: The internal registerMap arrays stores the last know register value, since the last read or write operation to that register. This function does not communicate with the device to retrieve the current register value. For the most up-to-date register data or retrieving the value of a hardware controlled register use readSingleRegister().

Returns
unsigned 8-bit register value.
int32_t readData ( void  )

Function for retrieving ADC conversion results

Returns
31-bit ADC data (signed-extended to 32-bits).

Example of reading data continuously:

1 // Device should be in RDATAC mode
2 sendCommand(OPCODE_RDATAC);
3 
4 for (i = 0; i < NUM_SAMPLES; i++)
5 {
6  // Wait for nDRDY to go low (or timeout)
7  waitForDRDYinterrupt(TIMEOUT_uSEC);
8 
9  // Read data
10  int32_t data = readData();
11 }

Example of reading data by command:

1 // Device should be in SDATAC mode
2 sendCommand(OPCODE_SDATAC);
3 
4 for (i = 0; i < NUM_SAMPLES; i++)
5 {
6  // Send RDATA command
7  sendCommand(OPCODE_RDATA);
8 
9  // Wait for nDRDY to go low (or timeout)
10  waitForDRDYinterrupt(TIMEOUT_uSEC);
11 
12  // Read data
13  int32_t data = readData();
14 }

Here is the call graph for this function:

void readMultipleRegisters ( const uint8_t  startAddress,
const uint8_t  count 
)

Reads the contents of multiple registers starting at the specified address.

Parameters
startAddressis the 8-bit starting address of the first register to read.
counttotal number of register to read
Returns
None. Register data can retrieved later by calling getRegisterValue().

Here is the call graph for this function:

uint8_t readSingleRegister ( const uint8_t  address)

Reads the contents of a single register at the specified address.

Parameters
addressis the 8-bit address of the register to read.
Returns
Returns the 8-bit register read result.

Here is the call graph for this function:

uint8_t sendCommand ( const uint8_t  op_code)

Function for sending single byte SPI commands to the ADC

Parameters
op_codethe command byte/opcode.

NOTE: Multi-byte SPI commands have their own dedicated functions.

Returns
None.

Here is the call graph for this function:

void writeMultipleRegisters ( const uint8_t  startAddress,
const uint8_t  count,
const uint8_t  dataArray[] 
)

Writes data to a multiple registers starting at the specified address.

Parameters
startAddressis the 8-bit starting address of the first register to begin writing.
countis the total number of registers to write.
dataArray[]is the data array containing the new register values, where dataArray[0] is the value to be written to the 'startAddress' register.
Returns
None.

Here is the call graph for this function:

void writeSingleRegister ( const uint8_t  address,
const uint8_t  data 
)

Writes data to a single register.

Parameters
addressis the address of the register to write to.
datais the value to write.
Returns
None.

Here is the call graph for this function:

Variable Documentation

bool readContinuousMode = false
static

Flag to track if device is in SDATAC mode (false) or RDATAC mode (true)

uint8_t registerMap[((uint8_t) 11)]
static

Internal register map array (to recall current configuration)