Nol.A SDK Library 26.11.2
For IoT System Software Development
Loading...
Searching...
No Matches
MCP391x Class Reference

SPI driver for MCP391x multi-channel ADCs. Call begin() before reads. I2C operation and the declared streaming entry points are not implemented. More...

#include <MCP391x.hpp>

Public Types

enum  Chip_t {
  MCP3918 , MCP3910 , MCP3919 , MCP3912 ,
  MCP3913 , MCP3914
}
 ADC model and channel count; only SPI transport is supported. More...
enum  Pre_t { PRE_DIV1 = 0ul , PRE_DIV2 = 1ul , PRE_DIV4 = 2ul , PRE_DIV8 = 3ul }
 ADC master-clock prescaler settings. More...
enum  Osr_t {
  OSR_32 = 0ul , OSR_64 = 1ul , OSR_128 = 2ul , OSR_256 = 3ul ,
  OSR_512 = 4ul , OSR_1024 = 5ul , OSR_2048 = 6ul , OSR_4096 = 7ul
}
 ADC oversampling ratio settings. More...

Public Member Functions

 MCP391x (Chip_t type, SPI &spi, int8_t cs, int8_t dr, bool drHiZ=true, int8_t reset=-1)
 Bind an ADC model, SPI bus, and GPIO wiring.
bool begin (bool useCrystal=false, Pre_t pre=PRE_DIV1, Osr_t osr=OSR_256)
 Configure GPIO and ADC prescaler/oversampling after checking the security register.
void streamStart (unsigned reg)
 Streaming entry point declared without an implementation; do not call.
void streamEnd ()
 Streaming entry point declared without an implementation; do not call.
uint32_t readChannel (unsigned channel, unsigned len)
 Read raw channel bytes synchronously without sign conversion.

Detailed Description

SPI driver for MCP391x multi-channel ADCs. Call begin() before reads. I2C operation and the declared streaming entry points are not implemented.

Member Enumeration Documentation

◆ Chip_t

ADC model and channel count; only SPI transport is supported.

28 { MCP3918, // 1 channel (SPI/TWI)
29 MCP3910, // 2 channels (SPI/TWI)
30 MCP3919, // 3 channels (SPI/TWI)
31 MCP3912, // 4 channels (SPI)
32 MCP3913, // 6 channels (SPI)
33 MCP3914, // 8 channels (SPI)
34 } Chip_t;
Chip_t
ADC model and channel count; only SPI transport is supported.
Definition MCP391x.hpp:28

◆ Osr_t

ADC oversampling ratio settings.

66 { OSR_32 = 0ul,
67 OSR_64 = 1ul,
68 OSR_128 = 2ul,
69 OSR_256 = 3ul,
70 OSR_512 = 4ul,
71 OSR_1024 = 5ul,
72 OSR_2048 = 6ul,
73 OSR_4096 = 7ul } Osr_t;
Osr_t
ADC oversampling ratio settings.
Definition MCP391x.hpp:66

◆ Pre_t

ADC master-clock prescaler settings.

58 { PRE_DIV1 = 0ul,
59 PRE_DIV2 = 1ul,
60 PRE_DIV4 = 2ul,
61 PRE_DIV8 = 3ul } Pre_t;
Pre_t
ADC master-clock prescaler settings.
Definition MCP391x.hpp:58

Constructor & Destructor Documentation

◆ MCP391x()

MCP391x::MCP391x ( Chip_t type,
SPI & spi,
int8_t cs,
int8_t dr,
bool drHiZ = true,
int8_t reset = -1 )
inline

Bind an ADC model, SPI bus, and GPIO wiring.

Parameters
typeADC model.
spiBus that outlives the driver.
csActive-low chip-select pin.
drData-ready input pin.
drHiZStored data-ready mode flag; currently not applied to hardware.
resetOptional reset pin; -1 omits hardware reset.
46 : spi(spi), PIN_RESET(reset), PIN_CS(cs), PIN_DR(dr), drHiZ(drHiZ),
47 NumChannels((type == MCP3918) ? 1 :
48 (type == MCP3910) ? 2 :
49 (type == MCP3919) ? 3 :
50 (type == MCP3912) ? 4 :
51 (type == MCP3913) ? 6 :
52 (type == MCP3914) ? 8 : 0) {
53 }

Member Function Documentation

◆ begin()

bool MCP391x::begin ( bool useCrystal = false,
Pre_t pre = PRE_DIV1,
Osr_t osr = OSR_256 )

Configure GPIO and ADC prescaler/oversampling after checking the security register.

Parameters
useCrystalTrue selects the internal crystal oscillator; false leaves the clock setting unchanged.
preMaster-clock prescaler.
osrOversampling ratio.
Returns
True if the security register is 0xA50000 and configuration was attempted.

◆ readChannel()

uint32_t MCP391x::readChannel ( unsigned channel,
unsigned len )

Read raw channel bytes synchronously without sign conversion.

Parameters
channelZero-based channel index valid for the selected model.
lenTransfer width in bytes: 2, 3, or 4, matching device configuration.
Returns
Raw bits assembled into a uint32_t; arguments are not validated.

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