Author Topic: Read\Write I2C EEPROM using Arduino (or anything)  (Read 7882 times)

0 Members and 1 Guest are viewing this topic.

Offline VEGETATopic starter

  • Super Contributor
  • ***
  • Posts: 1946
  • Country: jo
  • I am the cult of personality
    • Thundertronics
Read\Write I2C EEPROM using Arduino (or anything)
« on: July 24, 2017, 08:10:37 pm »
Dear EEVBlog members,

I saw this link: https://playground.arduino.cc/Code/I2CEEPROM

I need to read AT24cxx eeproms data to a file on my PC\laptop (.txt for example) and also writes a certain file to another EEPROM... like copying one of them then programming the other one.

I didn't find in that link or any other how to do that part which involves storing the values in a txt file not just on serial because some chips has too many lines, also writing will not happen if I have the data on a txt file using that sketch alone.

Looking forward to your generous help!

Best regards,

Vegeta

Offline 3db

  • Frequent Contributor
  • **
  • Posts: 331
  • Country: gb
Re: Read\Write I2C EEPROM using Arduino (or anything)
« Reply #1 on: July 24, 2017, 11:46:07 pm »
Check out the UNI-T UT210E clamp meter thread.
There's some information there about using an Arduino to read/write these chips.
You could also check Kerry Wong's Youtube channel where he modifies one of these chips in a multimeter.
He wrote some Arduino code to do this which is on his website.
Sorry I can't be bothered finding the links for you

3DB
 

Online rstofer

  • Super Contributor
  • ***
  • Posts: 9889
  • Country: us
Re: Read\Write I2C EEPROM using Arduino (or anything)
« Reply #2 on: July 25, 2017, 12:21:37 am »
That library code reads and writes the EEPROM, nothing else. In setup() there is an example of writing a string to the EEPROM starting at address 0x0000.  In loop() there is an example of reading the contents starting at address 0x0000 on up until a 0x00 is read (end of string written above).

Getting EEPROM data into and out of the Arduino is one thing, writing a text file out in PC land is an entirely different matter.  There are a number of projects on the Internet where the user wants to capture text data from the Arduino.  That is pretty easy!  I would have the Arduino convert the bytes to the Intel Hex format before transmission.  That includes calculating the checksum which will allow the PC to verify the transmission.

What's hard is having the PC send data to the Arduino serial port.  The hardest part is for the Arduino to halt the PC while is processes a line of text.  I'm not sure what the best way to do that will be.  I would write something in Python (I guess...) that reads the file converts it to Intel Hex format if not already done and sends one line to the Arduino.  Then the Python code waits for an acknowledgement from the Arduino before sending the next line.  The Arduino will eat the hex line, verify the checksum and strip out the bytes before writing the EEPROM with the library from above.

