NetBurner 3.5.6
PDF Version
I2C Address Scan

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

  1. Complete Address Scan: Tests all 127 possible I2C addresses
  2. Device Detection: Identifies responding devices by ACK signal
  3. Dual Address Format: Reports both 7-bit and 8-bit address formats
  4. Interactive Operation: Allows repeated scans on user command
  5. Error Handling: Proper I2C bus reset on communication failures

Program Flow

  1. Initialization
    • Initialize network stack and diagnostics
    • Initialize I2C module with NetBurner as address 0x08
    • Display initialization status
  2. 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
  3. 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**

  • 7-bit addr: 0x50 (binary: 1010000)
  • 8-bit addr byte: 0xA0 (binary: 10100000) - with write bit (0)
  • Read address byte: 0xA1 (binary: 10100001) - with read bit (1)

    Status Codes:**

  • 0: Successful ACK received
  • **>= I2C_TIMEOUT**: No response or communication error

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

// Change I2C module (if multiple modules available)
#define I2C_MODULE_NUM 1 // Use I2C1 instead of I2C0
// Change NetBurner slave address
const uint8_t slaveAddr = 0x10; // Different slave address

Hardware Setup

I2C Bus Requirements

Pull-up Resistors:**

  • SDA and SCL: 4.7k to VCC (typically 3.3V)
  • Strong pull-ups: 2.2k for high-speed or long cables
  • Weak pull-ups: 10k for low-power applications

    Bus Termination:**

  • Only required at physical ends of long bus runs
  • Not needed for short connections between devices

Platform-Specific Connections

MOD5441X:**

  • Check module datasheet for I2C pin locations
  • Typically available on J2 connector
  • May require external pull-up resistors

    NANO54415:**

  • I2C pins available on development board connectors
  • Check for integrated pull-up resistors on board
  • Verify voltage levels (3.3V logic)

Troubleshooting

Common Issues

  1. 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
  2. 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
  3. Bus lockup or communication errors:
  4. Intermittent device detection:
    • Check power supply stability
    • Verify pull-up resistor values
    • Check for electromagnetic interference

Debug Techniques

Bus Status Monitoring:**

// Add status checking
uint8_t busStatus = GetI2CBusStatus(I2C_MODULE_NUM);
iprintf("I2C Bus Status: 0x%02X\n", busStatus);

Detailed Error Reporting:**

// Enhanced error information
if (I2CStat >= I2C_TIMEOUT) {
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:**

// Test communication with known good device
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

// Scan specific address range
void ScanAddressRange(uint8_t startAddr, uint8_t endAddr) {
for(int addr = startAddr; addr <= endAddr; addr++) {
// Perform scan as in main function
}
}

Device Identification

// Try to identify device type by reading manufacturer ID
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

// Monitor for device additions/removals
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

// Test basic communication with found devices
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

// Store found device addresses for later use
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

// Provide web-based scan results
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