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
Revision 4:d2fa630c69e1, committed 2018-10-04
- Comitter:
- mcx
- Date:
- Thu Oct 04 06:46:49 2018 +0000
- Parent:
- 3:1c34c302cbfb
- Commit message:
- For 6_Sensors
Changed in this revision
mcp3208.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 1c34c302cbfb -r d2fa630c69e1 mcp3208.cpp --- a/mcp3208.cpp Thu Apr 20 23:02:16 2017 +0000 +++ b/mcp3208.cpp Thu Oct 04 06:46:49 2018 +0000 @@ -9,8 +9,8 @@ _cs(cs), _vref(5.0) { -// _spi.frequency(2000000); - _spi.frequency(8000000); // Out of MCP3208 spec + _spi.frequency(2000000); +// _spi.frequency(8000000); // Out of MCP3208 spec // _spi.format(12,3); _spi.format(16,3); // To accomodate STM32 Nucleo support for only 8-bit and 16-bit words. _cs = 1; @@ -20,9 +20,10 @@ { _cs = 0; // int ret = _spi.write((0x18|ch)<<2); + unsigned long ret = _spi.write((0x18|ch)<<2); // int adb = _spi.write(0); // commented out due to bug with STM32 Nucleo 16-bit words sending another 16-bit word immediately after the 1st one - unsigned long ret = _spi.write((0x18|ch)<<2); - int adb = ret>>20; // Bitshifting by 16-bits to get rid of the initial 1111 1110, another 4-bit to get the 12-bits of data + int adb = _spi.write(0)>>4; // mbed fixed my fix (-_-). +// int adb = ret>>20; // Bitshifting by 16-bits to get rid of the initial 1111 1110, another 4-bit to get the 12-bits of data _cs = 1; return adb; }