Skip to content

limingjie/CH32V003-Tristate-Multiplexing-LED

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CH32V003 Tristate Multiplexing LED

CH32V003J4M6 (SOP-8) drives a 5x6 LED matrix with only 6 GPIOs.

I programmed 5 boards to show running words. But as there is no synchronization among the boards, the boards will soon run out of sync.

Five Boards

Schematic

Schematic

How It Works

The program uses the Tristate Multiplexing (Charlieplexing) technique to drive LEDs. Each GPIO is used as both row and column lines, so n GPIOs support n x (n - 1) LEDs.

There is only one LED light at a time, and each LED supports 16 brightness levels. The program uses SysTick to update the LED matrix 50,000 times per second, so each LED updates at 50,000/30/16 = 104Hz, which is too fast for human eyes to notice.

Programming

To program the CH32V003 microcontroller, you will need a programmer that supports SWD.

Wiring the Board to WCH-LinkE

CH32V003 Upload Firmware Wiring

Switch WCH-LinkE to RISC-V Mode

If the blue LED on the WCH-LinkE is always on, it is in ARM mode. To program CH32V003, it needs to be switched to RISC-V mode. Hold the Modes key while plugging it in the USB port.

WCH-LinkE Modes

Compiling and Uploading (macOS)

Install RISC-V Toolchain.

brew tap riscv-software-src/riscv
brew install riscv-tools

This project uses the minichlink utility to upload, so the libusb is required as a dependency.

brew install libusb

Clone the project, connect the board to the programmer, then run the make command to compile and upload the firmware.

git clone https://github.com/limingjie/CH32V003-Tristate-Multiplexing-LED.git
cd CH32V003-Tristate-Multiplexing-LED
make

The PD1/SWDIO, PD4, and PD5 share the same pin on CH32V003J4M6, after the program uploaded, it is not possible to upload again. Use the minichlink -u command to clear all code flash (unbrick) and then upload.

./tools/minichlink -u
make

Build minichlink Utility (macOS)

The minichlink utility in the tools library is built for x86_64. If your macOS runs on Apple Silicon, you can build the minichlink utility and copy it to the tools folder.

brew install pkg-config
brew install libusb
git clone https://github.com/cnlohr/ch32v003fun.git
cd ch32v003fun/minichlink
make

References