modm API documentation
modm::ads101x< I2cMaster > Class Template Reference

#include <modm/driver/adc/ads101x.hpp>

Inheritance diagram for modm::ads101x< I2cMaster >:
modm::I2cDevice< I2cMaster, 2 > modm::NestedResumable< 10+1 >

Classes

struct  Data
 

Public Typedefs

typedef Configuration< ConfigRegister_t, FullScaleRange,(Bit11|Bit10|Bit9)> FullScaleRange_t
 
typedef Configuration< ConfigRegister_t, DeviceOperatingMode, Bit8 > DeviceOperatingMode_t
 
typedef Configuration< ConfigRegister_t, InputMultiplexer,(Bit14|Bit13|Bit12)> InputMultiplexer_t
 
typedef Configuration< ConfigRegister_t, DataRate,(Bit7|Bit6|Bit5)> DataRate_t
 
typedef Configuration< ConfigRegister_t, ComparatorMode, Bit4 > ComparatorMode_t
 
typedef Configuration< ConfigRegister_t, ComparatorPolarity, Bit3 > ComparatorPolarity_t
 
typedef Configuration< ConfigRegister_t, ComparatorLatch, Bit2 > ComparatorLatch_t
 
typedef Configuration< ConfigRegister_t, ComparatorQueue, Bit4 > ComparatorQueue_t
 

Public Types

enum  Register : uint8_t { Conversion = 0b00, Config = 0b01, LowThreshold = 0b10, HighThreshold = 0b11 }
 
enum  ConfigRegister : uint16_t {
  OS = Bit15, MUX2 = Bit14, MUX1 = Bit13, MUX0 = Bit12,
  PGA2 = Bit11, PGA1 = Bit10, PGA0 = Bit9, MODE = Bit8,
  DR2 = Bit7, DR1 = Bit6, DR0 = Bit5, COMP_MODE = Bit4,
  COMP_POL = Bit3, COMP_LAT = Bit2, COMP_QUE1 = Bit1, COMP_QUE0 = Bit0
}
 The Config register is used to control the operating mode, input selection, data rate, full-scale range, and comparator modes.
 
enum  FullScaleRange : uint16_t {
  V6_144 = 0, V4_096 = int(ConfigRegister::PGA0), V2_048 = int(ConfigRegister::PGA1), V1_024 = int(ConfigRegister::PGA1) | int(ConfigRegister::PGA0),
  V0_512 = int(ConfigRegister::PGA2), V0_256 = int(ConfigRegister::PGA2) | int(ConfigRegister::PGA0)
}
 
enum  DeviceOperatingMode : uint16_t { Continuous = 0, SingleShot = int(ConfigRegister::MODE) }
 
enum  InputMultiplexer : uint16_t {
  Input0 = 0, Input1 = int(ConfigRegister::MUX0), Input2 = int(ConfigRegister::MUX1), Input3 = int(ConfigRegister::MUX1) | int(ConfigRegister::MUX0),
  Input4 = int(ConfigRegister::MUX2), Input5 = int(ConfigRegister::MUX2) | int(ConfigRegister::MUX0), Input6 = int(ConfigRegister::MUX2) | int(ConfigRegister::MUX1), Input7 = int(ConfigRegister::MUX2) | int(ConfigRegister::MUX1) | int(ConfigRegister::MUX0)
}
 
enum  DataRate : uint16_t {
  Sps128 = 0, Sps250 = int(ConfigRegister::DR0), Sps490 = int(ConfigRegister::DR1), Sps920 = int(ConfigRegister::DR1) | int(ConfigRegister::DR0),
  Sps1600 = int(ConfigRegister::DR2), Sps2400 = int(ConfigRegister::DR2) | int(ConfigRegister::DR0), Sps3300 = int(ConfigRegister::DR2) | int(ConfigRegister::DR1)
}
 
enum  ComparatorMode : uint16_t { Traditional = 0, Window = int(ConfigRegister::COMP_MODE) }
 
enum  ComparatorPolarity : uint16_t { ActiveLow = 0, ActiveHigh = int(ConfigRegister::COMP_POL) }
 
