text file to eeprom

jackberg

New Member
Hello everyone,

Here is a request about transferring data from an "ascii" text file to an eeprom like 24C256/512 on I2C networks

The file contains 500 records like this: line 1 to 500.

100000xxxxxddddddddddddddDDDDDDppppppppssssxxxxxxxxxx
100001xxxxxddddddddddddddDDDDDDppppppppssssxxxxxxxxxx

""
""
""
100500xxxxxddddddddddddddDDDDDDppppppppssssxxxxxxxxxx

is it possible to transfer in a simple way the records to an eeprom 24C256/512

Thanks in advance.
 
You would either need an EEPROM programmer to do that or you could build your own EEPROM programmer with a PicAxe! The second option should be an easy and project to do with a PicAxe.
 
You would either need an EEPROM programmer to do that or you could build your own EEPROM programmer with a PicAxe! The second option should be an easy and project to do with a PicAxe.
I have a T48 programmer, can you suggest a solution, have you done this before and how. thanks for your time.
 
I you wantto use your programmer you need to read the device' manual to figure this out. You will also need to install the software needed for the programmer.
 
I you wantto use your programmer you need to read the device' manual to figure this out. You will also need to install the software needed for the programmer.
I do use on a daily basis my programmer for eeprom, TTL,CMOS, IC.
my request is mostly for someone on this forum who had in the pass any experience about transfering text to eeprom.
thank you for your comment.

Also many thanks to PhilHornby I did read about it, and thanks to westaust55 to saved info's since the link are not working anymore.

 
I wrote a program for a 20x2 and a companion app in Python to push a text file to an eeprom ... then, the 20x2 will pull random sentences from the load and send them out the serial port ... My thought was to have the PICAXE just sitting there throwing out random quotes .... here's the code for both, you can probably pull the bits and pieces you need to load your file.


Here's the 20x2 code ...

Code:
#picaxe 20x2
#no_data
#no_table

#rem

This is done using the HSERIN on the 20x2 .... so pins 10 and 12. It takes 8.3 seconds
to push the full contents into the EEPROM ... which is pretty damn fast!

Although a menu is displayed on the serial output, you can't make menu entries unless you're
using the HSERIN pins; as it's configured to take input from there (the Python program needs
to be able to start the transaction).

The 08M2 program does the same thing, but does NOT use HSERIN ... so is constrained to a
slower baud ... deals with "disconnect" and "reconnect" for downloads, and takes around 70
seconds to fully load the eeprom ... still, not bad.

The loading is done in 64k or 128k chunks; so 'page writes' to the eeprom; which will help
extend the eeprom life.

If serial monitor is hooked up, the chip will output a random sentence from the eeprom load
ever 25 seconds or so ... it should do that around 30 times, then show the menu again...
If you hook up to the HSER pins, you can send a "D" to dump the entire contents of the eeprom


'  A Standard Picaxe 20x2        
'                                       __________
'                           5V VCC   1- |        |- 20  0V GND
'                        Serial In   2- |        |- 19  A.0 / Serial Out
'                      ADC 3 / C.7   3- |  20X2  |- 18  B.0 / ADC 1 / hint1
'                              C.6   4- |        |- 17  B.1 / ADC 2 / hint2 / SRQ
'           hpwm A / pwm C.5 / C.5   5- |        |- 16  B.2 / ADC 4 / C2+
'              hpwm B / SRNQ / C.4   6- |        |- 15  B.3 / ADC 5 / C2-
'             hpwm C / ADC 7 / C.3   7- |        |- 14  B.4 / ADC 6 / hpwm D / C1-
'             kb clk / ADC 8 / C.2   8- |        |- 13  B.5 / ADC 10 / hi2c sda / hspi sdi
' hspi sdo / kb data / ADC 9 / C.1   9- |        |- 12  B.6 / ADC 11 / hserin
'                    hserout / C.0  10- |        |- 11  B.7 / hi2c scl / hspi sck
'                                       ----------

'          
'                                       __________
'                           5V VCC   1- |        |- 20  0V GND
'                        Serial In   2- |        |- 19  A.0 / Serial Out
'                              C.7   3- |  20X2  |- 18  B.0 RED LED
'                              C.6   4- |        |- 17  B.1
'                              C.5   5- |        |- 16  B.2
'                              C.4   6- |        |- 15  B.3
'                              C.3   7- |        |- 14  B.4
'                              C.2   8- |        |- 13  B.5 hi2c sda
'                  BLUE LED    C.1   9- |        |- 12  B.6 hserin
'                   hserout    C.0  10- |        |- 11  B.7 hi2c scl
'                                       ----------
' '
' Available Bytes: b0 - b55
' Available Words: w0 - w27



