Dan Allen
/
MAX11410_test
test program to power up two MAX11410 ADCs and check the inputs of ADC1. Uses MAX11410 library.
main.cpp@4:c194858fe0c6, 2016-11-18 (annotated)
- Committer:
- smartsystemdesign
- Date:
- Fri Nov 18 20:25:57 2016 +0000
- Revision:
- 4:c194858fe0c6
- Parent:
- 3:42120705a9bd
- Child:
- 5:d7b803aa9079
Updated comments and added 8 bit address for use with I2C read and write commands.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon | 0:4f78cdfc99de | 1 | // I2CU - Search for devices on an I2C bus |
simon | 0:4f78cdfc99de | 2 | // Copyright (c) 2009, sford |
simon | 0:4f78cdfc99de | 3 | // Released under the MIT License: http://mbed.org/license/mit |
simon | 0:4f78cdfc99de | 4 | // |
simon | 0:4f78cdfc99de | 5 | // Goes through each device address, seeing if it gets a response |
simon | 0:4f78cdfc99de | 6 | // - for every device if finds, it prints the 8-bit address |
simon | 0:4f78cdfc99de | 7 | // - if the program hangs, the bus isn't working (check pull-ups etc) |
simon | 0:4f78cdfc99de | 8 | // - if it doesn't find your device, check power/bus wiring etc |
smartsystemdesign | 3:42120705a9bd | 9 | // |
smartsystemdesign | 3:42120705a9bd | 10 | // - Note: if you plug / unplug devices try cycling power |
smartsystemdesign | 2:39ba9beabf3c | 11 | |
simon | 0:4f78cdfc99de | 12 | #include "mbed.h" |
simon | 0:4f78cdfc99de | 13 | |
smartsystemdesign | 1:1cdd12a4efb2 | 14 | I2C i2c(I2C_SDA, I2C_SCL); // sda, scl |
smartsystemdesign | 2:39ba9beabf3c | 15 | Ticker repeatTicker; |
simon | 0:4f78cdfc99de | 16 | |
smartsystemdesign | 2:39ba9beabf3c | 17 | void repeat() |
smartsystemdesign | 2:39ba9beabf3c | 18 | { |
simon | 0:4f78cdfc99de | 19 | printf("I2CU! Searching for I2C devices...\n"); |
simon | 0:4f78cdfc99de | 20 | |
simon | 0:4f78cdfc99de | 21 | int count = 0; |
simon | 0:4f78cdfc99de | 22 | for (int address=0; address<256; address+=2) { |
smartsystemdesign | 2:39ba9beabf3c | 23 | bool temp = i2c.write(address, NULL, 0); // 0 if successful, otherwise non-zero |
smartsystemdesign | 2:39ba9beabf3c | 24 | if (!temp && (address >> 1) != 0) { // not interested in address 0 |
smartsystemdesign | 4:c194858fe0c6 | 25 | printf(" - I2C device found at address 0x%02X (7 bit - Arduino) or 0x%02X (8 bit - mbed)\n", address >> 1, address); |
simon | 0:4f78cdfc99de | 26 | count++; |
simon | 0:4f78cdfc99de | 27 | } |
simon | 0:4f78cdfc99de | 28 | } |
smartsystemdesign | 2:39ba9beabf3c | 29 | printf("%d device(s) found\n", count); |
simon | 0:4f78cdfc99de | 30 | } |
smartsystemdesign | 2:39ba9beabf3c | 31 | |
smartsystemdesign | 2:39ba9beabf3c | 32 | int main() |
smartsystemdesign | 2:39ba9beabf3c | 33 | { |
smartsystemdesign | 2:39ba9beabf3c | 34 | repeatTicker.attach(&repeat, 2.0); |
smartsystemdesign | 2:39ba9beabf3c | 35 | } |