43 lines
1.3 KiB
Markdown
43 lines
1.3 KiB
Markdown
# CH32-16-CH-EXT
|
|
|
|
A simple CH32V003-based extension board providing 16 outputs (2x 74HC595), primarily designed for controlling [Chinese 16-relay modules](https://www.uctronics.com/download/Amazon/U604302_print.pdf) ([archive](https://web.archive.org/web/20220709045418/https://www.uctronics.com/download/Amazon/U604302_print.pdf)) over RS485. Uses 64-byte internal flash page for state persistence.
|
|
|
|
KiCad hardware design files are in the `hw` directory.
|
|
|
|

|
|

|
|
|
|
## 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
|
|
|
|
```c
|
|
#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:
|
|
|
|
```rust
|
|
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
|
|
];
|
|
```
|