Files
ch32v003-ext-board/README.md
2024-11-08 00:46:09 +06:00

1.2 KiB

CH32-16-CH-EXT

A simple CH32V003-based extension board providing 16 GPIO channels, primarily designed for controlling Chinese 16-relay modules (archive) over RS485. Uses 64-byte internal flash page for state persistence.

KiCad hardware design files are in the hw directory.

photo render

Communication Protocol

Message Format

The RS485 communication uses a simple 4-byte message format:

Byte 0: Board Address (0x01-0xFE, 0xFF for broadcast)
Byte 1: Command (0x01 for SET_OUTPUTS)
Byte 2: Data High Byte
Byte 3: Data Low Byte

Protocol Constants

#define BOARD_ADDRESS   0x01        // Default board address
#define CMD_SET_OUTPUTS 0x01        // Command to set outputs
#define BROADCAST_ADDR  0xFF        // Broadcast address

Example Message

To control the outputs, send a 4-byte message:

let message = [
    address,            // Board address (0xFF for broadcast)
    CMD_SET_OUTPUTS,    // Command
    (value >> 8) as u8, // Data high byte
    value as u8,        // Data low byte
];