MAX22200 ESP32-C6 Comprehensive Test Suite

This directory contains comprehensive test suites for the MAX22200 octal solenoid and motor driver using the ESP32-C6 DevKit-M-1.

πŸ“‹ Table of Contents


πŸ”Œ Hardware Overview

ESP32-C6 DevKit-M-1

The ESP32-C6 DevKit-M-1 serves as the host controller for communicating with the MAX22200 driver via SPI.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚        ESP32-C6 DevKit-M-1                      β”‚
β”‚                                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚        ESP32-C6 Microcontroller          β”‚   β”‚
β”‚  β”‚                                          β”‚   β”‚
β”‚  β”‚  GPIO Pins:                              β”‚   β”‚
β”‚  β”‚  β€’ SPI: MOSI (GPIO7), MISO (GPIO2),      β”‚   β”‚
β”‚  β”‚          SCLK (GPIO6), CS (GPIO10)       β”‚   β”‚
β”‚  β”‚  β€’ Test Indicator: GPIO14                β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                                 β”‚
β”‚  USB-C Connector                                β”‚
β”‚  (Power + Serial Communication)                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

MAX22200 Octal Solenoid and Motor Driver

The MAX22200 is an octal (eight-channel) solenoid and motor driver featuring:

  • Eight Half-Bridges: Each capable of handling up to 36V and 1A RMS
  • Current and Voltage Regulation: Supports both CDR and VDR modes
  • Integrated Lossless Current Sensing (ICS): Real-time current monitoring
  • High-Speed SPI Interface: Up to 10MHz communication
  • Comprehensive Protection: OCP, OL, DPM, UVLO, TSD, and fault registers
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
26
27
28
29
30
31
32
33
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      MAX22200 Octal Driver                     β”‚
β”‚                                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚        MAX22200 IC                       β”‚   β”‚
β”‚  β”‚                                          β”‚   β”‚
β”‚  β”‚  Features:                               β”‚   β”‚
β”‚  β”‚  β€’ 8 half-bridge channels (OUT0-OUT7)    β”‚   β”‚
β”‚  β”‚  β€’ SPI interface (up to 10MHz)           β”‚   β”‚
β”‚  β”‚  β€’ Current regulation (CDR mode)         β”‚   β”‚
β”‚  β”‚  β€’ Voltage regulation (VDR mode)         β”‚   β”‚
β”‚  β”‚  β€’ Integrated current sensing (ICS)     β”‚   β”‚
β”‚  β”‚  β€’ Fault detection and reporting         β”‚   β”‚
β”‚  β”‚  β€’ Thermal shutdown protection          β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                                 β”‚
β”‚  SPI Connections:                               β”‚
β”‚  β€’ MOSI (Master Out Slave In)                   β”‚
β”‚  β€’ MISO (Master In Slave Out)                   β”‚
β”‚  β€’ SCLK (Serial Clock)                          β”‚
β”‚  β€’ CS (Chip Select)                             β”‚
β”‚                                                 β”‚
β”‚  Power Connections:                             β”‚
β”‚  β€’ VCC (3.3V/5V Logic Power)                    β”‚
β”‚  β€’ VDD (12V-36V Load Power)                     β”‚
β”‚  β€’ GND (Ground)                                 β”‚
β”‚                                                 β”‚
β”‚  Control Pins:                                  β”‚
β”‚  β€’ RESET (Reset Input)                          β”‚
β”‚  β€’ FAULT (Fault Status Output)                  β”‚
β”‚  β€’ DIAG (Diagnostic Output)                     β”‚
β”‚  β€’ SHDN (Shutdown Input)                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“Œ Pin Connections

SPI Bus Connections

MAX22200 Pin ESP32-C6 GPIO Function Notes
MOSI GPIO7 SPI Data Out Master to Slave
MISO GPIO2 SPI Data In Slave to Master
SCLK GPIO6 SPI Clock Clock signal
CS GPIO10 Chip Select Active low
VCC 3.3V Logic Power 3.3V or 5V
VDD 12V-36V Load Power For solenoids/motors
GND GND Ground Common ground
RESET GPIO5 (optional) Reset Input Active low
FAULT GPIO4 (optional) Fault Status Open-drain, requires pull-up
DIAG GPIO3 (optional) Diagnostic Open-drain, requires pull-up
SHDN GPIO1 (optional) Shutdown Active low

Test Indicator

Signal ESP32-C6 GPIO Function
Test Progress GPIO14 Visual test progression indicator

SPI Configuration

Default SPI configuration (can be modified in test file):

  • Mode: Mode 0 (CPOL=0, CPHA=0) or Mode 3 (CPOL=1, CPHA=1)
  • Bit Order: MSB first
  • Clock Speed: Up to 10MHz (5MHz with daisy chaining)
  • Data Width: 8-bit transfers
  • Chip Select: Active low, controlled by software

