PropWare
C++ objects and CMake build system for Parallax Propeller
|
MCP3004/MCP3008 ADC driver using SPI communication for the Parallax Propeller. More...
#include <mcp3000.h>
Public Types | |
enum | Channel { CHANNEL_0, CHANNEL_1, CHANNEL_2, CHANNEL_3, CHANNEL_4, CHANNEL_5, CHANNEL_6, CHANNEL_7 } |
enum | ChannelDiff { DIFF_0_1, DIFF_1_0, DIFF_2_3, DIFF_3_2, DIFF_4_5, DIFF_5_4, DIFF_6_7, DIFF_7_6 } |
enum | PartNumber { MCP300x = 11, MCP320x = 13, MCP330x = 14 } |
Public Member Functions | |
MCP3000 (SPI *spi, const PropWare::Pin::Mask cs, MCP3000::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 MCP3000::Channel channel) |
Read a specific channel's data in single-ended mode. More... | |
uint16_t | read_diff (const MCP3000::ChannelDiff channels) |
Read a specific axis's data in differential mode. More... | |
MCP3004/MCP3008 ADC driver using SPI communication for the Parallax Propeller.
PropWare::MCP3000::MCP3000 | ( | SPI * | spi, |
const PropWare::Pin::Mask | cs, | ||
MCP3000::PartNumber | partNumber, | ||
const bool | alwaysSetSPIMode = false |
||
) |
Construction requires an instance of the SPI module; the SPI module does not need to be started.
[in] | *spi | Constructed SPI module |
[in] | cs | Pin mask used for chip select |
[in] | partNumber | Determine bit-width of the ADC channels |
[in] | alwaysSetSPIMode | Should 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 83 of file mcp3000.h.
void PropWare::MCP3000::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.
[in] | alwaysSetMode | For any non-zero value, the SPI modes will always be set before a read or write routine |
uint16_t PropWare::MCP3000::read | ( | const MCP3000::Channel | channel | ) |
Read a specific channel's data in single-ended mode.
[in] | channel | One 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 |
Definition at line 114 of file mcp3000.h.
uint16_t PropWare::MCP3000::read_diff | ( | const MCP3000::ChannelDiff | channels | ) |
Read a specific axis's data in differential mode.
[in] | channels | One 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) |
Definition at line 145 of file mcp3000.h.