- A practical guide to using the CH341A MiniProgrammer for I2C communication, with signal behavior analysis.
CH341DLL.H
(Header file)CH341DLL.LIB
(Linker library)CH341DLL.DLL
(Runtime DLL)
#include "CH341DLL.H"
int main() {
// Open the first CH341 device
if ((int)CH341OpenDevice(0) < 0) {
// Handle error
}
// Optional: Set I2C speed (0=20kHz, 1=100kHz, 2=400kHz, 3=750kHz)
CH341SetStream(0, 1);
// ... Perform I2C operations ...
CH341CloseDevice(0); // Cleanup
return 0;
}
Usage: Writes 1 byte to a device register.
Example:
UCHAR deviceAddr = 0x86 >> 1; // Right-shift 7-bit address
UCHAR regAddr = 0x22;
UCHAR data = 0x13;
CH341WriteI2C(0, deviceAddr, regAddr, data);
Bus Sequence:
- Start condition
- Write device address (LSB=0 for write)
- Write register address byte (
0x22
) - Write data byte (
0x13
) - Stop condition
Usage: Reads 1 byte from a device register.
Example:
UCHAR deviceAddr = 0x86 >> 1; // Right-shift 7-bit address
UCHAR regAddr = 0xD4;
UCHAR receivedData;
CH341ReadI2C(0, deviceAddr, regAddr, &receivedData);
Bus Sequence:
- Start condition
- Write device address (LSB=0)
- Write register address byte (
0xD4
) - Repeated start
- Write device address (LSB=1 for read)
- Read data byte
- Stop condition
Usage: Flexible multi-byte read/write operations.
UCHAR writeBuffer[] = {0x86, 0x22, 0x13}; // Device address + data
CH341StreamI2C(0, 3, writeBuffer, 0, NULL);
Bus Sequence:
- Start condition
- Write all bytes sequentially (
0x86
,0x22
,0x13
) - Stop condition
UCHAR readBuffer[2];
CH341StreamI2C(0, 0, NULL, 2, readBuffer); // No address sent!
Bus Sequence:
- Start condition
- Clock pulses (no address/data)
- Stop condition
UCHAR writeBuffer[] = {0x86}; // Device address (write mode)
UCHAR readBuffer[2];
CH341StreamI2C(0, 1, writeBuffer, 2, readBuffer);
Bus Sequence:
- Start condition
- Write address byte (
0x86
with LSB=0) - Repeated start
- Write address byte (
0x87
with LSB=1) - Read 2 bytes
- Stop condition
UCHAR writeBuffer[] = {0x86, 0xD4}; // Device address + register
UCHAR readBuffer[1];
CH341StreamI2C(0, 2, writeBuffer, 1, readBuffer);
Bus Sequence:
- Start condition
- Write address (
0x86
) + register (0xD4
) - Repeated start
- Write address (
0x87
with LSB=1) - Read 1 byte
- Stop condition
- Address Handling: Always right-shift 7-bit addresses (no LSB for R/W)
- Clock Speeds: Use
CH341SetStream()
for 20/100/400/750kHz - DLL Dependency: Must be in executable directory or System32
- Signal Verification: Use logic analyzer to validate complex transactions