πŸ› οΈ Hardware Setup

Basic Setup

  1. Connect SPI Bus:
    • Connect MAX22200 MOSI to ESP32-C6 GPIO7
    • Connect MAX22200 MISO to ESP32-C6 GPIO2
    • Connect MAX22200 SCLK to ESP32-C6 GPIO6
    • Connect MAX22200 CS to ESP32-C6 GPIO10
  2. Power Connections:
    • Connect MAX22200 VCC to ESP32-C6 3.3V (logic power)
    • Connect MAX22200 VDD to 12V-36V power supply (load power)
    • Connect MAX22200 GND to ESP32-C6 GND (common ground)
  3. Optional Control Pins:
    • Connect MAX22200 RESET to ESP32-C6 GPIO5 (optional, can use software reset)
    • Connect MAX22200 FAULT to ESP32-C6 GPIO4 (optional, for fault monitoring)
    • Connect MAX22200 DIAG to ESP32-C6 GPIO3 (optional, for diagnostics)
    • Connect MAX22200 SHDN to ESP32-C6 GPIO1 (optional, for hardware shutdown)
  4. Load Connections:
    • Connect solenoids or motors to OUT0-OUT7 pins
    • Ensure proper current ratings (max 1A RMS per channel)
    • Use appropriate flyback diodes for inductive loads

Test Setup

For comprehensive testing, you can connect:

  • Solenoids or motors to output channels (with appropriate current ratings)
  • Current measurement equipment for ICS verification
  • Logic analyzer on SPI bus for protocol verification
  • Oscilloscope for timing analysis

πŸš€ Building the Tests

Prerequisites

  1. 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
    
  2. Navigate to ESP32 Examples:

    1
    
    cd examples/esp32
    
  3. 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
max22200_comprehensive_test Comprehensive MAX22200 driver testing with all features MAX22200 board
max22200_solenoid_valve_test Solenoid/valve test: all 8 channels, C21 hit/hold, sequential & parallel patterns, full diagnostics MAX22200 board + valves (optional)
max22200_diagnostic Fault-isolation tool β€” dumps every SPI byte, walks the datasheet init flow, round-trips CFG_CH0, then continuous STATUS dump @ 5 Hz for scope probing. Use when chip won’t initialize or behaves unexpectedly MAX22200 board (no coil required)
c21_cycle_test Single-channel Parker C21 24 V solenoid hit-and-hold cycle test on CH0 with 10 Hz STATUS+FAULT telemetry. Bench-validated baseline for MAX22200 + C21 MAX22200 board + C21 24 V solenoid wired between OUT0 and +VM
c21_dpm_tuning_test Cycles a C21 with DPM enabled, polls FAULT @ 1 kHz during HIT window, emits CSV stream + summary stats so DPM ISTART/IPTH/TDEB can be tuned against real plunger movement. Hold the plunger still to validate the no-movement detection MAX22200 board + C21 24 V solenoid

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 max22200_comprehensive_test Debug

# Build comprehensive test (Release build)
./scripts/build_app.sh max22200_comprehensive_test Release

πŸ“€ Running the Tests

Flash Application

1
2
3
4
5
# Flash the application to ESP32-C6
./scripts/flash_app.sh max22200_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 max22200_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: max22200_comprehensive_test

This comprehensive test suite validates all MAX22200 functionality:

Test Sections

  1. Initialization Tests
    • SPI bus initialization
    • Driver initialization
    • Reset to default state
    • Global configuration
  2. Channel Configuration Tests
    • Single channel configuration
    • Multiple channel configuration
    • All channels configuration
    • Channel enable/disable
  3. Current Control Tests
    • Hit current setting
    • Hold current setting
    • Current reading (ICS)
    • Current regulation (CDR mode)
  4. Voltage Control Tests
    • Voltage regulation (VDR mode)
    • Voltage setting and reading
  5. Drive Mode Tests
    • CDR (Current Drive Regulation) mode
    • VDR (Voltage Drive Regulation) mode
    • Bridge mode configuration
  6. Fault Detection Tests
    • Overcurrent protection (OCP)
    • Overload (OL) detection
    • Dynamic power management (DPM)
    • Thermal shutdown (TSD)
    • Under-voltage lockout (UVLO)
  7. Diagnostic Tests
    • Diagnostic mode enable/disable
    • Fault status reading
    • Fault callback registration
  8. Statistics Tests
    • Operation statistics tracking
    • Error counting
    • Performance metrics
  9. Error Handling Tests
    • Invalid channel handling
    • Error flag management
    • Error recovery
  10. Stress Tests
    • Rapid channel operations
    • Continuous read/write cycles
    • Multi-channel simultaneous operations

Test Configuration

You can enable/disable specific test sections by editing the test file:

