|
PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
|
Go to the documentation of this file.
94 const bool alwaysSetSPIMode =
false)
96 m_alwaysSetMode(alwaysSetSPIMode),
97 m_dataWidth(static_cast<uint8_t>(partNumber)) {
114 this->m_alwaysSetMode = alwaysSetMode;
128 options = START |
static_cast<int8_t
>(SINGLE_ENDED) |
static_cast<int8_t
>(channel);
133 if (this->m_alwaysSetMode) {
134 this->m_spi->
set_mode(MCP3xxx::SPI_MODE);
139 this->m_spi->
shift_out(OPTION_WIDTH, (uint32_t) options);
140 dat = (uint16_t) this->m_spi->
shift_in(this->m_dataWidth);
159 options = START |
static_cast<int8_t
>(DIFFERENTIAL) |
static_cast<int8_t
>(channels);
164 if (this->m_alwaysSetMode) {
170 this->m_spi->
shift_out(OPTION_WIDTH, (uint32_t) options);
171 dat = (uint16_t) this->m_spi->
shift_in(this->m_dataWidth);
179 static const SPI::BitMode SPI_BITMODE = SPI::BitMode::MSB_FIRST;
181 static const uint8_t START = BIT_4;
182 static const uint8_t SINGLE_ENDED = BIT_3;
183 static const uint8_t DIFFERENTIAL = 0;
184 static const uint8_t OPTION_WIDTH = 7;
189 bool m_alwaysSetMode;
void set_dir_out() const
Set the port for output.
void set_bit_mode(const BitMode bitmode)
Set the bitmode of SPI communication.
void set_mask(const Pin::Mask mask)
uint16_t read_diff(const MCP3xxx::ChannelDiff channels)
Read a specific axis's data in differential mode.
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...
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.
Utility class to handle general purpose I/O pins.
uint16_t read(const MCP3xxx::Channel channel)
Read a specific channel's data in single-ended mode.
void shift_out(uint8_t bits, uint32_t value) const
Send a value out to a peripheral device.
void set() const
Set selected output port high (set all pins to 1)
MCP3xxx-series ADC driver using SPI communication for the Parallax Propeller. Compatible with the fol...
void set_mode(const Mode mode)
Set the mode of SPI communication.
BitMode
Determine if data is communicated with the LSB or MSB sent/received first.
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.
Generic definitions and functions for the Parallax Propeller.
void clear() const
Clear selected output port (set it to 0)
Mode
Descriptor for SPI signal as defined by Motorola modes.