PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Public Types | Public Member Functions | List of all members
PropWare::MCP3xxx Class Reference

MCP3xxx-series ADC driver using SPI communication for the Parallax Propeller. Compatible with the following devices: More...

#include <PropWare/sensor/analog/mcp3xxx.h>

Public Types

enum  Channel {
  Channel::CHANNEL_0,
  Channel::CHANNEL_1,
  Channel::CHANNEL_2,
  Channel::CHANNEL_3,
  Channel::CHANNEL_4,
  Channel::CHANNEL_5,
  Channel::CHANNEL_6,
  Channel::CHANNEL_7
}
 
enum  ChannelDiff {
  ChannelDiff::DIFF_0_1,
  ChannelDiff::DIFF_1_0,
  ChannelDiff::DIFF_2_3,
  ChannelDiff::DIFF_3_2,
  ChannelDiff::DIFF_4_5,
  ChannelDiff::DIFF_5_4,
  ChannelDiff::DIFF_6_7,
  ChannelDiff::DIFF_7_6
}
 
enum  PartNumber {
  PartNumber::MCP300x = 11,
  PartNumber::MCP320x = 13,
  PartNumber::MCP330x = 14
}
 

Public Member Functions

 MCP3xxx (SPI &spi, const PropWare::Pin::Mask cs, MCP3xxx::PartNumber partNumber, const bool alwaysSetSPIMode=false)
 Construction requires an instance of the SPI module; the SPI module does not need to be started. More...
 
void always_set_spi_mode (const bool alwaysSetMode)
 Choose whether to always set the SPI mode and bitmode before reading or writing to the ADC; Useful when multiple devices are connected to the SPI bus. More...
 
uint16_t read (const MCP3xxx::Channel channel)
 Read a specific channel's data in single-ended mode. More...
 
uint16_t read_diff (const MCP3xxx::ChannelDiff channels)
 Read a specific axis's data in differential mode. More...
 

Detailed Description

MCP3xxx-series ADC driver using SPI communication for the Parallax Propeller. Compatible with the following devices:

Note
MCP3xxx chips uses SPI mode 2 and shifts data MSB first
Examples
MCP3xxx_Demo.cpp.

Definition at line 49 of file mcp3xxx.h.

Member Enumeration Documentation

◆ Channel

Single-ended channels

Enumerator
CHANNEL_0 

Channel 0

CHANNEL_1 

Channel 1

CHANNEL_2 

Channel 2

CHANNEL_3 

Channel 3

CHANNEL_4 

Channel 4 (MCP3008 only)

CHANNEL_5 

Channel 5 (MCP3008 only)

CHANNEL_6 

Channel 6 (MCP3008 only)

CHANNEL_7 

Channel 7 (MCP3008 only)

Definition at line 52 of file mcp3xxx.h.

◆ ChannelDiff

Pseudo-differential pair channels

Enumerator
DIFF_0_1 

CH0+, CH1-

DIFF_1_0 

CH1+, CH0-

DIFF_2_3 

CH2+, CH3-

DIFF_3_2 

CH3+, CH2-

DIFF_4_5 

CH4+, CH5- (MCP3008 only)

DIFF_5_4 

CH5+, CH4- (MCP3008 only)

DIFF_6_7 

CH6+, CH7- (MCP3008 only)

DIFF_7_6 

CH7+, CH6- (MCP3008 only)

Definition at line 64 of file mcp3xxx.h.

◆ PartNumber

The part number determines the width of the data transfer

Enumerator
MCP300x 

10-bit ADC, includes MCP3002, MCP3004 and MCP3008

MCP320x 

12-bit ADC, includes MCP3202, MCP3204 and MCP3208

MCP330x 

13-bit ADC, includes MCP3302, MCP3304 and MCP3308

Definition at line 76 of file mcp3xxx.h.

Constructor & Destructor Documentation

◆ MCP3xxx()

PropWare::MCP3xxx::MCP3xxx ( SPI spi,
const PropWare::Pin::Mask  cs,
MCP3xxx::PartNumber  partNumber,
const bool  alwaysSetSPIMode = false 
)

Construction requires an instance of the SPI module; the SPI module does not need to be started.

Parameters
[in]spiConstructed SPI module
[in]csPin mask used for chip select
[in]partNumberDetermine bit-width of the ADC channels
[in]alwaysSetSPIModeShould every invocation of read or read_diff set the SPI mode. Setting to true is only necessary when multiple devices are connected to the same SPI bus and use different SPI modes

Definition at line 93 of file mcp3xxx.h.

Member Function Documentation

◆ always_set_spi_mode()

void PropWare::MCP3xxx::always_set_spi_mode ( const bool  alwaysSetMode)

Choose whether to always set the SPI mode and bitmode before reading or writing to the ADC; Useful when multiple devices are connected to the SPI bus.

Parameters
[in]alwaysSetModeFor any non-zero value, the SPI modes will always be set before a read or write routine

Definition at line 113 of file mcp3xxx.h.

◆ read()

uint16_t PropWare::MCP3xxx::read ( const MCP3xxx::Channel  channel)

Read a specific channel's data in single-ended mode.

Parameters
[in]channelOne of MCP_CHANNEL_x, where x is a number 0 through 3 (or 0 through 7 for the MCP3008); Selects the channel to be read
Returns
Returns 0 upon success, error code otherwise

Definition at line 124 of file mcp3xxx.h.

+ Here is the call graph for this function:

◆ read_diff()

uint16_t PropWare::MCP3xxx::read_diff ( const MCP3xxx::ChannelDiff  channels)

Read a specific axis's data in differential mode.

Parameters
[in]channelsOne of DIFF_x_y, where x is a number 0 through 3 (or 0 through 7 for the MCP3008) and y is x + (x + 1)%2 (See above defined enum or datasheet for details)
Returns
Returns 0 upon success, error code otherwise

Definition at line 155 of file mcp3xxx.h.

+ Here is the call graph for this function:

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