Byte    Byte Variable    Word Variable    Word
B0    endSentence                    W0
B1          

B2    eeprom_Byte                    W1
B3    serData

B4    serLoops                    W2
B5    menuCounter

B6    tempByte                    W3
B7    failure      

B8    goodMark                    W4
B9          

B10                            W5
B11      

B12                            W6
B13  

B14                            W7
B15          

B16                            W8
B17          

B18                            W9
B19      

B20                             W10
B21      

B22                tempRandom        W11
B23          

B24                eeprom_address    W12
B25          

B26                tempWord         W13
B27          

B28                            W14
B29      

B30                            W15
B31      

B32                            W16
B33          

B34                            W17
B35          

B36                            W18
B37          

B38                             W19
B39      

B40                            W20
B41  

B42                            W21
B43          

B44                            W22
B45          

B46                            W23
B47      

B48                            W24
B49              

B50                            W25
B51  

B52                            W26
B53          

B54                    Counts    W27
B55          

#endrem


' symbol D1 = b.0    ' RED
' symbol D2 = c.1    ' BLUE

symbol LED = c.1                                ' BLUE LED

symbol endSentence = bit0
symbol eeprom_byte = b2
symbol serData = b3
symbol ser_loops = b4
symbol menuCounter = b5
symbol tempByte = b6
symbol failure = b7
symbol goodMark = b8
symbol tempRandom = w11
symbol eeprom_address = w12
symbol tempWord = w13
symbol counts = w27

' Credit Hippy for below ... a cleaner way to hi2cout 128 individual bytes...

#define WR4        @ptrinc, @ptrinc, @ptrinc, @ptrinc      
#define WR16    WR4, WR4, WR4, WR4
#define WR64    WR16, WR16, WR16, WR16
#define WR128    WR64, WR64

Setfreq m64                                    ' Rock and Roll!
#define pinBaud A.0,N19200_64
#define eeprom_ID    %10100000


hi2csetup i2cmaster, eeprom_ID, i2cfast_64, i2cword
hsersetup b115200_32, %00001


readadc10 LED,tempRandom;                             ' Get initial seed value into random

' pause 2000                                ' Time to download code if needed... Not disconnecting; not needed

main:
    counts = 0
    menuCounter = 0
    gosub greeting:
   
    do
   
        gosub getInput:
            if @ptr = "D" then                ' Dump Eeprom
                @ptr = 0;
                gosub eepromDump:
            else if @ptr = "W" then                ' Write to eeprom
                @ptr = 0;
                gosub receiveAll:
                exit                        ' Bail from the loop ...
            else if @ptr = 0 then
                serData = 0;
            else
                @ptr = 0;
                serData = "R"                ' Not valid entry; so "R" for reset
            endif

       

    counts = counts + 1
       
    if counts > 200 then                        ' 200 loops = ~25sec at 64mhz
        gosub randomSentence:
        menuCounter = menuCounter + 1
        toggle LED
        counts = 0
    endif
    if menuCounter > 30 then                    ' reset loop;
        menuCounter = 0
        exit
    endif
           
    loop while serData <> "R"                    ' If "R" then go back to main; display greeting


goto main:
   
   
   
   
readData:

        hi2cin eeprom_address,(eeprom_byte)

return

randomSentence:
    endSentence = 0;
    do
        random tempRandom;
    loop while tempRandom > 65534;

    eeprom_address = tempRandom;
    goodMark = 0
    do
        eeprom_address = eeprom_address + 1
        gosub readData
        if eeprom_byte = "." OR eeprom_byte = "?" then
            goodMark = 1
        endif
       
    loop while goodMark = 0
   
    eeprom_address = eeprom_address + 2                ' skip the space
   
    do
        gosub readData
        serout pinBaud,(eeprom_byte);
        if endSentence = 1 AND eeprom_byte = 34 then
            return
        endif
   
        if endSentence = 1 AND eeprom_byte <> " " then
            eeprom_byte = " "
        endif
   
       
        if eeprom_byte = "." OR eeprom_byte = "?" then let endSentence = 1
        endif
       
        eeprom_address = eeprom_address + 1
       
    loop until eeprom_byte = " " AND endSentence = 1
   
    serout pinBaud,(CR,LF);

return


greeting:

    serout pinBaud,(CR,LF,"Hello There...",cr,lf)
    serout pinBaud,("Enter 'D' For Dump of eeprom",cr,lf);
    serout pinBaud,("Enter 'W' to write to eeprom",cr,lf);
    serout pinBaud,("Enter 'R' to re-enable downloads",cr,lf);
    serout pinBaud,(">");
   