enum  ComparatorLatch : uint16_t { Nonlatching = 0, Latching = int(ConfigRegister::COMP_LAT) }
 
enum  ComparatorQueue : uint16_t { OneConversion = 0, TwoConversions = int(ConfigRegister::COMP_QUE0), FourConversions = int(ConfigRegister::COMP_QUE1), Disable = int(ConfigRegister::COMP_QUE1) | int(ConfigRegister::COMP_QUE0) }
 

Public Member Functions

 MODM_FLAGS16 (ConfigRegister)
 
 Ads101x (Data &data, uint8_t address=0x49)
 
modm::ResumableResult< bool > initialize ()
 Call this function before using the device.
 
modm::ResumableResult< bool > isBusy ()
 Determine if the device is currently performing a conversion.
 
modm::ResumableResult< bool > startSingleShotConversion ()
 Start a single conversion with the specified input.
 
modm::ResumableResult< bool > startContinuousConversion (DataRate dataRate=DataRate::Sps1600)
 Start continuous conversions with the specified datarate and input.
 
modm::ResumableResult< bool > startSingleShotConversion (InputMultiplexer input=InputMultiplexer::Input0)
 
modm::ResumableResult< bool > startContinuousConversion (InputMultiplexer input=InputMultiplexer::Input0, DataRate dataRate=DataRate::Sps1600)
 
modm::ResumableResult< bool > readConversionResult ()
 
modm::ResumableResult< bool > enableConversionReadyFunction ()
 
modm::ResumableResult< bool > enableComparator (ComparatorMode mode, ComparatorPolarity polarity, ComparatorLatch latch, ComparatorQueue queue)
 
modm::ResumableResult< bool > setLowThreshold (uint16_t threshold)
 
modm::ResumableResult< bool > setHighThreshold (uint16_t threshold)
 
modm::ResumableResult< bool > setFullScaleRange (FullScaleRange fullScaleRange)
 Set the full scale range by programming the PGA and corresponding LSB size.
 
void attachConfigurationHandler (I2c::ConfigurationHandler handler)
 
modm::ResumableResult< bool > ping ()
 
void setAddress (uint8_t address)
 

Protected Member Functions

modm::ResumableResult< ReturnType > resumable function (...)
 
int8_t getResumableDepth () const
 
bool isResumableRunning () const
 
bool isTransactionRunning ()
 
modm::ResumableResult< bool > runTransaction ()
 Starts our own transaction and waits until finished.
 
bool startRead (uint8_t *buffer, std::size_t size)
 Configures the transaction with a read operation and starts it.
 
bool startTransaction ()
 Starts the transaction with our own transaction object.
 
bool startTransaction (modm::I2cTransaction *transaction)
 Starts the transaction with a seperate transaction object.
 
bool startWrite (const uint8_t *buffer, std::size_t size)
 Configures the transaction with a write operation and starts it.
 
bool startWriteRead (const uint8_t *writeBuffer, std::size_t writeSize, uint8_t *readBuffer, std::size_t readSize)
 Configures the transaction with a write/read operation and starts it.
 
void stopResumable ()
 Force all resumable functions to stop running at the current nesting level.
 
bool wasTransactionSuccessful ()
 

Protected Attributes

I2cWriteReadTransaction transaction
 

Static Protected Attributes

static constexpr float lsbSizeTable []
 

Detailed Description

template<typename I2cMaster>
class modm::ads101x< I2cMaster >

Template Parameters
I2cMasterI2cMaster interface
Author
Jonas Kazem Andersen
Rasmus Kleist Hørlyck Sørensen

Member Function Documentation

template<typename I2cMaster >
modm::ads101x< I2cMaster >::Ads101x ( Data data,
uint8_t  address = 0x49 
)
Parameters
data
address
void modm::I2cDevice< I2cMaster, 10 , I2cWriteReadTransaction >::attachConfigurationHandler ( I2c::ConfigurationHandler  handler)
inheritedinline

