FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
Loading...
Searching...
No Matches
devices::mcp3x0x::MCP3x0x< CS, CHANNEL_, MASK, RSHIFT, TYPE_ > Class Template Reference

Generic class to support (almost) any chip of the SPI-based MicroChip ADC chips family (MCP3001-2-4-8, MCP3201-2-4-8, MCP3301-2-4). More...

#include <fastarduino/devices/mcp3x0x.h>

Inheritance diagram for devices::mcp3x0x::MCP3x0x< CS, CHANNEL_, MASK, RSHIFT, TYPE_ >:
Collaboration diagram for devices::mcp3x0x::MCP3x0x< CS, CHANNEL_, MASK, RSHIFT, TYPE_ >:

Public Types

using CHANNEL = CHANNEL_
 The enum class type defining all possible analog input channels handled by the device. More...
 
using TYPE = TYPE_
 The analog output type for this device, either uint16_t or int16_t. More...
 

Public Member Functions

 MCP3x0x ()=default
 Create a new device driver for an MCP chip.
 
TYPE read_channel (CHANNEL channel)
 Read an analog channel from this device. More...
 

Additional Inherited Members

- Protected Member Functions inherited from spi::SPIDevice< CS, spi::ChipSelect::ACTIVE_LOW, spi::compute_clockrate(3 '600 '000UL), spi::Mode::MODE_0, spi::DataOrder::MSB_FIRST >
 SPIDevice () INLINE=default
 Create a new SPIDevice; this sets up the CS pin for later use during transfers.
 
void start_transfer ()
 Start an SPI transfer to this device. More...
 
void end_transfer () INLINE
 End the current SPI ransfer tot hsi device. More...
 
- Protected Member Functions inherited from spi::AbstractSPIDevice
 AbstractSPIDevice (const AbstractSPIDevice &)=delete
 
AbstractSPIDeviceoperator= (const AbstractSPIDevice &)=delete
 
uint8_t transfer (uint8_t data)
 Transfer one byte to the currently selected SPI slave device through MOSI pin, and get the byte returned by the device through MISO pin. More...
 
void transfer (uint8_t *data, uint16_t size)
 Transfer an array of payload data to the currently selected SPI slave device through MOSI pin, and get all data bytes simultaneously received from that device through MISO pin. More...
 
void transfer (const uint8_t *data, uint16_t size)
 Transfer an array of payload data to the currently selected SPI slave device through MOSI pin; any data bytes simultaneously received from that device through MISO pin are lost. More...
 
void transfer (uint8_t *data, uint16_t size, uint8_t sent)
 Transfer the provided byte sent several times to the currently selected SPI slave device through MOSI pin, and get all data bytes simultaneously received from that device through MISO pin. More...
 
void transfer (uint16_t size, uint8_t sent)
 Transfer the provided byte sent several times to the currently selected SPI slave device through MOSI pin; any data bytes simultaneously received from that device through MISO pin are lost. More...
 

Detailed Description

template<board::DigitalPin CS, typename CHANNEL_, uint16_t MASK, uint8_t RSHIFT, typename TYPE_ = uint16_t>
class devices::mcp3x0x::MCP3x0x< CS, CHANNEL_, MASK, RSHIFT, TYPE_ >

Generic class to support (almost) any chip of the SPI-based MicroChip ADC chips family (MCP3001-2-4-8, MCP3201-2-4-8, MCP3301-2-4).

You would never directly use this class in your programs but rather use class aliases with the proper template parameter values.

Template Parameters
CSthe output pin used for Chip Selection of the MCP chip on the SPI bus.
CHANNEL_an enum class type defining all possible analog input channels handled by the device; this is used as an argument in read_channel(); it must be castable to a uint8_t or uint16_t that will be used as the first or two first bytes in the transmission to the chip.
MASKthe mask to use on the 2 bytes received from the chip to get the analog value read; this mask shall match the number of bits returned by the chip.
RSHIFTthe number of bits to shift right on the analog value read by the chip; some MCP devices actually return values that are not right-aligned; for these devices you need a non-0 RSHIFT.
TYPE_the analog output type, typically uint16_t, or int16_t for some devices.
See also
MCP3008
MCP3208
MCP3304

Definition at line 67 of file mcp3x0x.h.

Member Typedef Documentation

◆ CHANNEL

template<board::DigitalPin CS, typename CHANNEL_ , uint16_t MASK, uint8_t RSHIFT, typename TYPE_ = uint16_t>
using devices::mcp3x0x::MCP3x0x< CS, CHANNEL_, MASK, RSHIFT, TYPE_ >::CHANNEL = CHANNEL_

The enum class type defining all possible analog input channels handled by the device.

See also
read_channel()

Definition at line 83 of file mcp3x0x.h.

◆ TYPE

template<board::DigitalPin CS, typename CHANNEL_ , uint16_t MASK, uint8_t RSHIFT, typename TYPE_ = uint16_t>
using devices::mcp3x0x::MCP3x0x< CS, CHANNEL_, MASK, RSHIFT, TYPE_ >::TYPE = TYPE_

The analog output type for this device, either uint16_t or int16_t.

See also
read_channel()

Definition at line 89 of file mcp3x0x.h.

Member Function Documentation

◆ read_channel()

template<board::DigitalPin CS, typename CHANNEL_ , uint16_t MASK, uint8_t RSHIFT, typename TYPE_ = uint16_t>
TYPE devices::mcp3x0x::MCP3x0x< CS, CHANNEL_, MASK, RSHIFT, TYPE_ >::read_channel ( CHANNEL  channel)
inline

Read an analog channel from this device.

Parameters
channelthe channel to read from this device
Returns
the analog value; the bits precision depends on each device (typically 10, 12 or 13 bits).

Definition at line 102 of file mcp3x0x.h.


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