1
2
3
// In MAX22200ComprehensiveTest.cpp
static constexpr bool ENABLE_BASIC_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

Solenoid / Valve Test

Application: max22200_solenoid_valve_test

Dedicated full driver check on valves. Configures all 8 channels with the same C21-style profile (100 ms hit, 50% hold, low-side CDR or VDR per C21ValveConfig in esp32_max22200_test_config.hpp). Runs synchronized patterns and logs comprehensive diagnostics.

Features

  • Same valve profile on all channels: Hit time 100 ms, hold 50%, CDR or VDR at compile time.
  • Sequential pattern: Follow-up clicking β€” ch0 β†’ ch1 β†’ … β†’ ch7 (each on 200 ms, 80 ms gap).
  • Parallel pattern: All 8 channels on together for 500 ms, then all off.
  • Full diagnostics: STATUS (ACTIVE, fault flags, channels on), FAULT register (OCP, HHF, OLF, DPM per channel), last fault byte (hex + decode), nFAULT pin state, per-channel config readback, board config, driver statistics. Formatted logging with section headers and tables for easy interpretation.

Build and run

1
2
./scripts/build_app.sh max22200_solenoid_valve_test Debug
./scripts/flash_app.sh max22200_solenoid_valve_test Debug

Configuration

Valve profile is controlled by C21ValveConfig in esp32_max22200_test_config.hpp: USE_CDR, HIT_TIME_MS, HOLD_PERCENT, HIT_PERCENT. Timing constants (e.g. SEQUENTIAL_HIT_MS, PARALLEL_HOLD_MS) are in max22200_solenoid_valve_test.cpp.


MAX22200 Diagnostic

Application: max22200_diagnostic

End-to-end fault-isolation tool. Walks every comm path the datasheet defines (Figures 7, 10, 11, 12, 13) and dumps the raw register bytes so they can be correlated against scope/DMM measurements at the chip pins. Use this when the chip won’t initialize, when nFAULT asserts unexpectedly, or when SPI round-trips don’t match expected bytes.

Test sections

  1. Pin level snapshot (BEFORE bus init) β€” shows the chip’s idle state at MCU boot. 0.5. Hard ENABLE pulse β€” drive ENABLE LOW for 50 ms (low-power start).
  2. Bus + driver construction (no chip access yet).
  3. driver.Initialize() β€” the datasheet init flow (read STATUS to clear UVM, write ACTIVE=1, verify); pin levels dumped again.
  4. Three consecutive raw STATUS reads β€” confirms the value is stable.
  5. CFG_CH0 round-trip β€” write 0x28500600, read back, compare. Canonical SPI sanity check.
  6. FAULT register clear-by-read β€” clears OCP/HHF/OLF/DPM bits.
  7. STATUS read after FAULT clear β€” confirms nFAULT releases.
  8. Two STATUS-write variants + a second CFG_CH0 round-trip.
  9. Continuous STATUS+FAULT @ 5 Hz with periodic ACTIVE=1 re-write.

Always built with ESP32_MAX22200_ENABLE_DETAILED_SPI_LOGGING=1, so every TX/RX byte goes to the console.

Build and run

1
2
./scripts/build_app.sh max22200_diagnostic Debug
./scripts/flash_app.sh flash_monitor max22200_diagnostic Debug

C21 Single-Channel Cycle Test

Application: c21_cycle_test

Real-hardware cycle test for a Parker C21 24 V solenoid driven on MAX22200 channel 0 in CDR (current-controlled hit-and-hold) mode. Drives the coil at 102 mA hit / 51 mA hold (per the C21 Hit-and-Hold table) and cycles ON/OFF every 2 s while a 10 Hz telemetry task scrapes STATUS, FAULT, last CMD-echo byte and nFAULT pin.

Bench-validated baseline for first-light bring-up of a new MAX22200 + C21 setup. Implements the recommended β€œwake the chip, then poll STATUS until ACTIVE=1” pattern β€” see docs/troubleshooting.md for why this is needed.

Hardware

  • C21 24 V solenoid wired between OUT0 and +VM (low-side switching).
  • +VM = 24 V supply to the MAX22200 board.

Build and run

1
2
./scripts/build_app.sh c21_cycle_test Debug
./scripts/flash_app.sh flash_monitor c21_cycle_test Debug

Configuration

Edit the cfg namespace at the top of main/c21_cycle_test.cpp for a different C21 variant, cycle cadence, or to enable per-channel diagnostics (DPM / OL / HHF). All fault detections are OFF by default for first-light bring-up.


C21 + DPM Tuning Test

Application: c21_dpm_tuning_test

Cycles a Parker C21 24 V solenoid with DPM (Detection of Plunger Movement) enabled, polls the FAULT register at 1 kHz during the HIT window, and emits one CSV line per sample plus a final summary with DPM hit-rate and first-fire timing statistics.

