CH341A tool
This is a Windows tool adding extra functionality to popular EEPROM/FLASH programmer based on CH341A USB to I2C/SPI/UART converter - using it as a general purpose interface.
Before using this type of CH341A-based programmer check if your variant is using 5 V for CH341A power supply. There are some variants that don't have this issue or might even be able to switch between 5 V and 3.3 V (more useful / commonly used), but the ones with CH341A powered from 5 V might be still common. Example "voltage fix".
Functions:
- detecting I2C devices
- writing/reading raw I2C data
- writing/reading raw SPI data
- writing/reading CH341A GPIO
- reading Smart Battery information
- reading data from some I2C sensors:
- BME280/BMP280
- BMP180
- Si7021
- LM75
- AHT10/AHT20
- AS5600
- VL53L0X laser ToF distance sensor
- APDS-9960 light/proximity/gesture sensor
- L3G4200D gyro
- writing to SSD1306-based OLED display
- writing text text to HD44780 display (GPIO mode)
- writing text text to HD44780 + PCF8574 display (I2C)
- writing to SPI MAX7219 8x8 LED matrix
- controlling RDA5807M FM radio module
- controlling Si5351A clock generator
Detecting I2C devices
Scanning I2C bus for responding devices, like Linux i2cdetect program. Illustration above shows result with RDA5807M FM radio module connected - this chip has two separate addresses giving access to single and to multiple registers and yet another address (0x60) for compability with TEA5767 chip.
I2C write/read
Plain GUI for CH341StreamI2C() API. Sending I2C address, sending optional bytes (from hex string), receving optional bytes (as hex string). Accepts hex string with and without "0x" prefix and with or without comma/whitespace separators.
SPI write/read
SPI on CH341A seems very limited. There are some contradicting informations regarding clock speed, here is my capture from using CH341StreamSPI4() function:
What might be confusing is that clock is irregular - high clock pulses are uniform and have 250 ns, but low state can last around 330 ns (lets call this one regular), around 420 ns (between second and third bit of a byte), around 680 ns (between fourth and fifth bit) or even (between two bytes) around 1170 ns. After averaging this results in ~1.4 MHz clock. CH341A would be not viable for driving WS2812B LEDs.
CS polarity is active low, in my tests CS was activated 11...20 us before the data start and was held down for 930...1110 us after the end of data.
GPIO
This module has no practical use - it was used only to test CH341A API.
Reading data from sensors
HTU21/SHT21/Si7021 sensors are cheap but from my experience fragile when used outdoors, in particular humidity measurements is prone to returning incorrect data on a rainy days, so it is not only the PCB
but also the sensor itself. I have a small collection of sensors eaten by corrosion and CH341 can be used to double check them.
I have ordered BME280 sensor module some time ago with the intention of replacing Si7021, but it was actually the first time I've tested it.
AS5600 magnetic sensor / encoder
This is a quite interesting magnetic field sensor. It measures absolute direction of magnetic field in one plane, up to 360 degrees with 12-bit resolution, working as an absolute angle sensor. Apart from the I2C data it is able to output voltage ratiometric to Vdd or PWM signal. It looks like a possible replacement for potentiometers used in game controllers like joycon.
The kit I've bought from China comes with a small cylindrical magnet that could be connected to controller/potentiometer axis. This probably helps new users as proper magnetic field orientation and strength is required. Magnet should be placed relatively close to the sensor chip - consider using some isolator to avoid shorts due to sticking to goldpin headers.
Reading Smart Battery information
One of the main reasons for writing this tool was the need for diagnosing some old laptop batteries. In the past I was also reselling some batteries bought in bulk and being able to make sure if their controller is fine, read their production date and cycle count would be helpful. I was hoping also for battery repair functionality, it is not trivial though - unlock procedures and/or codes are not publicly known except for few older models like BQ8030.
CH341A is not recommended on NLBA forum as a Smart Battery interface due to poor timings. I have not verified this, but I do indeed have some unstable readings. To gain confidence in data reading needs to be repeated few times.
Dell VV0NF battery (based on BQ8050, Sanyo firmware) required +12V power (despite cells being charged) to communicate over SMBus. Pinout: 1 = GND, 4 = T, 6 = DATA, 7 = CLK, 9 = +.
This battery also wasn't working with 100 kHz I2C clock speed, requiring 20 kHz.
IBM/Lenovo P1137 (for Lenovo R500, T500 laptops, based on BQ8030): plus on the left, GND on the right, DATA on pin 3, CLK on pin 4.
DIP-8 socket can be used as a makeshift cable connector plugged into TEXTOOL socket.
Identifying Smart Battery clock/data can be done by try/error using multimeter and knowing that both these pins would be connected to GND through protection diodes. GND and "+" pins are often marked/visible on the battery and most likely placed on the connector edges.
Note on Smart Battery "T"/System Present pin: it probably needs connecting to GND (I've seen it connected directly or through 1kOhm resistor, I've used 75Ohm resistor myself with Dell VV0NF). If it is not connected I2C on the Smart Battery might be not responding or it might be still active, just reporting battery as locked.
SSD1306 OLED display
Controlling popular cheap 0.96" OLED display based on SSD1306.
HD44780 display
Writing text to HD47780 LCD display connected over GPIO in 4-bit mode. For the connection CH341A programmer pins that are available on goldpin headers were choosen: UART RX/TX and four SPI pins.
HD44780 display connected using PCF8574
This type of alphanumeric display can be bought cheaply on aliexpress. While HD44780 requires normally at least 6 pins for control, adding PCF8574 (I2C to GPIO expander) allows to use it directly with I2C and up to 8 displays can be controlled with a single interface.
This consists of two boards connected together (sold as a soldered set or separately) - regular LCD display and PCF8574 piggyback.
This particular display requires 5V power supply. I2C/PCF8574 works fine with 3.3V (and 3.3V is fine for I2C even is display is powered from 5V),
but only LED backlight be controlled, LCD itself is blank. There are also variants able to operate at 3.3V, with ICL7660 charge pump soldered as U3 and two extra capacitors.
Note: if the display is blank (either all lit or all black) then contrast might need adjusting (the blue potentiometer).
Connections between PCF8574 and display:
PCF8574 Display D0 RS D1 RW D2 ENABLE D3 LED control D4 DATA4 D5 DATA5 D6 DATA6 D7 DATA7
MAX7219 8x8 LED matrix
This is an 8x8 LED matrix display controlled by a MAX7219 clone over SPI.
LED matrix is marked as M12088A/B and connected to PCB with two precision SIP sockets. There are few color and brigthness variants, with 25 or 30 mA forward current and 100 mA peak forward current in 1/10 duty cycle, 0.1 ms pulse.
Original MAX7219 would be more expensive on itself than this module. Chip that I found inside is marked as GC7219C.
The GUI part allows to switch state of each LED individually and control display brightness.
Note: I've used 5V to power this display board, but 3.3V signal voltage levels.
RDA5807M FM tuner
Controlling RDA5807M FM radio tuner. Tuner module can be powered from CH341A programmer. For audio output either active speakers can be used or 32 Ohm headphones can be directly driven.
Si5351A clock generator
Cheap programmable clock generator with two PLLs.
CH341A: Si5351A module
The particular module I own is intended to be powered from 3.3V - 5V (there is a voltage regulator and also I2C level converters on the PCB).
It uses 25 MHz reference crystal. Outputs are separated with capacitors.
Releases, changelog, source code
- 2023.11.04: version 1.0.0, initial release.
CH341A_tool_1_0_0_bin.zip
CH341A_tool_1_0_0_src.zip
- detecting I2C devices
- writing/reading raw I2C data
- reading Smart Battery information
- writing/reading CH341A GPIO
- reading data from some popular I2C sensors:
- BME280
- BMP180
- Si7021
- writing to SSD1306-based OLED display
- controlling RDA5807M FM radio module
- 2023.11.28: version 1.1.0
CH341A_tool_1_1_0_bin.zip
CH341A_tool_1_1_0_src.zip
- added reading temperature from LM75 I2C sensor
- added writing to HD44780 display using GPIO
- added writing to HD44780 + PCF8574 (I2C) display
- added I2C address selection to BME280
- BMP280 is listed next to BME280
- added AHT10/AHT20 temperature + humidity sensor
- added writing/reading raw SPI data (but CH341 SPI is quite limited)
- added writing to SPI MAX7219 8x8 LED matrix display
- added AS5600 - magnetic rotary position sensor with 12-bit resolution
- 2024.06.29: version 1.2.0
CH341A_tool_1_2_0_bin.zip
CH341A_tool_1_2_0_src.zip
- added Si5351A clock generator support
- added reading distance from VL53L0X laser ToF sensor
- added APDS-9960 light/proximity/gesture sensor reading
- added L3G4200D gyro reading
Note: using CH341A as I2C/SPI/GPIO interface requires "CH341PAR" driver. If you have used CH341A for EEPROM/FLASH programming, you already have it installed. Otherwise you can download it from https://www.wch-ic.com/downloads/CH341PAR_EXE.html or use my local copy: CH341PAR.zip.