PCAL9555 ESP32-C6 Comprehensive Test Suite
This directory contains comprehensive test suites for the PCAL9555 16-bit I/O expander driver using the ESP32-C6 DevKit-M-1.
๐ Table of Contents
- Hardware Overview
- Pin Connections
- Hardware Setup
- Building the Tests
- Running the Tests
- Test Suites
- Troubleshooting
๐ Hardware Overview
ESP32-C6 DevKit-M-1
The ESP32-C6 DevKit-M-1 serves as the host controller for communicating with the PCAL9555 GPIO expander via I2C.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ESP32-C6 DevKit-M-1 โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ ESP32-C6 Microcontroller โ โ
โ โ โ โ
โ โ GPIO Pins: โ โ
โ โ โข I2C: SDA (GPIO4), SCL (GPIO5) โ โ
โ โ โข Test Indicator: GPIO14 โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ USB-C Connector โ
โ (Power + Serial Communication) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
PCAL9555 GPIO Expander
The PCAL9555 is a 16-bit I/O expander with IยฒC interface, providing 16 GPIO pins organized into two 8-bit ports.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ PCAL9555 GPIO Expander โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ PCAL9555 IC โ โ
โ โ โ โ
โ โ Features: โ โ
โ โ โข 16 GPIO pins (PORT_0: P0.0-P0.7) โ โ
โ โ โข 16 GPIO pins (PORT_1: P1.0-P1.7) โ โ
โ โ โข I2C interface (7-bit address) โ โ
โ โ โข Configurable pull-up/pull-down โ โ
โ โ โข Programmable drive strength โ โ
โ โ โข Interrupt support โ โ
โ โ โข Input latch capability โ โ
โ โ โข Polarity inversion โ โ
โ โ โข Open-drain output mode โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ I2C Connections: โ
โ โข SDA (I2C Data) โ
โ โข SCL (I2C Clock) โ
โ โข VDD (3.3V Power) โ
โ โข GND (Ground) โ
โ โข INT (Interrupt Output, optional) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Pin Connections
I2C Bus Connections
| PCAL9555 Pin | ESP32-C6 GPIO | Function | Notes |
|---|---|---|---|
| SDA | GPIO4 | I2C Data | With 4.7kฮฉ pull-up to 3.3V |
| SCL | GPIO5 | I2C Clock | With 4.7kฮฉ pull-up to 3.3V |
| VDD | 3.3V | Power Supply | ย |
| GND | GND | Ground | ย |
| INT | GPIO15 (optional) | Interrupt Output | Open-drain, requires pull-up |
Test Indicator
| Signal | ESP32-C6 GPIO | Function |
|---|---|---|
| Test Progress | GPIO14 | Visual test progression indicator |
I2C Address Configuration
The PCAL9555 I2C address is determined by the A0, A1, and A2 address pins:
| A2 | A1 | A0 | I2C Address (7-bit) | I2C Address (8-bit) |
|---|---|---|---|---|
| GND | GND | GND | 0x20 | 0x40 |
| GND | GND | VDD | 0x21 | 0x42 |
| GND | VDD | GND | 0x22 | 0x44 |
| GND | VDD | VDD | 0x23 | 0x46 |
| VDD | GND | GND | 0x24 | 0x48 |
| VDD | GND | VDD | 0x25 | 0x4A |
| VDD | VDD | GND | 0x26 | 0x4C |
| VDD | VDD | VDD | 0x27 | 0x4E |
Default: All address pins to GND = 0x20 (used in examples)
๐ ๏ธ Hardware Setup
Basic Setup
- Connect I2C Bus:
- Connect PCAL9555 SDA to ESP32-C6 GPIO4
- Connect PCAL9555 SCL to ESP32-C6 GPIO5
- Add 4.7kฮฉ pull-up resistors on both SDA and SCL to 3.3V
- Power Connections:
- Connect PCAL9555 VDD to ESP32-C6 3.3V
- Connect PCAL9555 GND to ESP32-C6 GND
- Optional Interrupt:
- Connect PCAL9555 INT to ESP32-C6 GPIO15 (with pull-up resistor)
- Address Configuration:
- Connect A0, A1, A2 to GND for default address 0x20
- Or configure for different address if needed
Test Setup
For comprehensive testing, you can connect:
- LEDs to output pins (with current-limiting resistors)
- Switches/buttons to input pins
- External pull-up/pull-down resistors for testing
- Logic analyzer on I2C bus for protocol verification
๐ Building the Tests
Prerequisites
-
Install ESP-IDF (if not already installed):
1 2 3 4 5 6 7 8 9 10 11 12 13
# Clone ESP-IDF git clone --recursive https://github.com/espressif/esp-idf.git cd esp-idf # Checkout release version 5.5 git checkout release/v5.5 git submodule update --init --recursive # Install ESP-IDF (Linux/macOS) ./install.sh esp32c6 # Set up environment (add to ~/.bashrc or ~/.zshrc for persistence) . ./export.sh
-
Navigate to ESP32 Examples:
1
cd examples/esp32 -
Setup Repository (First time only):
1 2 3
# Make scripts executable and setup the build environment chmod +x scripts/*.sh ./scripts/setup_repo.sh
Available Test Applications
The test suites use a centralized build system with scripts. Available applications:
| Application Name | Description | Hardware Required |
|---|---|---|
pcal9555_comprehensive_test |
Comprehensive PCAL9555 GPIO expander testing with all features | PCAL9555 board |
List Available Applications
1
2
# List all available applications
./scripts/build_app.sh list
Build an Application
1
2
3
4
5
# Build comprehensive test (Debug build)
./scripts/build_app.sh pcal9555_comprehensive_test Debug
# Build comprehensive test (Release build)
./scripts/build_app.sh pcal9555_comprehensive_test Release
๐ค Running the Tests
Flash Application
1
2
3
4
5
# Flash the application to ESP32-C6
./scripts/flash_app.sh pcal9555_comprehensive_test Debug
# Or manually:
idf.py -p /dev/ttyUSB0 flash
Monitor Output
1
2
3
4
5
# Monitor serial output
idf.py -p /dev/ttyUSB0 monitor
# Or use the flash script which includes monitoring
./scripts/flash_app.sh pcal9555_comprehensive_test Debug
Auto-detect Port
1
2
# The scripts can auto-detect the port
./scripts/detect_ports.sh
๐งช Test Suites
Comprehensive Test Suite
Application: pcal9555_comprehensive_test
This comprehensive test suite validates all PCAL9555 functionality:
Test Sections
- Initialization Tests
- I2C bus initialization
- Driver initialization
- Reset to default state
- GPIO Direction Tests
- Single pin direction configuration (input/output)
- Multiple pin direction configuration
- Port-level direction control
- GPIO Read/Write Tests
- Pin write operations (HIGH/LOW)
- Pin read operations
- Pin toggle operations
- Port-level read/write
- Pull Resistor Tests
- Pull-up resistor configuration
- Pull-down resistor configuration
- Pull enable/disable
- Per-pin pull configuration
- Drive Strength Tests
- All drive strength levels (Level0-Level3)
- Per-pin drive strength configuration
- Output Mode Tests
- Push-pull mode configuration
- Open-drain mode configuration
- Port-level output mode control
- Polarity Tests
- Input polarity inversion (normal/inverted)
- Single pin polarity configuration
- Multiple pin polarity configuration
- Input Latch Tests
- Input latch enable/disable
- Single pin latch configuration
- Multiple pin latch configuration
- Interrupt Tests
- Interrupt mask configuration
- Interrupt status reading
- Interrupt callback registration
- Port Operation Tests
- Port 0 operations (pins 0-7)
- Port 1 operations (pins 8-15)
- Mixed port operations
- Error Handling Tests
- Invalid pin handling
- Error flag management
- Error recovery
- Stress Tests
- Rapid pin operations
- Continuous read/write cycles
- Multi-pin simultaneous operations
Test Configuration
You can enable/disable specific test sections by editing the test file:
1
2
3
4
// In PCAL9555ComprehensiveTest.cpp
static constexpr bool ENABLE_INITIALIZATION_TESTS = true;
static constexpr bool ENABLE_GPIO_DIRECTION_TESTS = true;
// ... etc
Test Results
The test framework provides:
- Automatic pass/fail tracking
- Execution time measurement
- GPIO14 progress indicator (toggles on each test)
- Comprehensive test summary
- Success percentage calculation
๐ง Configuration
I2C Bus Configuration
Default I2C configuration (can be modified in test file):
1
2
3
4
5
6
Esp32Pcal9555Bus::I2CConfig config;
config.port = I2C_NUM_0;
config.sda_pin = GPIO_NUM_4; // SDA pin
config.scl_pin = GPIO_NUM_5; // SCL pin
config.frequency = 400000; // 400 kHz
config.pullup_enable = true; // Enable internal pullups
PCAL9555 Address
Default I2C address (can be modified in test file):
1
static constexpr uint8_t PCAL9555_I2C_ADDRESS = 0x20; // Default address
๐ Troubleshooting
I2C Communication Failures
Symptoms: Tests fail with I2C errors
Solutions:
- Check I2C connections:
- Verify SDA/SCL connections
- Check pull-up resistors (4.7kฮฉ recommended)
- Ensure proper power connections
- Verify I2C address:
- Check A0, A1, A2 pin configuration
- Use I2C scanner to detect device address
- Update
PCAL9555_I2C_ADDRESSif different
- Check I2C bus speed:
- Reduce frequency if using long wires
- Try 100 kHz instead of 400 kHz
- Verify power supply:
- Ensure 3.3V is stable
- Check for voltage drops
Build Errors
Symptoms: CMake or compilation errors
Solutions:
- Verify ESP-IDF version:
1 2
idf.py --version # Should show ESP-IDF v5.5 or compatible
- Clean and rebuild:
1 2
idf.py fullclean ./scripts/build_app.sh pcal9555_comprehensive_test Debug
- Check component paths:
- Verify component CMakeLists.txt paths
- Ensure source files are accessible
Test Failures
Symptoms: Specific tests fail
Solutions:
- Check hardware connections:
- Verify all pins are properly connected
- Check for loose connections
- Review test logs:
- Check which specific test failed
- Review error messages in serial output
- Verify device state:
- Reset PCAL9555 (power cycle)
- Run reset test first
๐ Additional Resources
๐ฏ Quick Reference
Build Commands
1
2
3
4
5
6
7
8
# List available apps
./scripts/build_app.sh list
# Build comprehensive test
./scripts/build_app.sh pcal9555_comprehensive_test Debug
# Flash and monitor
./scripts/flash_app.sh pcal9555_comprehensive_test Debug
Test Execution
The comprehensive test suite runs automatically on boot and provides:
- Real-time test progress via GPIO14 indicator
- Serial output with detailed test results
- Automatic test summary at completion
GPIO14 Test Indicator
GPIO14 toggles between HIGH/LOW for each completed test, providing visual feedback:
- Use oscilloscope or logic analyzer to monitor
- Useful for automated test verification
- Blinks 5 times at section start/end
๐ Notes
- I2C Pull-ups: External pull-up resistors (4.7kฮฉ) are recommended even if internal pullups are enabled
- Address Configuration: Default address is 0x20. Modify if using different A0/A1/A2 configuration
- Test Duration: Comprehensive test suite takes approximately 2-5 minutes to complete
- Hardware Requirements: Basic tests work without external hardware; some tests benefit from LEDs/switches
Start with:
./scripts/build_app.sh pcal9555_comprehensive_test Debug