
Hardware Introduction:
Power Supply:

An AP63203 DC-DC converter is used, with a fixed 3.3V output. However, this power supply design had a slight mishap. The AP63203 DC-DC datasheet states a 3.3V output, but the actual output is about 0.1-0.3V higher, causing the ST7735 screen to display incorrectly when the input voltage is high. Fortunately, the solution is simple: short-circuit the 3.3V and 5V on the development board. Testing showed that after short-circuiting, the output was 3.4V with a 20V input, but this did not affect operation.

Note: After short-circuiting, never use the development board's built-in Type-C
power supply. Voltage and Current Sampling:
TI's INA226 is used for sampling. It has a built-in 16-bit ADC, built-in op-amps, and can automatically average. It uses an IIC to connect to the host. The communication

main control MCU
is the LCSC-Diwenxing development board, built using the CW32F030C8T6 from Wuhan Xinyuan Semiconductor and a LCSC development board.
It's worth mentioning that the CW32F030C8T6 boasts a 32Mbits SPI refresh rate of 0.96, handling a 160*80 resolution screen with virtually no issues, significantly faster than the STM32F103's SPI. Thanks to the CW32F030C8T6's wide voltage range, it can operate normally even with slight power supply design issues. Additionally, the CW32F030C8T6 includes an advanced timer. Four general-purpose timers and three basic timers perfectly meet the requirements of this project

. The display screen
is a 0.96-inch, 160*80 resolution IPS display, communicating with the MCU via an SPI interface; this screen is very common

. Software components:
Overall software block diagram:

See source code: https://gitee.com/xmqor/cw32f030-mini-usb-voltage-ammeter
Function introduction:
Voltage and current display: Resolution 0.25mV, 0.25mA, power is the product of voltage and current.

Coulomb meter: The coulomb meter samples power 100 times per second via a timer and calculates the integral.

UI menu:


UI operation instructions:
Main interface:
Press both buttons simultaneously to enter the function menu
; right-click to switch between coulomb meter interfaces
. In the coulomb meter interface, press the left button to clear the time and coulomb value
(pressing both buttons simultaneously will not trigger the left and right button functions).
UI Menu:
Left and right buttons switch menus;
pressing both buttons simultaneously confirms (back in the brightness adjustment interface).
When the screen flips, the buttons will flip accordingly,
returning to the main interface and saving the state to flash.
A flash equalization loss algorithm is used, theoretically with a lifespan of 1000 cycles, two bytes per cycle, and one sector (512 bytes) can save for 250,000 cycles.
Possible bug: One error may occur every 255 cycles (this bug is unverified and may not exist).
A key point about LCDConfig:
Due to differences in screen batches, some may have negative colors, while
others may have BGR. Use the "OK" button on this interface to switch until the screen icon colors are normal.
There are four configurations in total.
As for different XY offsets, this can only be resolved by modifying the program offset.
Function demonstration video: [Mini USB Voltage and Current Meter - Bilibili] https://b23.tv/0eSmw3u
Important Notes: When soldering headers
for 5A or higher interfaces
, ensure they are aligned correctly. Otherwise, they will not be level.
After soldering the headers, first test the functionality by attaching the development board to the headers, then solder them securely
. To ensure a smooth solder joint, see the image below. Solder two headers to empty I/O pins, using

screws and nuts as spacers. Buy the size shown below.

The printed panel is semi-transparent, and the text is very unclear. If you don't like it, adjust the transparency control layer yourself.
As for the 8A and 16A markings on the panel, just take it as a joke; those are the maximum register values.
16A requires replacing the sampling resistor, modifying the program, and also requires a 10A connector.