Read write external data to 24c256and 24c16 help

lamxe

Senior Member
send to forum.JPG
Code:
         ; ###########  original code on ours forum #########
               ;///////////////////////////////////////////
#PICAXE 28X2
'
Symbol i2cAddr24LC256 = %10100000  'For i2c address details, refer to Manual 2 "hi2csetup"

b0 = 0	'Initialise byte variables
b1 = 1
b2 = 2
b3 = 3
'
hi2cSetup i2cMaster, i2cAddr24LC256, i2cFast, i2cWord
Do
   hi2cOut 0,(b0, b1, b2, b3) 'Write values to bytes 0-4 of EEPROM
   Pause 50
   Inc b0
   Inc b1
   Inc b2
   Inc b3
   hi2cIn 0, (b4, b5, b6, b7) 'Read values back from EEPROM
   Debug
   Pause 2000                 'Wait 2 seconds
Loop

   ;///////////////////////////////////////////////////////////////////////////
   
                         ; My copied and added  code
                         
                          
                          #PICAXE-18m2; 20m2 ;14m2
'
Symbol i2cAddr24LC256 = %10100000  'For i2c address details, refer to Manual 2 "hi2csetup"

b0 = 0	'Initialise byte variables
b1 = 1
b2 = 2
b3 = 3
xxxxxxxxxxxx (1)

hi2cSetup i2cMaster, i2cAddr24LC256, i2cFast, i2cWord
main:
    if pinc.1 = 0 and pinc.0 = 0 then goto main
    if pinc.1 = 1 and pinc.0 = 0 then goto rea
    if pinc.1 = 1 and pinc.0 = 1 then goto writ
Writ:
               ;
   hi2cOut 0,(b0, b1, b2, b3,xxxxxxxx (2) 'Write values to bytes 0-4 of EEPROM
    Pause 50
   Inc b0
   Inc b1
   Inc b2
   Inc b3
 
         
           if bx or Wx  = XXXX (3) then end high B.3,;  detect reach at full memory  by led
   

Rea:
   hi2cIn 0, (b4, b5, b6, b7 xxxxxxxx) 'Read values back from EEPROM 
   Debug
   Pause 2000             'Wait 2 seconds
goto main
                           ;##########################
     
    ; This code can run with 20m2.18m2.14m2 or not please .
    ; Please give me  value  "b" at   XXXXXXX  (3 place ).Thank you so much
Dear All..
I would like to build the circuit for learning programming serial eeprom .But my solderless breadboard has been broken by my new dog ,in the time waiting order the new to come. Please could you help me to know this code can running with my circuit if yes please help me more to know : what value of " b" I must add set for read and write full (all) memory in 24c16 and 24c256 .
Sincerely many thank you.
lamxe
//////////////////////////////////////////////////////
# hi2cOut 0,(b0, b1, b2, b3 ??? ) 'Write values to bytes 0-4 of EEPROM *
#hi2cIn 0, (b4, b5, b6, b7???) 'Read values back from EEPROM
# if bx or Wx = XXXX (3) then end high B.3,; detect reach at full memory by led
Please help me to know values of "b" W. many thank you
 

hippy

Technical Support
Staff member
What you would normally do is write a single value to an EEPROM address, increment the address and write another byte. It is possible to write more than one byte at a time and adjust the address by incrementing by the number of bytes written.
 

lamxe

Senior Member
Dear Hippy
First thank you for your reply. I am sorry and I know to make (data in) is bad , but I want fast way to see eeprom can work with my code or not if good I will use this code for other project in future . Thank you so much
 

BeanieBots

Moderator
It's a little confusing to know exactly what you want to do. Are trying to test the EEPROM device or to work out what size it is?
To take your code literally, you would need to go up to b32768 to test all locations on a 24LC256. Obviously, that is not possible.
That type of approach will not work anyway, because if the address is larger than the EEPROM, it will "wrap around" and read/write to a lower address.
Hence, what you write will be read back OK, but what you will not know is that it has overwritten a lower address location.

Maybe I have miss-understood what you are trying to do.
 

lamxe

Senior Member
Dear BeanieBots
With my low basic W and b , I think is easy (except me) programing for test read write and stop(end) at full size eeprom (24cXX) Now I understand not easy to make that.
Sincerely thank you for your concern and advise me
 

BeanieBots

Moderator
I hope my explanation was clear. If not, do not hesitate to ask.
Please read the datasheet for YOUR EEPROM carefully. There are other issues you need to be aware of when you write multiple bytes in one write operation.
EEPROMs have what are called "page boundaries". If you write one byte at a time, you do not need to worry about them. If you write blocks of data, you need to know where they start and end but they are different for each type/size of EEPROM.
Also, be aware of write times. You must allow the EEPROM to finish writing before you try to read it back. Again, see the datasheet.
 

hippy

Technical Support
Staff member
Here is some (untested) code which will fill a 24LC256 EEPROM with 32768 analogue readings.

Code:
Symbol address   = w1 ; b3:b2
Symbol dataValue = b4

Main:
  HI2cSetup I2CMASTER, $A0, I2CSLOW, I2CWORD
  address = 0

  Do
    ReadAdc C.1, dataValue
    HI2cOut address, ( dataValue )
    Pause 20
    address = address + 1   
  Loop Until address >= 32768

Full:
  End
That should work for any word-addressed EEPROM and any byte-addressed EEPROM of up to 256 byte size. Byte-addressed EEPROM larger than 256 bytes size is more complicated.

The following (untested) code should write 2048 readings into a 24LC16 -

Code:
Symbol address    = w1 ; b3:b2
Symbol dataValue  = b4
Symbol i2cAddress = b5
Symbol lsbAddress = b6

Main:
  address = 0

  Do
    ReadAdc C.1, dataValue
    i2cAddress = address / 256 * 2 | $A0
    lsbAddress = address & 255
    HI2cSetup I2CMASTER, i2cAddress, I2CSLOW, I2CBYTE
    HI2cOut lsbAddress, ( dataValue )
    Pause 20
    address = address + 1   
  Loop Until address >= 2048

Full:
  End
 

lamxe

Senior Member
Dear Hippy ,BeanieBots ,Texasclodhopper
Thank you alot for being patient and helping me with best support.
Best regards
lamxe
 

lamxe

Senior Member
Symbol address = w1 ; b3:b2
Symbol dataValue = b4
Symbol i2cAddress = b5
Symbol lsbAddress = b6

Main:
address = 0

Do
ReadAdc C.1, dataValue
i2cAddress = address / 256 * 2 | $A0
lsbAddress = address & 255
HI2cSetup I2CMASTER, i2cAddress, I2CSLOW, I2CBYTE
HI2cOut lsbAddress, ( dataValue )
Pause 20
address = address + 1
Loop Until address >= 2048

Full:
End
Dear Hippy
Sincerely thank you for your reply and please forget my old question.
Sir. I have used original code with 18m2 + 24c16
Sir. send to hippy.JPGIt's bad idea but I have tried connector DATA IN and DATA out to different port in picaxe 18m2 ( C.1 , B.2 and B.5) but led all time turn off. With don't care overwrite and other problem just for learning how read write eeprom with picaxe code.Please coud you again help me to know where connect data in and data out to picaxe 18 m2. Thank you so much for your time .
Best regards
lamxe
 
Last edited:

hippy

Technical Support
Staff member
Post your full code, circuit diagram, and photo of your set-up, and it will be easier to figure out what is going wrong.

The code was untested so there may be issues with it. It would probably be best to start storing known numbers into just one byte of a 24LC16, then within one page, then move on to storing more data in multiple pages
 
Top