Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem app epson mbed msp430 pl tests
i2c_utils.cpp
00001 // 00002 // Filename: i2c_utils.cpp 00003 // 00004 // I2C utilities. 00005 // 00006 00007 #include "i2c_utils.h" 00008 00009 uint16_t GetAddressRangeEnd(uint16_t bits) 00010 { 00011 uint16_t end = 0; 00012 switch(bits) 00013 { 00014 case 7: 00015 end = 0x80; 00016 break; 00017 00018 case 10: 00019 end = 0x400; 00020 break; 00021 00022 default: 00023 printf("Bad address range\n"); 00024 } 00025 00026 return end; 00027 } 00028 00029 void I2C_Scan(I2C &i2c, uint16_t bits) 00030 { 00031 printf("Scanning I2C...\n"); 00032 00033 const uint16_t end = GetAddressRangeEnd(bits); 00034 00035 char data; 00036 for(uint16_t address = 0; address < end; address++) 00037 { 00038 if(i2c.read(address << 1, &data, 1) == 0) 00039 printf("Address 0x%02x found\n", address); 00040 } 00041 }
Generated on Tue Jul 12 2022 21:14:34 by
