![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
MCP3208 with SWSPI to support variable SPI bit lengths
Dependencies: MCP3208_STM32_16bit_HAX mbed
Fork of MCP3208_LPC1114 by
Revision 11:c42ced58244d, committed 2018-10-04
- Comitter:
- mcx
- Date:
- Thu Oct 04 06:47:20 2018 +0000
- Parent:
- 10:a22ee39e2282
- Commit message:
- First commit
Changed in this revision
diff -r a22ee39e2282 -r c42ced58244d MCP3208.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MCP3208.lib Thu Oct 04 06:47:20 2018 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/mcx/code/MCP3208_STM32_16bit_HAX/#d2fa630c69e1
diff -r a22ee39e2282 -r c42ced58244d MCP3208_SWSPI.lib --- a/MCP3208_SWSPI.lib Thu Apr 06 19:31:47 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://developer.mbed.org/users/mcx/code/MCP3208_SWSPI/#08c7702773b6
diff -r a22ee39e2282 -r c42ced58244d SWSPI.lib --- a/SWSPI.lib Thu Apr 06 19:31:47 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/users/davervw/code/SWSPI/#6a500a08c7fd
diff -r a22ee39e2282 -r c42ced58244d main.cpp --- a/main.cpp Thu Apr 06 19:31:47 2017 +0000 +++ b/main.cpp Thu Oct 04 06:47:20 2018 +0000 @@ -1,56 +1,19 @@ #include "mbed.h" #include "mcp3208.h" -//MCP3208 input1(PA_7, PA_6, PA_5, PA_4); //MCP3208(PinName mosi, PinName miso, PinName clk, PinName cs) -MCP3208 input1(PB_5, PB_4, PB_3, PA_11); -//MCP3208 input1(p5, p6, p7, p8); +MCP3208 input1(PA_7, PA_6, PA_5, PB_0); //MCP3208(PinName mosi, PinName miso, PinName clk, PinName cs) -//Serial pc(dp16,dp15); -// Serial pc(p9,p10); - Serial pc(USBTX, USBRX); +Serial pc(USBTX, USBRX); +//Serial pc(PA_2, PA_3); Ticker datalog; -Timer t; -char datastr0[5]; -char datastr1[5]; -char datastr2[5]; -char datastr3[5]; -char datastr4[5]; -char datastr5[5]; - -char datastr6[5]; - -int data0; -int data1; -int data2; -int data3; -int data4; -int data5; - -// Credit: Erik Olieman -// http://developer.mbed.org/questions/5149/Serial-port-on-LPC1114-is-slow/ -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'; -} +int data0 = 0; +int data1 = 0; +int data2 = 0; +int data3 = 0; +int data4 = 0; +int data5 = 0; bool tickerActivated = false; @@ -61,14 +24,11 @@ int main() { - int tt = 0; - t.start(); - pc.baud(921600); pc.printf("Working!!\n\r"); datalog.attach_us(&log_data,1000); // 1000us = 1ms - + while(1) { data0 = input1.binary(0); data1 = input1.binary(1); @@ -76,28 +36,10 @@ data3 = input1.binary(3); data4 = input1.binary(4); data5 = input1.binary(5); - - 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)); - - // 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); pc.printf("%04d,%04d,%04d,%04d,%04d,%04d\n\r",data0,data1,data2,data3,data4,data5); -// pc.printf("%d\n\r",SPI1->DR); -// pc.printf("%d\n\r",input1.binary(0)); } }
diff -r a22ee39e2282 -r c42ced58244d mbed.bld --- a/mbed.bld Thu Apr 06 19:31:47 2017 +0000 +++ b/mbed.bld Thu Oct 04 06:47:20 2018 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/0ab6a29f35bf \ No newline at end of file +https://os.mbed.com/users/mbed_official/code/mbed/builds/7130f322cb7e \ No newline at end of file