A simple library for controlling an MCP4241 digital potentiometer

Revision:
1:179b46a0165e
Parent:
0:f547d674e543
Child:
2:54e9d9ddc350
diff -r f547d674e543 -r 179b46a0165e DigiPot.cpp
--- a/DigiPot.cpp	Fri Sep 13 11:09:41 2013 +0000
+++ b/DigiPot.cpp	Sat Jan 25 21:05:15 2014 +0000
@@ -1,13 +1,14 @@
 #include "DigiPot.h"
+#include "math.h"
 
 #define POT_0 0x00
 #define POT_1 0x10
 
 DigiPot::DigiPot(PinName miso, PinName mosi, PinName clk, PinName cs) {
     chsel = new DigitalOut(cs);
-    spi = new SPI(mosi, miso, clk);// mosi, miso, sclk
-    spi->format(8,0); // 8 bits , mode 0
-    spi->frequency(1000000); // Default SPI frequency. ( 250kHz maximum for read commands).
+    spi = new SPI(mosi, miso, clk);
+    spi->format(8,0); 
+    spi->frequency(1000000);
     level = 0x00;
 }
 
@@ -24,6 +25,7 @@
     spi->write(POT_0);
     spi->write(level);
     *chsel = 1;
+    wait_us(2);
     *chsel = 0;
     spi->write(POT_1);
     spi->write(level);