![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Code to use read data from MCP3208 ADC via SPI and output it via serial using the LPC1114.
Diff: main.cpp
- Revision:
- 4:1267e8fa59a3
- Parent:
- 1:cf620653d56f
- Child:
- 5:9568cfe486dd
diff -r 1701a3738c54 -r 1267e8fa59a3 main.cpp --- a/main.cpp Thu Nov 12 22:12:34 2015 +0000 +++ b/main.cpp Wed Nov 16 23:47:52 2016 +0000 @@ -9,6 +9,7 @@ // Serial pc(USBTX, USBRX); Ticker datalog; +Timer t; char datastr0[5]; char datastr1[5]; @@ -17,6 +18,8 @@ char datastr4[5]; char datastr5[5]; +char datastr6[5]; + // Credit: Erik Olieman // http://developer.mbed.org/questions/5149/Serial-port-on-LPC1114-is-slow/ void intToString(char *buffer, int value) @@ -50,10 +53,13 @@ int main() { - pc.baud(921600); + int tt = 0; + t.start(); + + pc.baud(9600); pc.printf("Working!!\n\r"); - datalog.attach_us(&log_data,1000); // 1000us = 1ms + datalog.attach_us(&log_data,1000000); // 1000us = 1ms while(1) { intToString(datastr0,input1.binary(0)); @@ -63,10 +69,19 @@ intToString(datastr4,input1.binary(4)); intToString(datastr5,input1.binary(5)); + // Timing methods to verify 1 ms loop time / 1 kHz update speed + // tt = t.read_ms(); + tt++; + if(tt>=10000) { + tt = 0; + } + intToString(datastr6,tt); + if(tickerActivated == true) { tickerActivated = false; pc.printf("%s,%s,%s,%s,%s,%s\n\r",datastr0,datastr1,datastr2,datastr3,datastr4,datastr5); } + } }