Simon Ford
/
I2CU
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 // I2CU - Search for devices on an I2C bus 00002 // Copyright (c) 2009, sford 00003 // Released under the MIT License: http://mbed.org/license/mit 00004 // 00005 // Goes through each device address, seeing if it gets a response 00006 // - for every device if finds, it prints the 8-bit address 00007 // - if the program hangs, the bus isn't working (check pull-ups etc) 00008 // - if it doesn't find your device, check power/bus wiring etc 00009 00010 #include "mbed.h" 00011 00012 I2C i2c(p9, p10); // sda, scl 00013 00014 int main() { 00015 printf("I2CU! Searching for I2C devices...\n"); 00016 00017 int count = 0; 00018 for (int address=0; address<256; address+=2) { 00019 if (!i2c.write(address, NULL, 0)) { // 0 returned is ok 00020 printf(" - I2C device found at address 0x%02X\n", address); 00021 count++; 00022 } 00023 } 00024 printf("%d devices found\n", count); 00025 }
Generated on Tue Jul 12 2022 11:02:40 by 1.7.2