return

eepromDump:

    for eeprom_address = 0 to 65534                ' 32767 for 256k, 65534 for 512k      
        gosub readData
        serout pinBaud,(eeprom_byte)
    next eeprom_address
   
return

getInput:
   
    serData = 0;
    hserin [2000],0,1
    ptr = 0

return

receivePage:
   
    failure = 0;
    hserptr = 0;
    ptr = 0;
   
    hserout 0,("G")                            ' 71 is G for "GO"!

    hserin 0,128                            ' Bring in 128 bytes store starting at Scratchpad 0

    if hserptr <> 0 then                        ' 64 works for 64 bytes '0' means we rolled over from 127 ... so 128 bytes rcvd.
'        hserout 0,(#ptr)
'        hserout 0,(#hserptr)
        hserout 0,("W")                        ' 87 = W for "Wait a sec, this is screwed up!"
        failure = 1
        return
    endif
   
    hserptr = 0
    ptr = 0                                ' Reset the pointer to 0 ... reading the full scratchpad
    hi2cout eeprom_address, (WR128)                ' Send 128 bytes to i2c see Defines above
   

return

receiveAll:
    eeprom_address = 0x0000

    for tempWord = 0 to 511
        gosub receivePage:

        if failure = 0 then
            eeprom_address = eeprom_address + 128    ' should be 128 for 512k 64 for 256...
        else
            tempWord = tempWord - 1
        endif
       
    next tempWord
    hserout 0, ("D")                            ' 68 is D for Done


return
 
Last edited:
Here's the Python code ...

Code:
#!/usr/bin/python3

import os
import time
import datetime
import serial.tools.list_ports
import struct
from datetime import datetime
import sys, getopt


# Confirm file exists ...
# Loop 512 times ...

pagesize = 128
#book = "The Art of War.txt"

def accurate_delay(delay):
    ''' Function to provide accurate time delay in millisecond
    '''
    _ = time.perf_counter() + delay/1000
    while time.perf_counter() < _:
        pass

def endProg():
    input('Press ENTER to exit')
    sys.exit()


def main(argv):

    if len(sys.argv) < 2:
        print ("Argument missing ... abort")
        print ("use: TxtLoader.py -w filename.txt")
        endProg()

    command = sys.argv[1]

    try:
        opts, args = getopt.getopt(argv, "hw", ["help", "write"])
    except getopt.GetoptError:
        print ("Use -w or --write and filename")
        endProg()
    if command in ('-h', "--help"):
        print ("Help: Use -w or --write wtih a file-name")
        endProg()
    elif command in ("-w", "--write"):
        if len(sys.argv) < 3:
            print ("Argument missing ... abort")
            print ("use: program -w filename.txt")
            endProg()
        book = sys.argv[2]
        print ("We will work with file: ",book)
 
    
    if not os.path.exists(book):
        print ('No txt file to upload; aborting.')
        endProg()  # no file? Abort

    infile = open(book,"r",encoding="utf8")

    #ports = list(serial.tools.list_ports.comports())
    #for p in ports:
    try:
        #print (p)
        ser = serial.Serial('COM5', 230400, timeout=1)
        ser.close()
        ser.open()
        ser.write(str.encode('W'))
        time.sleep(.2)
        totalbytes = 0
        x = 0
        start = time.time()
        while x < 513:
            foo = ser.read()
     #       print (foo)
            if foo == b'W':
                for byte in data:
                    ser.write (byte.encode())
                    accurate_delay(2)
                x -= 1
                totalbytes -= pagesize
                ser.flushOutput()
                print ('Resent Page: ',x)
     #           print (data)
                x += 1
            elif foo == b'G':      # G for GO
                data =(infile.read(pagesize))
                ser.write (data.encode())
                
    #            for byte in data:
    #                ser.write (byte.encode())
     #               accurate_delay(2)
                ser.flushOutput()
                print ('Sent Page: ',x, ' ',totalbytes,' bytes')
     #           print (data)
                x += 1
                totalbytes += pagesize
     #           time.sleep(.001)
            elif foo == b'D':     # D for Done
                print ('Done message received...')
                break
            else:
                print ('NO or Improper response at page: ',x)

        ser.close()
        end = time.time()
        print ("Elapsed Time: ",end-start)
        print ("Total bytes sent: ",totalbytes)
        
        
    except serial.SerialException:
        Continue
        
    infile.close()
    endProg()

if __name__== "__main__":
        main(sys.argv[1:])
 
