multiple i2c EEPROMs + SIMULATOR read problem

GreenLeader

Senior Member
Hi - I am having some problems with the simulator V5.1.7 and 40X1 - is there a bug in the simulator or in my code?

My test program does following:
Writes some values to EEPROM 0 (1,2,3 and 2,3,4)
Write some different values to EEPROM 1 (101,102,103 and 102,103,104)
Read them back and display with serout

In the simulator, the values for EEPROM 1 are correct, but EEPROM 0 are same as EEPROM 1

I'd appreciate any comments - perhaps someone could test it on their simulator? I haven't progressed to testing on hardware yet..

Code:
#PICAXE 40X1
' Program to test i2c write/read with 2 EEPROMs 
  
' Setup i2c 2x24LC256 EEPROMS
hi2csetup i2cmaster,%10100000,i2cfast,i2cword 'EEPROM addr 0
hi2csetup i2cmaster,%10100010,i2cfast,i2cword 'EEPROM addr 1

' Write some data to first EEPROM
' *******************************
w1 = 1
w2 = 2
w3 = 3
for w13 = 1 to 10 step 6
    hi2cout [%10100000],w13,(b2,b3,b4,b5,b6,b7)    'EEPROM addr 0
    inc w1
    inc w2
    inc w3
next
    
' Write some different data to second EEPROM
' ******************************************
w1 = 101
w2 = 102
w3 = 103
for w13 = 1 to 10 step 6
    hi2cout [%10100010],w13,(b2,b3,b4,b5,b6,b7)    'EEPROM addr 0
    inc w1
    inc w2
    inc w3
next

' read the data back and send to serout
' *************************************
serout 7,N4800,("EEPROM 0 ",13)
for w13 = 1 to 10 step 6
    hi2cin [%10100000],w13,(b2,b3,b4,b5,b6,b7)    'EEPROM addr 0
    serout 7,N4800,(#w1,44,#w2,44,#w3,13)
next

serout 7,N4800,("EEPROM 1 ",13)
for w13 = 1 to 10 step 6
    hi2cin [%10100010],w13,(b2,b3,b4,b5,b6,b7)    'EEPROM addr 0
    serout 7,N4800,(#w1,44,#w2,44,#w3,13)
next
 

Technical

Technical Support
Staff member
The simulator only supports a single EEPROM and ignores the address bits, so you cannot simulate multiple devices.

You don't need two hi2csetup lines, one would be enough as you change the address during the actual hi2c command.
 

GreenLeader

Senior Member
Thanks - that explains it then! (Is there a manual for the simulator that clarifies these type of issues? I have not been able to find anything)

This means that I can't verify code that uses a variable for the EEPROM i2c address. Is this permitted? Would you mind looking at this code to confirm that my approach is valid:
* use variable to specify EEPROM (24LC256) address
* increment the address by decimal 2 to select next EEPROM

The code runs in simulator, but that is meaningless if the simulator is ignoring the EEPROM addrees in the hi2cout cmd :)

Code:
#PICAXE 40X1
' Program to test use of variable to select EEPROM i2c address
symbol memadr= b25 ' EEPROM memory address variable
memadr = %10100000 ' EEPROM address 0
hi2csetup i2cmaster,memadr,i2cfast,i2cword
' write to EEPROM 0
w1=1
w2=2
hi2cout [memadr],1,(b2,b3,b4,b5)
memadr = memadr + 2 'increment EEPROM address pointer
 
' write to EEPROM 1
w1=10
w2=20
hi2cout [memadr],1,(b2,b3,b4,b5)
 
Top