ADS131A04 Example C Code  1.0.0
Macros | Functions | Variables
ads131a04.c File Reference
#include "ads131a04.h"
Include dependency graph for ads131a04.c:

Macros

#define WORD_LENGTH   (WORD_LENGTH_BITS >> 3)
 
#define UPPER_BYTE(x)    ((uint8_t) ((0xFF00 & x) >> 8))
 
#define LOWER_BYTE(x)    ((uint8_t) (0x00FF & x))
 
#define COMBINE_BYTES(x, y)    (((uint16_t) x << 8) | ((uint16_t) y & 0x00FF))
 

Functions

uint8_t getRegisterValue (uint8_t address)
 
void adcStartup (void)
 
uint8_t readSingleRegister (uint8_t address)
 
void writeSingleRegister (uint8_t address, uint8_t data)
 
bool readData (adc_data_struct *dataStruct)
 
uint16_t sendCommand (uint16_t opcode)
 
bool lockRegisters (void)
 
bool unlockRegisters (void)
 
uint16_t calculateCRC (const uint8_t dataBytes[], uint8_t numberBytes, uint16_t initialValue)
 
void restoreRegisterDefaults (void)
 
int32_t signExtend (const uint8_t dataBytes[])
 

Variables

static uint8_t registerMap [((uint8_t) 21)]
 
static bool registersLocked = true
 
static uint8_t dataTx [6 *(((uint8_t) 24) >> 3)] = { 0 }
 
static uint8_t dataRx [6 *(((uint8_t) 24) >> 3)] = { 0 }
 
static uint8_t cmdByteLength = 6 * ( ((uint8_t) 24) >> 3)
 

Macro Definition Documentation

#define COMBINE_BYTES (   x,
 
)    (((uint16_t) x << 8) | ((uint16_t) y & 0x00FF))
#define LOWER_BYTE (   x)    ((uint8_t) (0x00FF & x))
#define UPPER_BYTE (   x)    ((uint8_t) ((0xFF00 & x) >> 8))
#define WORD_LENGTH   (WORD_LENGTH_BITS >> 3)

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 adcStartup ( void  )

Example start up sequence for the ADS131A04.

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

NOTE: You may want to modify this function to configure the ADC's initial register settings to your application's requirements.

Returns
None.

Here is the call graph for this function:

uint16_t calculateCRC ( const uint8_t  dataBytes[],
uint8_t  numberBytes,
uint16_t  initialValue 
)

Calculates the 16-bit CRC for the selected CRC polynomial.

Parameters
dataBytes[]pointer to first element in the data byte array
numberByteslength of data byte array to include in the CRC calculation
initialValuethe seed value (or partial crc calculation), use 0xFFFF when beginning a new CRC computation

NOTE: This calculation is shown as an example and has not been optimized for speed.

Returns
uint16_t calculated CRC word. When performing a partial CRC computation, provide this value as the input to initialValue to resume computing the CRC for additional input bytes.

Here is the call graph for this function:

uint16_t getRegisterValue ( uint8_t  address)

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

NOTE: The internal registerMap arrays stores the last known 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 reading the value of a hardware controlled register, it is recommend to use readSingleRegister() to read the device register.

Parameters
addressis the 8-bit address of the register value to recall.
Returns
unsigned 8-bit register value.
bool lockRegisters ( void  )

Sends the LOCK command and then verifies that registers are locked.

Returns
boolean to indicate if registers are locked (0 = unlocked; 1 = locked)

Here is the call graph for this function:

bool readData ( adc_data_struct dataStruct)

Read ADC data

Parameters
dataStructpointer to data structure where results from reading data will be placed

NOTE: This is currently the only function in this example that verifies if the CRC word on DOUT is correct.

Returns
bool indicating if a CRC mismatch occurred (false = No error)

Here is the call graph for this function:

uint8_t readSingleRegister ( 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:

void restoreRegisterDefaults ( void  )

Updates the registerMap[] array to its default values.

NOTES:

  • If the MCU keeps a copy of the ADC's 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 hardware pin control or SPI software command), as is shown in this example.
Returns
None.
uint16_t sendCommand ( uint16_t  opcode)

Sends the specified SPI command to the ADC (NULL, RESET, STANDBY, or WAKEUP).

Parameters
opcode16-bit SPI command.

NOTE: Other ADC commands have their own dedicated functions to support additional functionality. This function will raise an assert if used with one of these commands (RREG, WREG, WREGS, LOCK,or UNLOCK).

Returns
uint16_t response byte (typically the STATUS byte).

Here is the call graph for this function:

int32_t signExtend ( const uint8_t  dataBytes[])

Internal function used by readData() to convert ADC data from multiple unsigned bytes into a single signed 32-bit word.

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

Sends the UNLOCK command and then verifies that registers are unlocked

Returns
boolean to indicate if registers are locked (0 = unlocked; 1 = locked)

Here is the call graph for this function:

void writeSingleRegister ( uint8_t  address,
uint8_t  data 
)

Writes data to a single register.

This command will be ignored if device registers are locked.

NOTE: This functions also performs a NULL command frame after the register write command to verify the new register value.

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

uint8_t cmdByteLength = 6 * ( ((uint8_t) 24) >> 3)
static
uint8_t dataRx[6 * (((uint8_t) 24) >> 3)] = { 0 }
static
uint8_t dataTx[6 * (((uint8_t) 24) >> 3)] = { 0 }
static
uint8_t registerMap[((uint8_t) 21)]
static
bool registersLocked = true
static