ADS1282 Example C Code
1.0.0
|
ADS1282 Example Code. More...
#include "ads1282.h"
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... | |
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.
void _restoreRegisterDefaults | ( | void | ) |
Reverts internal variables to default state after a reset.
NOTES:
|
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
[in] | dataBytes | is a pointer to uint8_t[] where the first element is the MSB. |
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.
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().
int32_t readData | ( | void | ) |
Function for retrieving ADC conversion results
Example of reading data continuously:
Example of reading data by command:
void readMultipleRegisters | ( | const uint8_t | startAddress, |
const uint8_t | count | ||
) |
Reads the contents of multiple registers starting at the specified address.
startAddress | is the 8-bit starting address of the first register to read. |
count | total number of register to read |
uint8_t readSingleRegister | ( | const uint8_t | address | ) |
Reads the contents of a single register at the specified address.
address | is the 8-bit address of the register to read. |
uint8_t sendCommand | ( | const uint8_t | op_code | ) |
Function for sending single byte SPI commands to the ADC
op_code | the command byte/opcode. |
NOTE: Multi-byte SPI commands have their own dedicated functions.
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.
startAddress | is the 8-bit starting address of the first register to begin writing. |
count | is 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. |
void writeSingleRegister | ( | const uint8_t | address, |
const uint8_t | data | ||
) |
Writes data to a single register.
address | is the address of the register to write to. |
data | is the value to write. |
|
static |
Flag to track if device is in SDATAC mode (false) or RDATAC mode (true)
|
static |
Internal register map array (to recall current configuration)