Attaches a configuration handler, which is called before a transaction, whenever the configuration has to be changed.

template<typename I2cMaster >
modm::ResumableResult<bool> modm::ads101x< I2cMaster >::enableComparator ( ComparatorMode  mode,
ComparatorPolarity  polarity,
ComparatorLatch  latch,
ComparatorQueue  queue 
)

Enable the comparator

Warning
ADS1014 and ADS1015 only
To use the comparator-function the high threshold must be greater than the low threshold
template<typename I2cMaster >
modm::ResumableResult<bool> modm::ads101x< I2cMaster >::enableConversionReadyFunction ( )

Enable the conversion-ready function of the ALERT/RDY pin

Attention
enabling the conversion-ready function disables the comparator and sets the ComparatorQue value to one conversion
modm::ResumableResult< ReturnType > resumable modm::NestedResumable< 1 >::function (   ...)
inherited

Run the resumable function.

You need to implement this method in you subclass yourself.

Returns
>NestingError if still running, <=NestingError if it has finished.
int8_t modm::NestedResumable< 1 >::getResumableDepth ( ) const
inheritedinline
Returns
the nesting depth in the current resumable function, or -1 if called outside any resumable function
bool modm::NestedResumable< 1 >::isResumableRunning ( ) const
inheritedinline
Returns
true if a resumable function is running at the current nesting level, else false
bool modm::I2cDevice< I2cMaster, 10 , I2cWriteReadTransaction >::isTransactionRunning ( )
inheritedinlineprotected
Returns
true when transaction is busy.
modm::ResumableResult<bool> modm::I2cDevice< I2cMaster, 10 , I2cWriteReadTransaction >::ping ( )
inheritedinline
Return Values
truedevice responds to address
falseno device with address found
template<typename I2cMaster >
modm::ResumableResult<bool> modm::ads101x< I2cMaster >::readConversionResult ( )

Read the last conversion result

Attention
Following power-up, the conversion result remains zero until the first conversion is completed
void modm::I2cDevice< I2cMaster, 10 , I2cWriteReadTransaction >::setAddress ( uint8_t  address)
inheritedinline

Sets a new address of the slave device.

Parameters
addressthe slave address not yet shifted left (address < 128).
template<typename I2cMaster >
modm::ResumableResult<bool> modm::ads101x< I2cMaster >::setHighThreshold ( uint16_t  threshold)
inline

Set the high threshold used by the comparator queue

Warning
ADS1014 and ADS1015 only
The high threshold value must be greater than the low threshold value
Attention
The high threshold value must be updated whenever the PGA settings are changed
template<typename I2cMaster >
modm::ResumableResult<bool> modm::ads101x< I2cMaster >::setLowThreshold ( uint16_t  threshold)
inline

Set the low threshold used by the comparator queue

Warning
ADS1014 and ADS1015 only
The low threshold value must be smaller than the high threshold value
Attention
The high threshold value must be updated whenever the PGA settings are changed
template<typename I2cMaster >
modm::ResumableResult<bool> modm::ads101x< I2cMaster >::startContinuousConversion ( InputMultiplexer  input = InputMultiplexer::Input0,
DataRate  dataRate = DataRate::Sps1600 
)

Start continuous conversions with the specified datarate and input

Warning
ADS1015 only
template<typename I2cMaster >
modm::ResumableResult<bool> modm::ads101x< I2cMaster >::startSingleShotConversion ( InputMultiplexer  input = InputMultiplexer::Input0)

Start a single conversion with the specified input

Warning
ADS1015 only
bool modm::I2cDevice< I2cMaster, 10 , I2cWriteReadTransaction >::wasTransactionSuccessful ( )
inheritedinlineprotected
Returns
true when transaction did not return an error.

Member Data Documentation

template<typename I2cMaster >
constexpr float modm::ads101x< I2cMaster >::lsbSizeTable[]
staticprotectedconstexpr
Initial value:
{
0.003f,
0.002f,
0.001f,
0.0005f,
0.00025f,
0.000125f
}

The documentation for this class was generated from the following file: