MCPcopy Create free account
hub / github.com/RobTillaart/Arduino / readADC

Method readADC

libraries/MCP_ADC/MCP_ADC.cpp:122–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120
121
122int16_t MCP_ADC::readADC(uint8_t channel, bool single)
123{
124 if (channel >= _channels) return 0;
125
126 _count++;
127
128 uint8_t data[3] = { 0,0,0 };
129 uint8_t bytes = buildRequest(channel, single, data);
130
131 digitalWrite(_select, LOW);
132 if (_hwSPI)
133 {
134 mySPI->beginTransaction(_spi_settings);
135 for (uint8_t b = 0; b < bytes; b++)
136 {
137 data[b] = mySPI->transfer(data[b]);
138 }
139 mySPI->endTransaction();
140 }
141 else // Software SPI
142 {
143 for (uint8_t b = 0; b < bytes; b++)
144 {
145 data[b] = swSPI_transfer(data[b]);
146 }
147 }
148 digitalWrite(_select, HIGH);
149
150 if (bytes == 2) return ((256 * data[0] + data[1]) & _maxValue);
151 // data[0]?
152 return ((256 * data[1] + data[2]) & _maxValue);
153}
154
155
156// MSBFIRST

Callers

nothing calls this directly

Calls 1

transferMethod · 0.80

Tested by

no test coverage detected