test program to power up two MAX11410 ADCs and check the inputs of ADC1. Uses MAX11410 library.

Dependencies:   MAX11410 mbed

Committer:
smartsystemdesign
Date:
Wed Nov 09 01:31:22 2016 +0000
Revision:
2:39ba9beabf3c
Parent:
1:1cdd12a4efb2
Child:
3:42120705a9bd
Changed I2C scanner to behave like the Arduino I2C scanner.  Also, made it ignore address 0.

Who changed what in which revision?

UserRevisionLine numberNew 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 2:39ba9beabf3c 9
simon 0:4f78cdfc99de 10 #include "mbed.h"
simon 0:4f78cdfc99de 11
smartsystemdesign 1:1cdd12a4efb2 12 I2C i2c(I2C_SDA, I2C_SCL); // sda, scl
smartsystemdesign 2:39ba9beabf3c 13 Ticker repeatTicker;
simon 0:4f78cdfc99de 14
smartsystemdesign 2:39ba9beabf3c 15 void repeat()
smartsystemdesign 2:39ba9beabf3c 16 {
simon 0:4f78cdfc99de 17 printf("I2CU! Searching for I2C devices...\n");
simon 0:4f78cdfc99de 18
simon 0:4f78cdfc99de 19 int count = 0;
simon 0:4f78cdfc99de 20 for (int address=0; address<256; address+=2) {
smartsystemdesign 2:39ba9beabf3c 21 bool temp = i2c.write(address, NULL, 0); // 0 if successful, otherwise non-zero
smartsystemdesign 2:39ba9beabf3c 22 if (!temp && (address >> 1) != 0) { // not interested in address 0
smartsystemdesign 1:1cdd12a4efb2 23 printf(" - I2C device found at address 0x%02X\n", address >> 1);
simon 0:4f78cdfc99de 24 count++;
simon 0:4f78cdfc99de 25 }
simon 0:4f78cdfc99de 26 }
smartsystemdesign 2:39ba9beabf3c 27 printf("%d device(s) found\n", count);
simon 0:4f78cdfc99de 28 }
smartsystemdesign 2:39ba9beabf3c 29
smartsystemdesign 2:39ba9beabf3c 30 int main()
smartsystemdesign 2:39ba9beabf3c 31 {
smartsystemdesign 2:39ba9beabf3c 32 repeatTicker.attach(&repeat, 2.0);
smartsystemdesign 2:39ba9beabf3c 33 }