PicKit I2C Serial Demo Board Example
Overview
This example demonstrates comprehensive I2C communication using a Microchip PicKit Serial I2C Demo Board. The application interfaces with five different I2C peripherals, showcasing various data types and communication patterns including EEPROM storage, temperature sensing, GPIO expansion, analog-to-digital conversion, and digital-to-analog conversion.
Supported Platforms
- MOD5441X - MOD54415 development module
- NANO54415 - Nano54415 development module
Both platforms use the MCF54415 processor with identical I2C functionality.
Hardware Requirements
Microchip PicKit Serial I2C Demo Board
This example requires the Microchip PicKit Serial I2C Demo Board containing the following I2C peripherals:
| Component | Type | Description | I2C Address |
| 24LC0B | EEPROM | 2Kbit (256 x 8) memory | 0x50 |
| MCP9800 | Temperature Sensor | Digital thermometer | 0x49 |
| MCP23008 | GPIO Expander | 8-bit I/O expander with LEDs | 0x20 |
| TC1321 | DAC | 10-bit Digital-to-Analog Converter | 0x48 |
| MCP3221 | ADC | 12-bit Analog-to-Digital Converter | 0x4D |
I2C Connection Requirements
MOD5441X Platform
NetBurner Pin PicKit Demo Board
----------- -----------------
J2.39 (SDA) --- SDA
J2.42 (SCL) --- SCL
J2.1 (GND) --- GND
J2.2 (VCC) --- VCC (3.3V)
NANO54415 Platform
NetBurner Pin PicKit Demo Board
----------- -----------------
P1.29 (SDA) --- SDA
P1.48 (SCL) --- SCL
J2.1 (GND) --- GND
P1.47 (VCC) --- VCC (3.3V)
Power Requirements
- Voltage: 3.3V DC
- Current: Typical 50mA (depending on LED usage)
Features
Multi-Peripheral I2C Communication
- Simultaneous device support - Communicates with 5 different I2C devices
- Address management - Proper 7-bit I2C addressing scheme
- Error handling - Comprehensive status code checking and reporting
- Device initialization - Automatic setup and configuration
EEPROM Operations (24LC0B)
- 256-byte capacity - Full memory read/write operations
- Page writing - Efficient 8-byte page write cycles
- Write completion polling - Automatic write cycle detection
- Memory display - Hex dump formatting for data visualization
Temperature Monitoring (MCP9800)
- 12-bit resolution - High precision temperature measurement
- Celsius and Fahrenheit - Dual unit temperature display
- 2's complement format - Proper signed temperature handling
- Configuration register - Device setup and calibration
GPIO Expansion (MCP23008)
- LED control - 8-bit LED pattern display
- Sequential patterns - Rotating LED animation
- Direction control - Input/output pin configuration
- Real-time updates - Continuous LED pattern cycling
Digital-to-Analog Conversion (TC1321)
- 10-bit resolution - 0-1023 digital range
- 2.5V reference - 0-2.5VDC analog output
- User input - Interactive DAC value entry
- Voltage calculation - Real-time output voltage display
Analog-to-Digital Conversion (MCP3221)
- 12-bit resolution - 4096-step analog measurement
- 3.3V reference - 0-3.3VDC input range
- Real-time sampling - Continuous analog input monitoring
- Voltage display - Converted voltage readout
I2C Address Configuration
Address Format Explanation
I2C addresses can be confusing due to different documentation conventions. This example uses the standard NetBurner 7-bit addressing scheme:
I2C Address Byte Format: [A6 A5 A4 A3 A2 A1 A0 R/W]
|<---- 7-bit Address ---->|
Where:
- A6-A0: 7-bit device address
- R/W: Read/Write bit (0=Write, 1=Read)
I2C Peripheral Class.
Definition i2c.h:213
Address Translation Table
| Device | Datasheet Address | NetBurner 7-bit Address | Binary Address |
| 24LC0B EEPROM | 0xA0 | 0x50 | 0101 0000 |
| MCP9800 Temp | 0x92 | 0x49 | 0100 1001 |
| MCP23008 GPIO | 0x40 | 0x20 | 0010 0000 |
| TC1321 DAC | 0x90 | 0x48 | 0100 1000 |
| MCP3221 ADC | 0x9A | 0x4D | 0100 1101 |
Address Calculation
#define I2C_DEVICE_ADDRESS (DATASHEET_ADDR >> 1)
#define I2C_ADC_ADDRESS (0x9A >> 1)
Application Menu System
Interactive Commands
The application provides a menu-driven interface for testing all I2C devices:
Main Menu:
1. Erase EEPROM
2. Read EEPROM
3. Write incrementing sequence to EEPROM
A. Read ADC
D. DAC Test
T. Read Temperature Sensor
Automatic Operations
- LED Animation - Continuously cycles through LED patterns every 500ms
- Status Monitoring - Real-time I2C bus status reporting
- Error Detection - Automatic error code display and description
Usage Instructions
Setup Process
- Prepare hardware
- Connect PicKit I2C Demo Board to NetBurner module using I2C connections above
- Verify power connections (3.3V, GND)
- Ensure proper pull-up resistors on SDA/SCL lines (usually provided on demo board)
- Build and deploy
- Connect serial terminal
- Use terminal program (MTTTY, PuTTY, etc.)
- Configure: 115200 baud, 8-N-1
- Connect to NetBurner device
Operation Examples
EEPROM Testing Sequence
[Press '1'] Erase EEPROM
[Press '3'] Write incrementing sequence to EEPROM
[Press '2'] Read EEPROM - should show 00 01 02 03 ... FF
Temperature Monitoring
[Press 'T'] Read Temperature Sensor
Output: Temp: 23.56 C, 74.41 F, Register data: 17 90
DAC Control
[Press 'D'] DAC Test
Enter a DAC value between 0-1023
[Enter: 512]
Writing 512 (0x0200) to DAC: 0x80 0x00, 1.25 V
ADC Reading
[Press 'A'] Read ADC
Reading from address 0x4D ... Success
Voltage: 1.65V, Register data: 82 3F
LED Pattern Behavior
The application automatically cycles through LED patterns:
Pattern Sequence:
00000001 -> 00000010 -> 00000100 -> 00001000 ->
00010000 -> 00100000 -> 01000000 -> 10000000 ->
[Repeat from beginning]
Technical Implementation Details
EEPROM Page Writing
The 24LC0B EEPROM uses 8-byte pages for efficient writing:
int endOfPage = (8 - (startAddress % 8)) + 1;
Write Completion Detection
bool WaitForEepromWriteCmpl(uint8_t moduleNum, uint8_t address)
{
}
Temperature Conversion
The MCP9800 provides 12-bit temperature data in 2's complement format:
int8_t highByte = (int8_t)buffer[0];
float temp = highByte + ((buffer[1] >> 4) * 0.0625);
float tempF = (tempC * 9.0 / 5.0) + 32.0;
DAC Output Calculation
The TC1321 uses a 10-bit value with 2.5V reference:
buf[0] = 0x00;
buf[1] = (uint8_t)((value >> 2) & 0xFF);
buf[2] = (uint8_t)((value & 0x03) << 6);
float outputV = (float)value / 1023.0 * 2.5;
ADC Input Processing
The MCP3221 provides 12-bit ADC data:
uint16_t adcValue = ((uint16_t)buf[0] << 8) | buf[1];
float voltage = (float)adcValue * (3.3 / 4095.0);
Error Handling
I2C Status Codes
The application provides detailed status code descriptions:
| Code | Status | Description |
| 0 | I2C_OK | Operation successful |
| 1 | I2C_NEXT_WRITE_OK | Bus ready for write operation |
| 2 | I2C_NEXT_READ_OK | Bus ready for read operation |
| 3 | I2C_MASTER_OK | Master transmission complete |
| 4 | I2C_TIMEOUT | Communication timeout occurred |
| 5 | I2C_BUS_NOT_AVAIL | Bus acquisition timeout |
| 6 | I2C_NOT_READY | Device not ready for operation |
| 7 | I2C_LOST_ARB | Lost arbitration during start |
| 8 | I2C_LOST_ARB_ADD | Lost arbitration, addressed as slave |
| 9 | I2C_NO_LINK_RX_ACK | No ACK received from slave |
Troubleshooting Guide
Common Issues
- No device response
- Check physical connections (SDA, SCL, power, ground)
- Verify pull-up resistors on I2C lines
- Confirm device addresses match hardware configuration
- EEPROM write failures
- Ensure write completion polling is working
- Check for proper page boundary handling
- Verify address range (0-255 for 24LC0B)
- Temperature reading errors
- Confirm device initialization sequence
- Check configuration register settings
- Verify 12-bit resolution mode
- DAC output incorrect
- Check reference voltage (should be 2.5V)
- Verify 10-bit data format and bit alignment
- Measure actual output with multimeter
- ADC reading issues
- Confirm input voltage within 0-3.3V range
- Check reference voltage stability
- Verify 12-bit conversion calculation
Debug Commands
# Check I2C bus status
iprintf("I2C Status: %d\n", status);
DisplayI2CStatusCode(status);
# Display raw register data
for(int i = 0; i < len; i++)
iprintf("%02X ", buffer[i]);
Performance Characteristics
Timing Specifications
- I2C Clock Speed: 100 kHz (standard mode)
- EEPROM Write Time: 5ms typical per page
- Temperature Conversion: 240ms maximum (12-bit)
- ADC Conversion: 133 microseconds typical
- DAC Settling Time: 6 microseconds typical
Memory Usage
- EEPROM Buffer: 256 bytes static allocation
- I2C Buffers: 8 bytes per transaction
- Total RAM Usage: Approximately 512 bytes
Code Architecture
Function Organization
Initialization Functions
Device-Specific Functions
ReadTempSensor() - MCP9800 temperature operations
WriteLeds() - MCP23008 GPIO control
WriteDAC() - TC1321 analog output
ReadADC() - MCP3221 analog input
EepromWriteBuf() / EepromRead() - 24LC0B memory operations
Utility Functions
DisplayI2CStatusCode() - Error code interpretation
WaitForEepromWriteCmpl() - Write cycle detection
Ascii2Byte() - String to hex conversion
DisplayBuffer() - Memory dump formatting
User Interface Functions
DisplayMenu() - Menu system display
ProcessCommand() - Command parsing and execution
IncrementLEDs() - LED pattern animation
Learning Objectives
This example demonstrates:
- Multi-device I2C communication - Managing multiple peripherals on single bus
- Different data types - Binary, analog, temperature, and memory data
- Error handling patterns - Comprehensive status checking and recovery
- Real-time operations - Continuous monitoring and control
- User interaction - Menu-driven testing and configuration
- Hardware abstraction - Platform-independent I2C operations
Build Configuration
Dependencies
- NetBurner NNDK (Network Development Kit)
- Microchip PicKit Serial I2C Demo Board
- Multi-channel I2C library support
Related Examples
For additional I2C learning, see:
- Basic I2C examples for single-device communication
- I2C address scanning utilities
- Advanced I2C timing and error recovery examples
- Real-time data logging with I2C sensors