12bit 8ch ADC with SPI interface for STM32 Nucleo to support 16-bit words. SPI speed bumped up to 8MHz
Fork of MCP3208_Y by
Diff: mcp3208.cpp
- Revision:
- 1:0876e83ba21b
- Parent:
- 0:2300f3b42cdb
- Child:
- 3:1c34c302cbfb
diff -r 2300f3b42cdb -r 0876e83ba21b mcp3208.cpp --- a/mcp3208.cpp Wed Oct 24 03:41:03 2012 +0000 +++ b/mcp3208.cpp Wed Oct 24 05:52:21 2012 +0000 @@ -7,20 +7,19 @@ MCP3208::MCP3208(PinName mosi, PinName miso, PinName clk, PinName cs) : _spi(mosi,miso,clk), _cs(cs), - vref(5.0) + _vref(5.0) { _spi.frequency(2000000); - _spi.format(14,3); - _cs = 1; + _spi.format(12,3); + _cs = 1; } int MCP3208::binary(int ch) { _cs = 0; - int ret = _spi.write(0x18|ch); + int ret = _spi.write((0x18|ch)<<2); int adb = _spi.write(0); - int dum = _spi.write(0); _cs = 1; return adb; } @@ -28,6 +27,6 @@ float MCP3208::volt(int ch) { - return vref * binary(ch) / 4095; + return _vref * binary(ch) / 4095; }