Note that the Intel Hex format has an address field.  This is kind of nice should the file be discontinuous.  You know where to write the bytes based on the address field.  This field only covers 64k bytes so there is another record type that gives an address to add.  If the hex file is coming from a compiler, the appropriate record type may already be determined.  If what you have is a big heap of bytes, you can decide how to implement the Extended Linear Address record (type '04).

http://www.interlog.com/~speff/usefulinfo/Hexfrmt.pdf

The Arduino <-> I2C is trivial, the rest of the project is going to take a little time.

This should be an interesting use of Arduino and Python (or whatever).

 

Online rstofer

  • Super Contributor
  • ***
  • Posts: 9889
  • Country: us
Re: Read\Write I2C EEPROM using Arduino (or anything)
« Reply #3 on: July 25, 2017, 12:28:55 am »
There's another way to skin this cat - skip the Arduino and buy one of the FTDI FT2232 bridges.
http://hackaday.com/2011/11/14/ft-2232-bridges-python-and-i2cspi/

I haven't gone down this rabbit hole.  One comment is that writing code is time consuming but there is a library wrapper (Linux based)
http://www.devttys0.com/2011/11/speaking-spi-i2c-with-the-ft-2232/

I like breaking the project up into pieces.  I would probably create the Arduino serial exchange with Intel Hex bit and the I2C library first and then worry about what to do with the PC end of the business.

Any language can be used, Python isn't the only game in town.  What you do need is a serial library to talk to the Arduino VCOM port.
 

Online rstofer

  • Super Contributor
  • ***
  • Posts: 9889
  • Country: us
Re: Read\Write I2C EEPROM using Arduino (or anything)
« Reply #4 on: July 25, 2017, 12:33:19 am »
There's another way:  Use a Raspberry Pi.  How you get the file from a PC to the PI is a simple matter of file sharing over the LAN.

Now that you have the .bin file you can use the RPI I2C library to read/write the EEPROM.

https://www.richud.com/wiki/Rasberry_Pi_I2C_EEPROM_Program

Note section 10 where reading and writing a file is discussed.

This might be the easiest way once you get the setup out of the way.  Raspberry PI can deal with files and I2C so the task doesn't need to be spread all over the place.
« Last Edit: July 25, 2017, 12:40:34 am by rstofer »
 

Offline 3db

  • Frequent Contributor
  • **
  • Posts: 331
  • Country: gb
Re: Read\Write I2C EEPROM using Arduino (or anything)
« Reply #5 on: July 25, 2017, 07:33:48 am »
Or even easier just buy the CH340 based programmer mentioned in the UT210 thread.  :palm:
 
 

Offline VEGETATopic starter

  • Super Contributor
  • ***
  • Posts: 1946
  • Country: jo
  • I am the cult of personality
    • Thundertronics
Re: Read\Write I2C EEPROM using Arduino (or anything)
« Reply #6 on: July 25, 2017, 07:44:44 am »
I have found this tool which seems cheap: https://www.banggood.com/CH341A-24-25-Series-EEPROM-Flash-BIOS-DVD-USB-Programmer-p-929338.html

I guess that would work but I didn't do much research about it. I am not sure if it does program at24cxx eeproms or not.

However, this seems to work according to description: https://www.ebay.com/p/EEPROM-Programmer-Reader-Writer-USB-for-At24cxx-Hot/874481693

I hoped to find a simple way using Arduino to save the file to a *.txt and send it by serial port, then vise versa. I found some results but one github page is for linux with compiling software and stuff which won't help. I tried searching for using tools such as usbasp or serial to ttl converters but no use since it is I2C not serial data. Using RPI now is not an option for me.

I guess, according to your replies and my situation, buying one of these 5$ I2C EEPROM programmer is the choice (if anyone can confirm that they work). Messing with Arduino and stuff will take time and effort while I cannot provide due to my work (plus, I am not the one who will eventually work on these eeproms).

I just hoped to have a simple Arduino code to dump stuff to PC via serial port or vice versa.




Offline 3db

  • Frequent Contributor
  • **
  • Posts: 331
  • Country: gb
Re: Read\Write I2C EEPROM using Arduino (or anything)
« Reply #7 on: July 25, 2017, 07:55:55 am »
I can confirm that the ones with a black and gold pcb  work.
Search Amazon for CH341A USB Programmer and you'll see the type I mean.
I think there was a minor issue with the software but it's easily fixed and is mentioned on Youtube.
I have no reason to believe the ones you found will not work.

Good luck.
 
The following users thanked this post: VEGETA

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4694
  • Country: au
  • Question Everything... Except This Statement
Re: Read\Write I2C EEPROM using Arduino (or anything)
« Reply #8 on: July 25, 2017, 10:41:58 am »
You can approach it like i did for a rom dumper i made, have it spit out the code in 8 bit chunks, formatted how the write operation has to take place, e.g. reading from 0x09 returns "eeprom.write(0x09,0xAA);" etc, so you just have to copy the serial dump in to your code for the write
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12855
Re: Read\Write I2C EEPROM using Arduino (or anything)
« Reply #9 on: July 25, 2017, 11:48:39 am »
The major issue is  reliable PC <> Arduino comms.
As the Arduino makes no provision for hardware handshaking, you have three choices:

1. Keep the baud rate low enough so that even with the worst case delay to write to a file on the PC or to write a page to the EEPROM, neither the PC's or the Arduino's serial receive buffers will overflow.  As the worst case delay on the PC cant be guaranteed, you'll need to set the baud rate very conservatively and have some means of detecting if data has been lost.

2. Use a higher level protocol that transfers the data as packets, with a unique packet number, length check and checksum so that retransmission can be requested for any packet that has lost or corrupted characters.   This will have a considerable impact on the Arduino code, as you must wait for each packet's reception to be confirmed before you can reuse the packet buffer + you have to handle the overhead of building each packet.  On  the PC side, you'll probably need custom software, though it may be possible to reuse file transfer software designed to handle transfers via serial modem, with a well documented protocol and packet structure.

3.  Use Intel HEX as the data format,  implement XON/XOFF handshaking for the PC<>Arduino serial link, and code the Arduino loop() function to be non-blocking so it can always respond to a received XOFF quickly.  Unfortunately the Arduino Wire (I2C) library uses blocking code so either you need to use a non-blocking Wire replacement or bypass the Wire library and use the AVR TWI hardware interface directly, otherwise you risk dropping data while waiting for an EEPRM byte or page write to complete.   On the PC end, use any terminal that supports XON/XOFF handshaking, capture to, and transmission of a file.  As there is no check that whole lines haven't been lost from the Intel HEX file, you also need a verify mode on the Arduino that compares received data against existing EEPROM contents, and repoorts any discrepancies and the total number of bytes checked.
 
The following users thanked this post: cdev

Offline VEGETATopic starter

  • Super Contributor
  • ***
  • Posts: 1946
  • Country: jo
  • I am the cult of personality
    • Thundertronics
Re: Read\Write I2C EEPROM using Arduino (or anything)
« Reply #10 on: July 25, 2017, 02:21:03 pm »
I can confirm that the ones with a black and gold pcb  work.
Search Amazon for CH341A USB Programmer and you'll see the type I mean.
I think there was a minor issue with the software but it's easily fixed and is mentioned on Youtube.
I have no reason to believe the ones you found will not work.

Good luck.

You mean this one right?

https://www.aliexpress.com/item/Free-shipping-Local-tyrants-gold-CH341A-programmer-routing-liquid-crystal-USB-motherboard-BIOS-FLASH-burn-24/32263275388.html

Offline 3db

  • Frequent Contributor
  • **
  • Posts: 331
  • Country: gb
Re: Read\Write I2C EEPROM using Arduino (or anything)
« Reply #11 on: July 25, 2017, 04:01:48 pm »
@VEGETA
Yes that's the one.  :)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf