84 const bool alwaysSetSPIMode =
false)
86 m_alwaysSetMode(alwaysSetSPIMode),
87 m_dataWidth(partNumber) {
104 this->m_alwaysSetMode = alwaysSetMode;
118 options = START | SINGLE_ENDED | channel;
123 if (this->m_alwaysSetMode) {
124 this->m_spi->
set_mode(MCP3000::SPI_MODE);
129 this->m_spi->
shift_out(OPTION_WIDTH, (uint32_t) options);
130 dat = (uint16_t) this->m_spi->
shift_in(this->m_dataWidth);
149 options = START | DIFFERENTIAL | channels;
154 if (this->m_alwaysSetMode) {
160 this->m_spi->
shift_out(OPTION_WIDTH, (uint32_t) options);
161 dat = (uint16_t) this->m_spi->
shift_in(this->m_dataWidth);
171 static const uint8_t START = BIT_4;
172 static const uint8_t SINGLE_ENDED = BIT_3;
173 static const uint8_t DIFFERENTIAL = 0;
174 static const uint8_t OPTION_WIDTH = 7;
179 bool m_alwaysSetMode;
void set_mask(const PropWare::Port::Mask mask)
Utility class to handle general purpose I/O pins.
void set_dir(const PropWare::Port::Dir direction) const
Set port as either input or output.
void clear() const
Clear selected output port (set it to 0)
Generic definitions and functions for the Parallax Propeller.
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 wh...
MCP3004/MCP3008 ADC driver using SPI communication for the Parallax Propeller.
void shift_out(uint8_t bits, uint32_t value) const
Send a value out to a peripheral device.
Mode
Descriptor for SPI signal as defined by Motorola modes.
uint16_t read(const MCP3000::Channel channel)
Read a specific channel's data in single-ended mode.
void set_bit_mode(const BitMode bitmode)
Set the bitmode of SPI communication.
BitMode
Determine if data is communicated with the LSB or MSB sent/received first.
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...
void set() const
Set selected output port high (set all pins to 1)
uint16_t read_diff(const MCP3000::ChannelDiff channels)
Read a specific axis's data in differential mode.
void set_mode(const Mode mode)
Set the mode of SPI communication.
SPI serial communications library; Core functionality comes from a dedicated assembly cog...
uint32_t shift_in(const unsigned int bits) const
Read a value from the MISO line.