How to access I2C EEPROM 24C01C from LC CH341A USB Adapter
Here is example how to access I2C EEPROM 24C01C:
from CH341A USB to UART/IIC/SPI/TTL/ISP adapter EPP/MEM Parallel converter
using I2C mode.
This is nice introductory example - it just uses
stock functions CH341WriteEEPROM()
and CH341ReadEEPROM()
already provided by CH341DLL.DLL
library
from CH341 driver. So the code is fairly trivial
as you can see from ch341_i2c_24c01c.cpp listing.
WARNING!
This program will overwrite all contents of your 24C01C EEPROM!
The example program does following:
Circuit schematic is below:
Hardware:
!!!IMPORTANT WARNING!!!
Do NOT use original Atmel 24C01! It uses different protocol
(the 1st byte which should be use for slave type/address is (mis)used
for EEPROM data address. The official CH341A library routines
will work with 24C01A or later revisions only!!!
The CH341A adapter must be setup following way:
I2C/SPI
mode5V
TTL logic - the only voltage supported by 24C01CSoftware setup:
Create environment variable CH341_SDK
that should point to extractedCH341PAR.ZIP
header and library files. For example
if you have extracted file:
C:\CH341_DRIVER\LIB\C\CH341DLL.H
Then your CH341_SDK
should be set to C:\CH341_DRIVER\LIB\C
.
Open and rebuild solution VS2010/ch341_i2c_24c01c/ch341_i2c_24c01c.sln
in VisualStudio 2010. There should be no errors.
Connect your CH341A USB module
to target circuit. Following pins are used:
PIN Name | Direction | Description |
---|---|---|
GND | N/A | Common ground |
VCC | N/A | 5V supply |
SDA | Open Drain | I2C Data |
SCL | Open Drain | I2C Clock |
Connect your CH341 USB module
to your PC. There should
be permanently lighting red LED on USB module.
Now you can run sample program - you should see following output:
ch341_i2c_24c01c.exe
CH341 library version: 33
Opening device# 0
CH341 driver version: 34
Storing string 'Hello!' (including '\0') at EEPROM address 0x5...
Fetching whole memory content...
Dumping EEPROM contents...
Dump of buffer at 0x00417140, bytes 128
0x0000 ff ff ff ff ff 48 65 6c 6c 6f 21 00 ff ff ff ff .....Hello!.....
0x0010 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
0x0020 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
0x0030 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
0x0040 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
0x0050 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
0x0060 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
0x0070 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
Cleaning EEPROM contents with 0xff...
Fetching whole memory content...
Dumping EEPROM contents...
Dump of buffer at 0x00417140, bytes 128
0x0000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
0x0010 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
0x0020 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
0x0030 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
0x0040 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
0x0050 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
0x0060 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
0x0070 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
TIP:
If you are curious how library functions work, you can found
them in Linux driver (there is no guarantee that they 100% match
Windows version though):
- Download and extract Linux driver: CH341PAR_LINUX.ZIP
- Look at
CH341PAR_LINUX\lib\ch34x_lib.c
For example in
CH34xWriteEEPROM()
function is very clever trick how to found
number of bytes till the end of page boundary:
mLen = iEepromID >= ID_24C04 ? 16 - ( iAddr & 15 ) : 8 - (iAddr & 7 );
if( mLen > iLength )
mLen = iLength;
In case of our EEPROM (
ID_24C01
) the second expression will apply:
mLen = 8 - (iAddr & 7 );
...
NOTE
Alternate driver source is from board vendor page CH341A USB to UART/IIC/SPI/TTL/ISP adapter EPP/MEM Parallel converter:
- Get and extract LC-TTL-CH341A_EN.zip (uhhh, the link seems to lost
after recent site revamp)- Look into
LC-TTL-CH341A\Drivers\Other platform drivers\CH341PAR_LINUX.ZIP
Here are Logic Analyzer outputs using Sigrok PulseView :
Page Write of Hello!\0
string to EEPROM:
There can be easily seen few challenges:
0x5
and page boundary is 0x8
there areAnd here is full sequential read (reading whole EEPROM):
Please note that sequential read has no page boundary limitation. Whole
EEPROM can be read using one command…