I2C EEPROM with 28X1

grout56

New Member
Hi All

Can anyone suggest how I can write a very large lookup table to a 256 /512 eeprom

used up much of the available space in the eeprom as a lookup table

and I've only got upto to the scrolled letter "C"

Look's like I need to store large amounts

Any thoughts much appreciated

Groutie
 

Attachments

hippy

Technical Support
Staff member
You could write a number of programs, each of which put an individual character bit map to the external EEPROM, run them one at a time until the EEPROM is loaded.

Each program may be able to hold multiple character bit maps to save on the number of programs to load and run.

A mechanism to specify bit maps on a PC and a program to transfer those to a single program running on the PICAXE would probably be best to minimise effort, but would require suitable programs to do that. A program to visually define the bit maps may also help in creating the raw data required.

What LED display are you using ? Your bit maps requiring 512 bits each seem quite large, 32 x 16 ?
 

Paix

Senior Member
@Hippy, I wisely abandoned a reply . . . I agree with writing the data via serial from a PC to a Picaxe for writing direct to I2C memory. I'm real sure that you needed that level of ressasurance . . . :)

I believe that the characters represent multiple scrolled images. Validating that lot could be a bit of a nightmare. it's more typing but I prefer %10101010 type representation as it is at least a little more direct for comparison purposes when things aren't quite right.
 

hippy

Technical Support
Staff member
I believe that the characters represent multiple scrolled images. Validating that lot could be a bit of a nightmare.
That would make sense. If the scrolling is simply bit-shifting ( didn't try to figure it out ) it may be possible to have one smaller bit map and programmatically generate the others from that, either when creating the bit maps or when it comes to using them. That would minimise the data entry required and/or the space needed to store the bit maps.
 

lbenson

Senior Member
Attached is the lua program I use to send 4K+ html page code to a picaxe for storing in i2c eeprom. The trick is to send 16-byte chunks with enough pauses to let the eeprom be written.

In that program, this code provides the delays:
Code:
      for m = 1, 11 do
        os.execute("dir > nul") -- delay for a while
      end
On a fast PC, you might need to increase the "11" by quite a lot--trial and error will get it right.

Here's the receiving picaxe code, which contains some extraneous stuff as well:
Code:
' 20loadI2CSer flash i2c eeprom over serial

#picaxe 20M2                  ' leg 8: 0V; leg 7: O0, serout, infraout; leg 6: I1, O1, ADC1; leg 

#no_data
#terminal 4800 'turn on terminal after program load
'setfreq M2 ' all baud rates are halved

symbol tcpInPin = c.5 ' b.1

'symbol baudrate=T600_4 ' serial in will be 300 baud
symbol baudrate=T2400_4 ' serial in will be 300 baud
symbol sertxBaud=N2400_4 ' 1200 baud
symbol i2cDevice=%10101110 ' note "111" address
'symbol i2cDevice=%10100000 ' note "000" address
symbol cI2CSpeed=i2cfast

symbol eeprom_Length_Addr=0
symbol htmlLengthAddr=0
symbol eeprom_base=16
symbol htmlBase=16
symbol cHTMLaddrBase=28  ' start of address/length pairs
                         ' for html pages
symbol inputBuffBase=120 ' WARNING! may wrap to b0

'symbol bitFlag=b0
symbol bMatchFlag=bit0
symbol bHTMLEndFlag=bit1

symbol nPages=b15
symbol matchCount=b16 ' if 7, have matched "</html>?
symbol value=b17
symbol n1 = b18

symbol year=b19
symbol month=b20
symbol day=b21
symbol hour=b22
symbol minute=b23

symbol eeprom_addr=w12
symbol addr_low=b24
symbol addr_high=b25
symbol wTemp1=w13
symbol wTemp1Low=b26
symbol wTemp1Hi=b27

symbol i2c_addr=s_w1
symbol i2c_addr_Limit=s_w2
symbol i2c_addr2=s_w3
symbol wHTMLPagePtr=s_w4
symbol wHTMLStartAdr=s_w5
symbol wHTMLlength=s_w6

start:
  pause 8000  ' startup time
'  high 0
'  readtemp b.4,b4
  sertxd("20loadI2CSer on ",#tcpInPin,cr,lf)
  pause 500  ' startup time
  i2cslave %11010000, i2cslow, i2cbyte
'  writei2c 0, ($00, $10, $22, $06, $18, $01, $14, $10) ' smhwdmy
  wHTMLPagePtr = cHTMLaddrBase
  wHTMLStartAdr = htmlBase
  poke wHTMLPagePtr, WORD wHTMLStartAdr
  gosub getDateTime
  gosub loadI2Ceeprom
  pause 5000
  gosub printTemplate
  sertxd("Done",13,10)

main:
  do
    pause 1000
    readtemp b.4,b4
'    sertxd ("Temp ",#b4,13,10)
    sertxd("Temp ",#b4," ")
    pause 1000
  loop

getDateTime:
'#rem
  i2cslave %11010000, i2cslow, i2cbyte
'  writei2c 0, ($00, $06, $17, $01, $09, $12, $13, $10) ' smhwdmy
  pause 40
  gosub getDate
'  sertxd ("Date is ", #year,":",#month,":",#day,13,10)
  sertxd("Date is ", #year,":",#month,":",#day,13,10)
  gosub getTime
'  sertxd ("Time is ", #hour,":",#minute,13,10)
  sertxd("Time is ", #hour,":",#minute,13,10)
  return

getTime:
  readi2c 0, (b1,b2,b3)
'    sertxd ("Getting Time3 ", #n1," ",#n2," ",#n3, 13, 10)
  bcdtoascii b1, b5, b6
'  second = n5-"0"*10+n6-"0"
  b4 = b2
  bcdtoascii b4, b1, b2
  minute = b1-"0"*10+b2-"0"
'sertxd ("n4 n1 n2 minute: ", #n4," ",n1," ",n2," ",#minute, 13, 10)
  bcdtoascii b3, b4, b5
  hour = b4-"0"*10+b5-"0"
  return

getDate:  ' 
  readi2c 4, (b1,b2,b3) ' xxxxdmy
'    sertxd ("Getting Date ", #n1," ",#n2," ",#n3, 13, 10)
  'day = bcdtobin n1
  'month = bcdtobin n2
  'year = bcdtobin n3
  bcdtoascii b1, b5, b6
  day = b5-"0"*10+b6-"0"
  b4 = b2
  bcdtoascii b2, b5, b6
  month = b5-"0"*10+b6-"0"
  bcdtoascii b3, b5, b6
  year = b5-"0"*10+b6-"0"
  return

loadI2Ceeprom:
  hi2csetup i2cmaster,i2cDevice, cI2CSpeed, i2cword
  eeprom_addr=eeprom_base
'  sertxd ("Load to ",#eeprom_addr,13,10)
  b0 = i2cDevice / 2 & %00000111
  sertxd("Load to ",#eeprom_addr,"; I2C device ",#b0,13,10)
'  serout tcpOutPin, baudrate, ("14LoadI2C ",13,10)

  do
    serin tcpInPin, baudrate, b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15
'    sertxd (b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15)
    sertxd(b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15)
'    writei2c eeprom_addr, (b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15)
    hi2cout eeprom_addr, (b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15)
    eeprom_addr = eeprom_addr + 16
    pause 10
    if b15 = 0 then
      bptr = 15
'      b15 = @bptrdec
      if b0 > 0 then
        do while @bptrdec = 0 and bptr > 0 : dec eeprom_addr : loop
      endif
'      eeprom_addr = eeprom_addr - 16
      hi2cout eeprom_Length_Addr, (addr_low,addr_high)
'      sertxd (cr,lf,#eeprom_addr," bytes written",cr,lf)
      sertxd(cr,lf,#eeprom_addr," bytes written",cr,lf)
      pause 2000
      exit
    endif
    pause 40
  loop
  return

 printTemplate:
'#rem
'  i2cslave i2cDevice, i2cfast, i2cword
  hi2csetup i2cmaster,i2cDevice, cI2CSpeed, i2cword
  value = $fe
  i2c_addr = htmlLengthAddr  ' Length of html code
  hi2cin i2c_addr, (wTemp1Low,wTemp1Hi)
  i2c_addr_Limit = wTemp1 + 16 +16 ' don't read past this address
  i2c_addr = htmlBase  ' start of html with embedded "~nn" variables
  sertxd("HTML Template: base, length ",#i2c_addr," ",#wTemp1,cr,lf)
  'i2c_addr = 0
  do while value <> 0 and value <> $ff and i2c_addr < i2c_addr_Limit
    gosub readI2Cbuff
    bptr = bptr - 16
    for n1 = 1 to 16
      if  bHTMLEndFlag = 1 then
        bHTMLEndFlag= 0
        i2c_addr2 = i2c_addr - 16 + bptr - inputBuffBase
        hi2cout i2c_addr2, (0) ' null terminate the html code
        inc nPages ' add to the web page count
        peek wHTMLPagePtr, WORD wHTMLStartAdr
        wHTMLlength = i2c_addr2 - wHTMLStartAdr
        wHTMLPagePtr = wHTMLPagePtr + 2
        poke wHTMLPagePtr, WORD wHTMLlength
        wHTMLPagePtr = wHTMLPagePtr + 2
        inc i2c_addr2
        poke wHTMLPagePtr, WORD i2c_addr2 ' start of next page, if any
      endif
      bMatchFlag = 0
      select matchCount
        case 0
          if @bptr = "<" then : bMatchFlag=1 : endif
        case 1
          if @bptr = "/" then : bMatchFlag=1 : endif
        case 2
          if @bptr = "h" then : bMatchFlag=1 : endif
        case 3
          if @bptr = "t" then : bMatchFlag=1 : endif
        case 4
          if @bptr = "m" then : bMatchFlag=1 : endif
        case 5
          if @bptr = "l" then : bMatchFlag=1 : endif
        case 6
          if @bptr = ">" then ' complete match 
            bHTMLEndFlag=1
          endif
      endselect
      if bMatchFlag = 1 then
        inc matchCount
      else
        matchCount = 0
      endif
      if @bptrinc = 0 then
	  dec bptr  ' point back to null
	  value = 0
	  do while n1 <= 16 : @bptrinc = " " : inc n1 loop
	endif
    next n1
    bptr = bptr - 16
    sertxd(@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc, _
      @bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptr)
  loop
  ' write the length of the last web page
        i2c_addr2 = i2c_addr - 16 + bptr - inputBuffBase
        inc nPages ' add to the web page count
        peek wHTMLPagePtr, WORD wHTMLStartAdr
        wHTMLlength = i2c_addr2 - wHTMLStartAdr
        wHTMLPagePtr = wHTMLPagePtr + 2
        poke wHTMLPagePtr, WORD wHTMLlength
  sertxd(cr,lf)
'#endrem
  return

readI2Cbuff:
  bptr = inputBuffBase
  hi2cin i2c_addr, (@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc, _
    @bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc)
  i2c_addr=i2c_addr+16
  return
Lua is a free download for PCs & Linux devices. It might take some fiddling to get this right, but it has worked for me.
 

Attachments

westaust55

Moderator
In the past I have written a PICAXE BASIC program using the full program space to write data such as bitmap character sets for Nokia phone displays. One program can hold the data for many characters but it may require several BASIC programs to hold all the required data to write to EEPROM. Some examples have been posted in the past in threads for Nokia graphic LCD display threads if you care to search for them.

Typically writing blocks of 16 bytes at a time will ensure that you do not have problems trying to write across EEPROM chip page boundaries (where the EEPROM internal address pointer rolls over at each page end with multi byte writes).
 
Top