Francesco Adamo
/
AD7730_demo
Demo program for the AD7730 library
main.cpp@0:929781c1530d, 2015-03-17 (annotated)
- Committer:
- frada
- Date:
- Tue Mar 17 17:25:15 2015 +0000
- Revision:
- 0:929781c1530d
Demo for the AD7730 library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
frada | 0:929781c1530d | 1 | #include "mbed.h" |
frada | 0:929781c1530d | 2 | #include "AD7730.h" |
frada | 0:929781c1530d | 3 | |
frada | 0:929781c1530d | 4 | #ifdef TARGET_K64F |
frada | 0:929781c1530d | 5 | #define SPI_SCK PTD1 |
frada | 0:929781c1530d | 6 | #define SPI_MOSI PTD2 |
frada | 0:929781c1530d | 7 | #define SPI_MISO PTD3 |
frada | 0:929781c1530d | 8 | #define SPI_CS PTD0 |
frada | 0:929781c1530d | 9 | #define READY PTC4 |
frada | 0:929781c1530d | 10 | #define I2C_SDA PTE25 |
frada | 0:929781c1530d | 11 | #define I2C_SCL PTE24 |
frada | 0:929781c1530d | 12 | #elif defined(TARGET_KL25Z) |
frada | 0:929781c1530d | 13 | #define SPI_SCK PTD1 |
frada | 0:929781c1530d | 14 | #define SPI_MOSI PTD2 |
frada | 0:929781c1530d | 15 | #define SPI_MISO PTD3 |
frada | 0:929781c1530d | 16 | #define SPI_CS PTD0 |
frada | 0:929781c1530d | 17 | #define READY PTD5 |
frada | 0:929781c1530d | 18 | #define I2C_SDA PTE0 |
frada | 0:929781c1530d | 19 | #define I2C_SCL PTE1 |
frada | 0:929781c1530d | 20 | #endif |
frada | 0:929781c1530d | 21 | |
frada | 0:929781c1530d | 22 | DigitalOut greenLED(LED_GREEN); |
frada | 0:929781c1530d | 23 | DigitalOut redLED(LED_RED); |
frada | 0:929781c1530d | 24 | DigitalOut blueLED(LED_BLUE); |
frada | 0:929781c1530d | 25 | Serial pc(USBTX, USBRX); |
frada | 0:929781c1530d | 26 | Ticker tick1; |
frada | 0:929781c1530d | 27 | volatile bool timerInterrupt = false; |
frada | 0:929781c1530d | 28 | |
frada | 0:929781c1530d | 29 | |
frada | 0:929781c1530d | 30 | AD7730 ad7730(SPI_MOSI, SPI_MISO, SPI_SCK, READY, SPI_CS); |
frada | 0:929781c1530d | 31 | |
frada | 0:929781c1530d | 32 | void timerISR() { |
frada | 0:929781c1530d | 33 | timerInterrupt = true; |
frada | 0:929781c1530d | 34 | greenLED = !greenLED; |
frada | 0:929781c1530d | 35 | } |
frada | 0:929781c1530d | 36 | |
frada | 0:929781c1530d | 37 | int main() { |
frada | 0:929781c1530d | 38 | pc.baud(115200); |
frada | 0:929781c1530d | 39 | greenLED = 1; |
frada | 0:929781c1530d | 40 | redLED = 1; |
frada | 0:929781c1530d | 41 | blueLED = 1; |
frada | 0:929781c1530d | 42 | ad7730.initialize(); |
frada | 0:929781c1530d | 43 | tick1.attach(timerISR, 0.02F); |
frada | 0:929781c1530d | 44 | |
frada | 0:929781c1530d | 45 | while(1) { |
frada | 0:929781c1530d | 46 | if (timerInterrupt) { |
frada | 0:929781c1530d | 47 | pc.printf("%d\r\n", ad7730.read(true)); |
frada | 0:929781c1530d | 48 | timerInterrupt = false; |
frada | 0:929781c1530d | 49 | } |
frada | 0:929781c1530d | 50 | } |
frada | 0:929781c1530d | 51 | } |