A template class supporting MCP3XXX ADC SPI chips.
More...
#include <MCP3XXX.h>
template<uint8_t NumBits, uint8_t NumChannels, uint32_t MaxSPIClockSpeed, uint8_t SPITransferLength = 3>
class MCP3XXX_< NumBits, NumChannels, MaxSPIClockSpeed, SPITransferLength >
A template class supporting MCP3XXX ADC SPI chips.
- Template Parameters
-
NumBits | Number of ADC bits. |
NumChannels | Number of input channels. |
MaxSPIClockSpeed | Maximum SPI communication speed rate in Hz. |
SPITransferLength | The number of bytes transferred over SPI. |
◆ anonymous enum
template<uint8_t NumBits, uint8_t NumChannels, uint32_t MaxSPIClockSpeed, uint8_t SPITransferLength = 3>
Enumerator |
---|
ADC_ERROR_INVALID_CHANNEL | ADC error value.
|
ADC_UNSUPPORTED_CONFIGURATION | ADC error value.
|
NUM_BITS | Number of ADC bits.
|
BIT_MASK | A bit mask based on the number of bits.
|
NUM_CHANNELS | Number of input channels.
|
MAX_SPI_CLOCK_SPEED | Maximum SPI communication speed rate in Hz.
|
SPI_TRANSFER_LEGNTH | The number of bytes transferred over SPI.
|
◆ analogRead()
template<uint8_t NumBits, uint8_t NumChannels, uint32_t MaxSPIClockSpeed, uint8_t SPITransferLength = 3>
uint32_t MCP3XXX_< NumBits, NumChannels, MaxSPIClockSpeed, SPITransferLength >::analogRead |
( |
uint8_t |
channel | ) |
const |
|
inline |
Read the analog value.
Reads a single-ended analog value using the given channel.
- Parameters
-
channel | The channel (channel < NUM_CHANNELS) to read. |
- Returns
- values [0, MAX_VALUE) on success or an error code on failure.
◆ analogReadDifferential()
template<uint8_t NumBits, uint8_t NumChannels, uint32_t MaxSPIClockSpeed, uint8_t SPITransferLength = 3>
uint32_t MCP3XXX_< NumBits, NumChannels, MaxSPIClockSpeed, SPITransferLength >::analogReadDifferential |
( |
uint8_t |
inPositiveChannel | ) |
const |
|
inline |
Read a differential analog value by specifying the IN+ channel.
Consecutive channel pairs can be differentially read. For instance, if inPositiveChannel == 0, inNegativeChannel will be 1. If inPositiveChannel == 1, then inNegativeChannel will be 0. Thus if inPositiveChannel is odd, inNegativeChannel == (inPositiveChannel - 1). if inPositiveChannel is even, inNegativeChannel == (inPositiveChannel + 1).
- Parameters
-
inPositiveChannel | The channel that should be input positive. |
- Returns
- Differential values. See the data sheet for information on how to interpret these return values.
◆ begin() [1/2]
template<uint8_t NumBits, uint8_t NumChannels, uint32_t MaxSPIClockSpeed, uint8_t SPITransferLength = 3>
void MCP3XXX_< NumBits, NumChannels, MaxSPIClockSpeed, SPITransferLength >::begin |
( |
uint8_t |
csPin = SS | ) |
|
|
inline |
Set up the ADC using default hardware SPI pins.
Hardware SPI pins vary based on the board being used. These default pins are represented by the constants SS, MOSI, MISO and SCK.
- See also
- https://www.arduino.cc/en/Reference/SPI
- Parameters
-
csPin | Chip Select Pin. Default value is SS. |
◆ begin() [2/2]
template<uint8_t NumBits, uint8_t NumChannels, uint32_t MaxSPIClockSpeed, uint8_t SPITransferLength = 3>
void MCP3XXX_< NumBits, NumChannels, MaxSPIClockSpeed, SPITransferLength >::begin |
( |
uint8_t |
csPin, |
|
|
uint8_t |
mosiPin, |
|
|
uint8_t |
misoPin, |
|
|
uint8_t |
sckPin |
|
) |
| |
|
inline |
Set up the ADC using custom software SPI pins.
This method forces the SPI to be accesed via software methods rather than hardware SPI. This is true, even if the default hardware SPI pins are used.
- Parameters
-
csPin | Chip Select Pin. |
mosiPin | MOSI pin. |
misoPin | MISO pin. |
sckPin | Clock pin. |
◆ numBits()
template<uint8_t NumBits, uint8_t NumChannels, uint32_t MaxSPIClockSpeed, uint8_t SPITransferLength = 3>
size_t MCP3XXX_< NumBits, NumChannels, MaxSPIClockSpeed, SPITransferLength >::numBits |
( |
| ) |
const |
|
inline |
- Returns
- the number of ADC bits.
◆ numChannels()
template<uint8_t NumBits, uint8_t NumChannels, uint32_t MaxSPIClockSpeed, uint8_t SPITransferLength = 3>
size_t MCP3XXX_< NumBits, NumChannels, MaxSPIClockSpeed, SPITransferLength >::numChannels |
( |
| ) |
const |
|
inline |
- Returns
- the number of ADC channels.
The documentation for this class was generated from the following file:
- /home/travis/build/bakercp/MCP3XXX/src/MCP3XXX.h