I2C Address Scanner
Overview
This NetBurner application scans all possible I2C device addresses (1-127) on the I2C bus and reports which addresses respond with an ACK signal. The application is useful for discovering I2C devices connected to the bus and identifying their addresses for communication.
Supported Platforms
- MOD5441X - I2C0 default module
- NANO54415 - I2C0 default module
- MCF5441X OEM - Configurable I2C module
Hardware Requirements
- NetBurner module with I2C capability
- I2C devices connected to the bus for testing
- Pull-up resistors on SDA and SCL lines (typically 4.7k)
- Serial console for viewing scan results
I2C Bus Configuration
Default Settings
- I2C Module: I2C0 (DEFAULT_I2C_MODULE)
- NetBurner Address: 0x08 (7-bit slave address)
- Scan Range: 1 to 127 (0x01 to 0x7F)
- Operation Mode: Master mode scanning
Address Format
The application reports addresses in both formats:
- 7-bit Address: Standard I2C addressing format (0x50)
- 8-bit Address Byte: Full address byte sent on bus (0xA0 for write, 0xA1 for read)
Application Functionality
Main Features
- Complete Address Scan: Tests all 127 possible I2C addresses
- Device Detection: Identifies responding devices by ACK signal
- Dual Address Format: Reports both 7-bit and 8-bit address formats
- Interactive Operation: Allows repeated scans on user command
- Error Handling: Proper I2C bus reset on communication failures
Program Flow
- Initialization
- Initialize network stack and diagnostics
- Initialize I2C module with NetBurner as address 0x08
- Display initialization status
- Address Scanning
- Loop through addresses 1-127 (0x01-0x7F)
- Send write start condition to each address
- Check for ACK response within timeout period
- Report responding devices with address information
- Interactive Mode
- Wait for user input to repeat scan
- Display total number of responding devices
- Continuous operation until reset
Scan Process Flow
Start -> Address 1 -> Send Start+Write -> ACK? -> Report Device -> Next Address
^ |
| v
+-- Address 127 <-
Bus Reset <-- NACK/Timeout
@ Bus
Non-multiplexed bus mode (write only). Separate address and data buses. Reads are performed as AD-Mux...
Key Components
Core Functions
I2C Operations:**
Output Format
Typical Scan Results
Initializing address: 0x08 ... Complete
Scanning peripheral I2C0...
Found device, 7-bit addr: 0x08, 8-bit addr byte: 0x10,
I2C Status: 0
Found device, 7-bit addr: 0x50, 8-bit addr byte: 0xA0,
I2C Status: 0
Found device, 7-bit addr: 0x68, 8-bit addr byte: 0xD0,
I2C Status: 0
Scan complete
3 addresses responded
Type any key to repeat
I2C Peripheral Class.
Definition i2c.h:213
Address Information Explained
Example: 7-bit address 0x50**
Device Address Ranges
Common I2C Device Addresses
EEPROMs (24Cxx series):**
- Base addresses: 0x50-0x57 (depending on A0-A2 pins)
8-bit address bytes: 0xA0-0xAE (write), 0xA1-0xAF (read)
Real-Time Clocks:**
- DS1307: 0x68 (8-bit: 0xD0 write, 0xD1 read)
DS3231: 0x68 (8-bit: 0xD0 write, 0xD1 read)
Temperature Sensors:**
- LM75: 0x48-0x4F (8-bit: 0x90-0x9E write)
DS18B20: 0x18-0x1F (when used with I2C bridge)
Accelerometers:**
- ADXL345: 0x1D or 0x53 (depending on ALT ADDRESS pin)
- MMA7455: 0x1D (8-bit: 0x3A write, 0x3B read)
Multiple Device Responses
Some devices may respond to multiple addresses due to "don't care" address bits:
Found device, 7-bit addr: 0x50, 8-bit addr byte: 0xA0,
I2C Status: 0
Found device, 7-bit addr: 0x51, 8-bit addr byte: 0xA2,
I2C Status: 0
Found device, 7-bit addr: 0x52, 8-bit addr byte: 0xA4,
I2C Status: 0
This typically indicates a single EEPROM with configurable address bits.
Building and Deployment
Configuration Options
#define I2C_MODULE_NUM 1
const uint8_t slaveAddr = 0x10;
Hardware Setup
I2C Bus Requirements
Pull-up Resistors:**
Platform-Specific Connections
MOD5441X:**
Troubleshooting
Common Issues
- No devices found (0 addresses responded):
- Check pull-up resistors on SDA and SCL
- Verify I2C device power connections
- Confirm correct pin connections
- Check for bus conflicts or shorts
- Only NetBurner address responds (0x08):
- Indicates I2C module is working but no external devices detected
- Check device connections and power
- Verify devices are properly addressed
- Bus lockup or communication errors:
- Intermittent device detection:
- Check power supply stability
- Verify pull-up resistor values
- Check for electromagnetic interference
Debug Techniques
Bus Status Monitoring:**
uint8_t busStatus = GetI2CBusStatus(I2C_MODULE_NUM);
iprintf("I2C Bus Status: 0x%02X\n", busStatus);
Detailed Error Reporting:**
iprintf("Address 0x%02X: Timeout/Error %d\n", addr, I2CStat);
}
#define I2C_TIMEOUT
A timeout occurred while trying communicate on I2C bus.
Definition multichanneli2c.h:82
Signal Quality Testing:**
uint8_t testData = 0x00;
int result = I2CWriteRead(I2C_MODULE_NUM, knownAddress, &testData, 1, NULL, 0);
iprintf("Test communication result: %d\n", result);
Advanced Usage
Selective Scanning
void ScanAddressRange(uint8_t startAddr, uint8_t endAddr) {
for(int addr = startAddr; addr <= endAddr; addr++) {
}
}
Device Identification
void IdentifyDevice(uint8_t address) {
uint8_t deviceID[3];
if(I2CRead(I2C_MODULE_NUM, address, deviceID, sizeof(deviceID)) == 0) {
iprintf("Device ID: %02X %02X %02X\n",
deviceID[0], deviceID[1], deviceID[2]);
}
}
Continuous Monitoring
void ContinuousMonitor() {
static uint8_t lastDeviceCount = 0;
uint8_t currentCount = scanAddressesI2C();
if(currentCount != lastDeviceCount) {
iprintf("Device count changed: %d -> %d\n",
lastDeviceCount, currentCount);
lastDeviceCount = currentCount;
}
}
Application Extensions
Device Communication Testing
void TestDeviceCommunication(uint8_t address) {
uint8_t testByte = 0x00;
uint8_t readBack;
if(I2CWriteRead(I2C_MODULE_NUM, address, &testByte, 1, &readBack, 1) == 0) {
iprintf("Device 0x%02X communication OK\n", address);
}
}
Configuration Storage
uint8_t foundDevices[128];
uint8_t deviceCount = 0;
void StoreFoundDevices() {
deviceCount = 0;
for(int addr = 1; addr < 0x80; addr++) {
if(TestDevicePresence(addr)) {
foundDevices[deviceCount++] = addr;
}
}
}
Web Interface
void HandleI2CScanRequest(int httpFd) {
SendHttpResponse(httpFd, "200 OK");
WriteHttp(httpFd, "<html><body>");
WriteHttp(httpFd, "<h1>I2C Device Scan</h1>");
int deviceCount = scanAddressesI2C();
WriteHttpf(httpFd, "<p>Found %d devices:</p>", deviceCount);
WriteHttp(httpFd, "</body></html>");
}
Performance Considerations
Scan Speed Optimization
- Reduce timeout values for faster scanning
- Skip known empty address ranges
- Use interrupt-driven I2C for better responsiveness
Memory Usage
- Minimal RAM usage for address scanning
- Consider buffering results for web interfaces
- Stack usage is minimal for this application
Related Examples
- I2C Communication: Device-specific communication examples
- EEPROM Examples: Reading/writing I2C memory devices
- Sensor Examples: I2C temperature, accelerometer, etc.
- Multi-Channel I2C: Using multiple I2C modules simultaneously
- I2C Slave Examples: NetBurner as I2C slave device