A library to interface to the MCP3208 SPI-based ADC from Microchip. This chip provides eight analogue inputs, providing converted 12-bit values via SPI.

Dependents:   Nucleo_MCP3208_Test Nucleo_MCP3208_Ticker_Test BBMv2_eps ref_BBMv2_eps ... more

Revision:
3:e7de500b1f2d
Parent:
2:93009a423b45
--- a/mcp3208.cpp	Tue May 24 14:06:57 2011 +0000
+++ b/mcp3208.cpp	Sat Jun 11 21:19:56 2011 +0000
@@ -8,20 +8,22 @@
 
 MCP3208::MCP3208(SPI bus, PinName cs)
     : m_cs(cs), m_bus(bus)
-{}
+{
+    deselect();
+}
 
 MCP3208::~MCP3208() {}
 
 
 void MCP3208::select() {m_cs = 0;}
-void MCP3208::deselect() {m_cs = 1;}
+void MCP3208::deselect() {m_cs = 1; wait_us(1);}
 
 
 float MCP3208::read_input(int channel)
 {
     int command_high = START_BIT | MODE_SINGLE | ((channel & 0x04) >> 2);
     int command_low = (channel & 0x03) << 6;
-
+    
     select();
     
     // Odd writing requirements, see the datasheet for details
@@ -33,7 +35,7 @@
     
     int conv_result = (high_byte << 8) | low_byte;
     
-    return float(conv_result) / 4096;
+    return ((float)conv_result) / 4096;
 }