I2C Wire Scan Application
Overview
This application scans the I2C bus for connected devices and displays their addresses using the Wire interface. It's a diagnostic utility that helps verify hardware connections and understand I2C device addressing.
Features
- Scans all valid I2C addresses (0x01 to 0x7F)
- Reports found device addresses in hexadecimal format
- Includes web server functionality for remote monitoring
- Provides network diagnostics capabilities
How It Works
The application performs the following operations:
- System Initialization: Initializes the network stack and starts a web server on port 80
- Network Setup: Waits for an active network connection
- I2C Scanning: Sends ping requests to each address in the I2C address space
- Device Detection: When a device responds with an acknowledgment (ACK), its address is recorded
- Results Display: Outputs all found device addresses to the console
I2C Address Scanning Process
The scan covers addresses 1 through 127 (0x01 to 0x7F) in the 7-bit I2C address space. For each address, the application:
- Sends a request using
Wire.ping(address)
- Waits for an acknowledgment from the device
- Records the address if a response is received
Output Format
For example, the application outputs scan results in the following format:
Doing scan
Scan done found 3 devices
I2C Peripheral Class.
Definition i2c.h:213
Where:
- Device addresses are displayed in hexadecimal format
- Multiple addresses are comma-separated
- Total count of found devices is reported
Use Cases
This utility is particularly helpful for:
- Hardware Verification: Confirming that I2C devices are properly connected and powered
- Address Discovery: Identifying the actual addresses of connected I2C devices
- Troubleshooting: Diagnosing I2C communication issues
- Documentation: Understanding device addressing schemes in datasheets
Technical Notes
Address Format
Some I2C device datasheets include the read/write bit as part of the address specification, while others do not. This scanner reports the base 7-bit address without the read/write bit.
Address Range
- Valid Range: 0x01 to 0x7F (1 to 127 decimal)
- Reserved Addresses: 0x00 and addresses above 0x7F are not scanned as they are reserved or invalid
Network Features
The application includes network capabilities:
- Web server running on port 80
- System diagnostics enabled
- Network connection monitoring
Dependencies
- NNDK (NetBurner Network Development Kit)
- Wire library for I2C communication
- System libraries for network and timing functions
Building and Running
- Compile the application using the NNDK toolchain
- Flash to your NetBurner device
- Connect to the device console to view scan results
- Optionally access the web interface for remote monitoring
Example Output
Web Application:
I2C Wire Scan
NNDK Revision: [version]
Doing scan
Scan done found 3 devices
This example shows three I2C devices found at addresses 0x20, 0x3C, and 0x50.
Troubleshooting
If no devices are found:
- Check I2C wiring (SDA, SCL, power, ground)
- Verify pull-up resistors on SDA and SCL lines
- Confirm device power supply voltages
- Check for proper ground connections
- Verify device addresses in datasheets
File Structure
main.cpp: Main application source code
- Web interface files (auto-generated by NNDK)