I wrote a program for a 20x2 and a companion app in Python to push a text file to an eeprom ... then, the 20x2 will pull random sentences from the load and send them out the serial port ... My thought was to have the PICAXE just sitting there throwing out random quotes .... here's the code for both, you can probably pull the bits and pieces you need to load your file.


Here's the 20x2 code ...

Code:
#picaxe 20x2
#no_data
#no_table

#rem

This is done using the HSERIN on the 20x2 .... so pins 10 and 12. It takes 8.3 seconds
to push the full contents into the EEPROM ... which is pretty damn fast!

Although a menu is displayed on the serial output, you can't make menu entries unless you're
using the HSERIN pins; as it's configured to take input from there (the Python program needs
to be able to start the transaction).

The 08M2 program does the same thing, but does NOT use HSERIN ... so is constrained to a
slower baud ... deals with "disconnect" and "reconnect" for downloads, and takes around 70
seconds to fully load the eeprom ... still, not bad.

The loading is done in 64k or 128k chunks; so 'page writes' to the eeprom; which will help
extend the eeprom life.

If serial monitor is hooked up, the chip will output a random sentence from the eeprom load
ever 25 seconds or so ... it should do that around 30 times, then show the menu again...
If you hook up to the HSER pins, you can send a "D" to dump the entire contents of the eeprom


'  A Standard Picaxe 20x2       
'                                       __________
'                           5V VCC   1- |        |- 20  0V GND
'                        Serial In   2- |        |- 19  A.0 / Serial Out
'                      ADC 3 / C.7   3- |  20X2  |- 18  B.0 / ADC 1 / hint1
'                              C.6   4- |        |- 17  B.1 / ADC 2 / hint2 / SRQ
'           hpwm A / pwm C.5 / C.5   5- |        |- 16  B.2 / ADC 4 / C2+
'              hpwm B / SRNQ / C.4   6- |        |- 15  B.3 / ADC 5 / C2-
'             hpwm C / ADC 7 / C.3   7- |        |- 14  B.4 / ADC 6 / hpwm D / C1-
'             kb clk / ADC 8 / C.2   8- |        |- 13  B.5 / ADC 10 / hi2c sda / hspi sdi
' hspi sdo / kb data / ADC 9 / C.1   9- |        |- 12  B.6 / ADC 11 / hserin
'                    hserout / C.0  10- |        |- 11  B.7 / hi2c scl / hspi sck
'                                       ----------

'         
'                                       __________
'                           5V VCC   1- |        |- 20  0V GND
'                        Serial In   2- |        |- 19  A.0 / Serial Out
'                              C.7   3- |  20X2  |- 18  B.0 RED LED
'                              C.6   4- |        |- 17  B.1
'                              C.5   5- |        |- 16  B.2
'                              C.4   6- |        |- 15  B.3
'                              C.3   7- |        |- 14  B.4
'                              C.2   8- |        |- 13  B.5 hi2c sda
'                  BLUE LED    C.1   9- |        |- 12  B.6 hserin
'                   hserout    C.0  10- |        |- 11  B.7 hi2c scl
'                                       ----------
' '
' Available Bytes: b0 - b55
' Available Words: w0 - w27



Byte    Byte Variable    Word Variable    Word
B0    endSentence                    W0
B1         

B2    eeprom_Byte                    W1
B3    serData

B4    serLoops                    W2
B5    menuCounter

B6    tempByte                    W3
B7    failure     

B8    goodMark                    W4
B9         

B10                            W5
B11     

B12                            W6
B13 

B14                            W7
B15         

B16                            W8
B17         

B18                            W9
B19     

B20                             W10
B21     

B22                tempRandom        W11
B23         

B24                eeprom_address    W12
B25         

B26                tempWord         W13
B27         

B28                            W14
B29     

B30                            W15
B31     

B32                            W16
B33         

B34                            W17
B35         

B36                            W18
B37         

B38                             W19
B39     

B40                            W20
B41 

B42                            W21
B43         

B44                            W22
B45         

B46                            W23
B47     

B48                            W24
B49             

B50                            W25
B51 

B52                            W26
B53         

B54                    Counts    W27
B55         

#endrem


' symbol D1 = b.0    ' RED
' symbol D2 = c.1    ' BLUE

symbol LED = c.1                                ' BLUE LED

symbol endSentence = bit0
symbol eeprom_byte = b2
symbol serData = b3
symbol ser_loops = b4
symbol menuCounter = b5
symbol tempByte = b6
symbol failure = b7
symbol goodMark = b8
symbol tempRandom = w11
symbol eeprom_address = w12
symbol tempWord = w13
symbol counts = w27

' Credit Hippy for below ... a cleaner way to hi2cout 128 individual bytes...

