MCP3208 with SWSPI to support variable SPI bit lengths
Dependencies: MCP3208_STM32_16bit_HAX mbed
Fork of MCP3208_LPC1114 by
main.cpp@11:c42ced58244d, 2018-10-04 (annotated)
- Committer:
- mcx
- Date:
- Thu Oct 04 06:47:20 2018 +0000
- Revision:
- 11:c42ced58244d
- Parent:
- 10:a22ee39e2282
First commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mcx | 0:6c41db68c857 | 1 | #include "mbed.h" |
mcx | 0:6c41db68c857 | 2 | #include "mcp3208.h" |
mcx | 0:6c41db68c857 | 3 | |
mcx | 11:c42ced58244d | 4 | MCP3208 input1(PA_7, PA_6, PA_5, PB_0); //MCP3208(PinName mosi, PinName miso, PinName clk, PinName cs) |
mcx | 0:6c41db68c857 | 5 | |
mcx | 11:c42ced58244d | 6 | Serial pc(USBTX, USBRX); |
mcx | 11:c42ced58244d | 7 | //Serial pc(PA_2, PA_3); |
mcx | 0:6c41db68c857 | 8 | |
mcx | 0:6c41db68c857 | 9 | Ticker datalog; |
mcx | 0:6c41db68c857 | 10 | |
mcx | 11:c42ced58244d | 11 | int data0 = 0; |
mcx | 11:c42ced58244d | 12 | int data1 = 0; |
mcx | 11:c42ced58244d | 13 | int data2 = 0; |
mcx | 11:c42ced58244d | 14 | int data3 = 0; |
mcx | 11:c42ced58244d | 15 | int data4 = 0; |
mcx | 11:c42ced58244d | 16 | int data5 = 0; |
mcx | 0:6c41db68c857 | 17 | |
mcx | 0:6c41db68c857 | 18 | bool tickerActivated = false; |
mcx | 0:6c41db68c857 | 19 | |
mcx | 0:6c41db68c857 | 20 | void log_data() |
mcx | 0:6c41db68c857 | 21 | { |
mcx | 0:6c41db68c857 | 22 | tickerActivated = true; |
mcx | 0:6c41db68c857 | 23 | } |
mcx | 0:6c41db68c857 | 24 | |
mcx | 0:6c41db68c857 | 25 | int main() |
mcx | 0:6c41db68c857 | 26 | { |
mcx | 7:983886b6ada9 | 27 | pc.baud(921600); |
mcx | 0:6c41db68c857 | 28 | pc.printf("Working!!\n\r"); |
mcx | 0:6c41db68c857 | 29 | |
mcx | 7:983886b6ada9 | 30 | datalog.attach_us(&log_data,1000); // 1000us = 1ms |
mcx | 11:c42ced58244d | 31 | |
mcx | 1:cf620653d56f | 32 | while(1) { |
mcx | 8:4c941f8c6d73 | 33 | data0 = input1.binary(0); |
mcx | 8:4c941f8c6d73 | 34 | data1 = input1.binary(1); |
mcx | 8:4c941f8c6d73 | 35 | data2 = input1.binary(2); |
mcx | 8:4c941f8c6d73 | 36 | data3 = input1.binary(3); |
mcx | 8:4c941f8c6d73 | 37 | data4 = input1.binary(4); |
mcx | 8:4c941f8c6d73 | 38 | data5 = input1.binary(5); |
mcx | 4:1267e8fa59a3 | 39 | |
mcx | 0:6c41db68c857 | 40 | if(tickerActivated == true) { |
mcx | 0:6c41db68c857 | 41 | tickerActivated = false; |
mcx | 10:a22ee39e2282 | 42 | pc.printf("%04d,%04d,%04d,%04d,%04d,%04d\n\r",data0,data1,data2,data3,data4,data5); |
mcx | 0:6c41db68c857 | 43 | } |
mcx | 4:1267e8fa59a3 | 44 | |
mcx | 0:6c41db68c857 | 45 | } |
mcx | 0:6c41db68c857 | 46 | } |
mcx | 0:6c41db68c857 | 47 | |
mcx | 0:6c41db68c857 | 48 |