MCP3208 with SWSPI to support variable SPI bit lengths

Dependencies:   MCP3208_STM32_16bit_HAX mbed

Fork of MCP3208_LPC1114 by Michael Chuah

Revision:
0:6c41db68c857
Child:
1:cf620653d56f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Feb 19 00:03:51 2015 +0000
@@ -0,0 +1,75 @@
+#include "mbed.h"
+#include "mcp3208.h"
+// #include "BufferedSerial.h"
+
+// #include <string>
+// using namespace std;
+
+MCP3208 input1(dp2, dp1, dp6, dp9); //MCP3208(PinName mosi, PinName miso, PinName clk, PinName cs)
+// MCP3208 input1(p5, p6, p7, p8);
+
+Serial pc(dp16,dp15); //(USBTX, USBRX)
+// Serial pc(p9,p10);
+
+Ticker datalog;
+
+char datastr0[5];
+char datastr1[5];
+char datastr2[5];
+char datastr3[5];
+char datastr4[5];
+char datastr5[5];
+
+// Credit: Erik Olieman
+void intToString(char *buffer, int value)
+{
+    int temp;
+    temp = value / 1000;
+    buffer[0] = temp + '0';
+    value = value - temp * 1000;
+
+    temp = value / 100;
+    buffer[1] = temp + '0';
+    value = value - temp * 100;
+
+    temp = value / 10;
+    buffer[2] = temp + '0';
+    value = value - temp * 10;
+
+    temp = value / 1;
+    buffer[3] = temp + '0';
+    value = value - temp * 1;
+
+    buffer[4] = '\0';
+}
+
+bool tickerActivated = false;
+
+void log_data()
+{
+    tickerActivated = true;
+}
+
+int main()
+{
+    pc.baud(921600);
+    pc.printf("Working!!\n\r");
+
+    datalog.attach_us(&log_data,1000); // 1000us = 1ms
+
+    intToString(datastr0,input1.binary(0));
+    intToString(datastr1,input1.binary(1));
+    intToString(datastr2,input1.binary(2));
+    intToString(datastr3,input1.binary(3));
+    intToString(datastr4,input1.binary(4));
+    intToString(datastr5,input1.binary(5));
+
+    while(1) {
+        if(tickerActivated == true) {
+            tickerActivated = false;
+            pc.printf("%s,%s,%s,%s,%s,%s\n\r",datastr0,datastr1,datastr2,datastr3,datastr4,datastr5);
+        }
+    }
+}
+
+