Francesco Adamo
/
AD7606_demo
AD7606 Library demo
main.cpp@3:0f818374b9b5, 2015-01-20 (annotated)
- Committer:
- frada
- Date:
- Tue Jan 20 16:07:16 2015 +0000
- Revision:
- 3:0f818374b9b5
- Parent:
- 2:7a0e156f2cc8
-
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
frada | 0:f0b559912391 | 1 | #include "mbed.h" |
frada | 0:f0b559912391 | 2 | #include "ad7606.h" |
frada | 0:f0b559912391 | 3 | |
frada | 0:f0b559912391 | 4 | #ifdef TARGET_KL25Z |
frada | 0:f0b559912391 | 5 | #define MISO PTD3 |
frada | 0:f0b559912391 | 6 | #define SCLK PTD1 |
frada | 0:f0b559912391 | 7 | #define CS PTD0 |
frada | 0:f0b559912391 | 8 | #define CONVST PTD5 |
frada | 3:0f818374b9b5 | 9 | #define BUSY PTA13 |
frada | 3:0f818374b9b5 | 10 | #define RESET PTC9 |
frada | 1:ca30c6307824 | 11 | #elif defined(TARGET_K64F) |
frada | 1:ca30c6307824 | 12 | #define MISO PTD3 |
frada | 1:ca30c6307824 | 13 | #define SCLK PTD1 |
frada | 1:ca30c6307824 | 14 | #define CS PTD0 |
frada | 1:ca30c6307824 | 15 | #define CONVST PTC4 |
frada | 1:ca30c6307824 | 16 | #define BUSY PTA0 |
frada | 1:ca30c6307824 | 17 | #define RESET PTC3 |
frada | 0:f0b559912391 | 18 | #endif |
frada | 0:f0b559912391 | 19 | |
frada | 0:f0b559912391 | 20 | |
frada | 0:f0b559912391 | 21 | Serial pc(USBTX, USBRX); |
frada | 1:ca30c6307824 | 22 | AD7606 ad7606(MISO, SCLK, CS, CONVST, BUSY, RESET, 100000); |
frada | 2:7a0e156f2cc8 | 23 | double aValues[8] = {0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F}; |
frada | 3:0f818374b9b5 | 24 | //int16_t rawValues[8] = {0, 0, 0, 0, 0, 0, 0, 0}; |
frada | 2:7a0e156f2cc8 | 25 | Ticker tick1; |
frada | 2:7a0e156f2cc8 | 26 | DigitalOut greenLED(LED_GREEN); |
frada | 2:7a0e156f2cc8 | 27 | volatile bool timerInterrupt = false; |
frada | 2:7a0e156f2cc8 | 28 | |
frada | 2:7a0e156f2cc8 | 29 | void timInterrupt_ISR() { |
frada | 2:7a0e156f2cc8 | 30 | timerInterrupt = true; |
frada | 2:7a0e156f2cc8 | 31 | greenLED = !greenLED; |
frada | 2:7a0e156f2cc8 | 32 | } |
frada | 0:f0b559912391 | 33 | |
frada | 0:f0b559912391 | 34 | int main() { |
frada | 2:7a0e156f2cc8 | 35 | greenLED = 1; |
frada | 0:f0b559912391 | 36 | pc.baud(115200); |
frada | 0:f0b559912391 | 37 | pc.printf("Hello, World!\r\n"); |
frada | 2:7a0e156f2cc8 | 38 | ad7606.setDR(10.0f); |
frada | 2:7a0e156f2cc8 | 39 | tick1.attach(timInterrupt_ISR, 0.1F); |
frada | 2:7a0e156f2cc8 | 40 | |
frada | 0:f0b559912391 | 41 | while(1) { |
frada | 2:7a0e156f2cc8 | 42 | if (timerInterrupt) { |
frada | 2:7a0e156f2cc8 | 43 | //ad7606.readRAW(rawValues); |
frada | 2:7a0e156f2cc8 | 44 | //pc.printf("%d, %d, %d, %d, %d, %d, %d, %d\r\n", rawValues[0], rawValues[1], rawValues[2], rawValues[3], rawValues[4], rawValues[5], rawValues[6], rawValues[7]); |
frada | 2:7a0e156f2cc8 | 45 | ad7606.readAnalog(aValues); |
frada | 3:0f818374b9b5 | 46 | pc.printf("%.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f\r\n", aValues[0], aValues[1], aValues[2], aValues[3], aValues[4], aValues[5], aValues[6], aValues[7]); |
frada | 2:7a0e156f2cc8 | 47 | timerInterrupt = false; |
frada | 2:7a0e156f2cc8 | 48 | } |
frada | 0:f0b559912391 | 49 | } |
frada | 1:ca30c6307824 | 50 | } |