#define WR4        @ptrinc, @ptrinc, @ptrinc, @ptrinc     
#define WR16    WR4, WR4, WR4, WR4
#define WR64    WR16, WR16, WR16, WR16
#define WR128    WR64, WR64

Setfreq m64                                    ' Rock and Roll!
#define pinBaud A.0,N19200_64
#define eeprom_ID    %10100000


hi2csetup i2cmaster, eeprom_ID, i2cfast_64, i2cword
hsersetup b115200_32, %00001


readadc10 LED,tempRandom;                             ' Get initial seed value into random

' pause 2000                                ' Time to download code if needed... Not disconnecting; not needed

main:
    counts = 0
    menuCounter = 0
    gosub greeting:
  
    do
  
        gosub getInput:
            if @ptr = "D" then                ' Dump Eeprom
                @ptr = 0;
                gosub eepromDump:
            else if @ptr = "W" then                ' Write to eeprom
                @ptr = 0;
                gosub receiveAll:
                exit                        ' Bail from the loop ...
            else if @ptr = 0 then
                serData = 0;
            else
                @ptr = 0;
                serData = "R"                ' Not valid entry; so "R" for reset
            endif

      

    counts = counts + 1
      
    if counts > 200 then                        ' 200 loops = ~25sec at 64mhz
        gosub randomSentence:
        menuCounter = menuCounter + 1
        toggle LED
        counts = 0
    endif
    if menuCounter > 30 then                    ' reset loop;
        menuCounter = 0
        exit
    endif
          
    loop while serData <> "R"                    ' If "R" then go back to main; display greeting


goto main:
  
  
  
  
readData:

        hi2cin eeprom_address,(eeprom_byte)

return

randomSentence:
    endSentence = 0;
    do
        random tempRandom;
    loop while tempRandom > 65534;

    eeprom_address = tempRandom;
    goodMark = 0
    do
        eeprom_address = eeprom_address + 1
        gosub readData
        if eeprom_byte = "." OR eeprom_byte = "?" then
            goodMark = 1
        endif
      
    loop while goodMark = 0
  
    eeprom_address = eeprom_address + 2                ' skip the space
  
    do
        gosub readData
        serout pinBaud,(eeprom_byte);
        if endSentence = 1 AND eeprom_byte = 34 then
            return
        endif
  
        if endSentence = 1 AND eeprom_byte <> " " then
            eeprom_byte = " "
        endif
  
      
        if eeprom_byte = "." OR eeprom_byte = "?" then let endSentence = 1
        endif
      
        eeprom_address = eeprom_address + 1
      
    loop until eeprom_byte = " " AND endSentence = 1
  
    serout pinBaud,(CR,LF);

return


greeting:

    serout pinBaud,(CR,LF,"Hello There...",cr,lf)
    serout pinBaud,("Enter 'D' For Dump of eeprom",cr,lf);
    serout pinBaud,("Enter 'W' to write to eeprom",cr,lf);
    serout pinBaud,("Enter 'R' to re-enable downloads",cr,lf);
    serout pinBaud,(">");
  
return

eepromDump:

    for eeprom_address = 0 to 65534                ' 32767 for 256k, 65534 for 512k     
        gosub readData
        serout pinBaud,(eeprom_byte)
    next eeprom_address
  
return

getInput:
  
    serData = 0;
    hserin [2000],0,1
    ptr = 0

return

receivePage:
  
    failure = 0;
    hserptr = 0;
    ptr = 0;
  
    hserout 0,("G")                            ' 71 is G for "GO"!

    hserin 0,128                            ' Bring in 128 bytes store starting at Scratchpad 0

    if hserptr <> 0 then                        ' 64 works for 64 bytes '0' means we rolled over from 127 ... so 128 bytes rcvd.
'        hserout 0,(#ptr)
'        hserout 0,(#hserptr)
        hserout 0,("W")                        ' 87 = W for "Wait a sec, this is screwed up!"
        failure = 1
        return
    endif
  
    hserptr = 0
    ptr = 0                                ' Reset the pointer to 0 ... reading the full scratchpad
    hi2cout eeprom_address, (WR128)                ' Send 128 bytes to i2c see Defines above
  

return

receiveAll:
    eeprom_address = 0x0000

    for tempWord = 0 to 511
        gosub receivePage:

        if failure = 0 then
            eeprom_address = eeprom_address + 128    ' should be 128 for 512k 64 for 256...
        else
            tempWord = tempWord - 1
        endif
      
    next tempWord
    hserout 0, ("D")                            ' 68 is D for Done


return
Many thanks for your help, I'll surely work on the 20x2 code, and fit it with my project.
 
Back
Top