Use this to:

  • Verify DPM correctly detects plunger movement on healthy actuations (DPM=0 every cycle).
  • Validate stuck-plunger detection by holding the plunger still during a cycle (DPM=1 should fire).
  • Tune the global DPM parameters (ISTART / IPTH / TDEB) for your specific valve.

DPM polarity (datasheet §”Detection of Plunger Movement”)

FAULT.DPM[ch] value Meaning
0 Current dip seen β†’ plunger MOVED (healthy)
1 Drop NOT revealed β†’ plunger STUCK (fault flag)

CSV format

Each sample emits a line like:

1
CSV,cycle,phase,t_us,fault_dpm_byte,status_byte,dpm_fired,ocp,hhf,olf

Pipe through grep '^CSV,' > run.csv and load into your plotter of choice.

Build and run

1
2
./scripts/build_app.sh c21_dpm_tuning_test Debug
./scripts/flash_app.sh flash_monitor c21_dpm_tuning_test Debug

Configuration

Tunable parameters at the top of main/c21_dpm_tuning_test.cpp:

1
2
3
constexpr float kDpmStartCurrent_mA = 20.0f;   // ISTART β€” start monitoring early
constexpr float kDpmThreshold_mA    = 4.0f;    // IPTH   β€” most-sensitive non-zero
constexpr float kDpmDebounce_ms     = 0.05f;   // TDEB   β€” minimum (1 chopping period)

See the file header for a full tuning workflow.


πŸ”§ Configuration

SPI Bus Configuration

Default SPI configuration (can be modified in test file):

1
2
3
4
// SPI configuration for MAX22200
// Mode: 0 (CPOL=0, CPHA=0) or 3 (CPOL=1, CPHA=1)
// Speed: Up to 10MHz
// Bit Order: MSB first

MAX22200 Configuration

Default MAX22200 settings (can be modified in test file):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Global configuration
GlobalConfig global_config;
global_config.diagnostic_enable = true;
global_config.ics_enable = true;
global_config.daisy_chain_mode = false;
global_config.sleep_mode = false;

// Channel configuration (user units: mA and ms)
ChannelConfig channel_config;
channel_config.drive_mode = DriveMode::CDR;
channel_config.side_mode = SideMode::LOW_SIDE;
channel_config.hit_setpoint = 500.0f;   // mA
channel_config.hold_setpoint = 200.0f;  // mA
channel_config.hit_time_ms = 10.0f;
// IFS from SetBoardConfig; driver uses cached STATUS for hit time
channel_config.chop_freq = ChopFreq::FMAIN_DIV2;

πŸ› Troubleshooting

SPI Communication Failures

Symptoms: Tests fail with SPI errors

Solutions:

  1. Check SPI connections:
    • Verify MOSI/MISO/SCLK/CS connections
    • Ensure proper power connections
    • Check for loose connections
  2. Verify SPI configuration:
    • Check SPI mode (0 or 3)
    • Verify clock speed (reduce if using long wires)
    • Ensure CS is properly controlled
  3. Verify power supply:
    • Ensure 3.3V logic power is stable
    • Check 12V-36V load power is present
    • Check for voltage drops

Build Errors

Symptoms: CMake or compilation errors

Solutions:

  1. Verify ESP-IDF version:
    1
    2
    
    idf.py --version
    # Should show ESP-IDF v5.5 or compatible
    
  2. Clean and rebuild:
    1
    2
    
    idf.py fullclean
    ./scripts/build_app.sh max22200_comprehensive_test Debug
    
  3. Check component paths:
    • Verify component CMakeLists.txt paths
    • Ensure source files are accessible

Test Failures

Symptoms: Specific tests fail

Solutions:

  1. Check hardware connections:
    • Verify all pins are properly connected
    • Check for loose connections
    • Verify load connections (solenoids/motors)
  2. Review test logs:
    • Check which specific test failed
    • Review error messages in serial output
  3. Verify device state:
    • Reset MAX22200 (power cycle or software reset)
    • Run reset test first
  4. Check current/voltage settings:
    • Verify current settings are within limits (max 1A RMS)
    • Check voltage supply is within range (12V-36V)

πŸ“š 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 max22200_comprehensive_test Debug

# Flash and monitor
./scripts/flash_app.sh max22200_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

  • SPI Configuration: Use Mode 0 or Mode 3, MSB first, up to 10MHz clock
  • Power Requirements: 3.3V/5V for logic, 12V-36V for load power
  • Current Limits: Maximum 1A RMS per channel
  • Test Duration: Comprehensive test suite takes approximately 2-5 minutes to complete
  • Hardware Requirements: Basic tests work without external hardware; some tests require solenoids/motors connected

🎯 Ready to test the MAX22200?
Start with: ./scripts/build_app.sh max22200_comprehensive_test Debug