News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Reading 24c256 eeprom with Amicus18

Started by broderic, Apr 23, 2021, 05:47 PM

Previous topic - Next topic

broderic

Hello.
I wrote 5 numbers on the eeprom, and it works, when I reading during writing cycle.
But when I read again, only reading, I have only the last value correct, others are 0s:
Include "Amicus18.inc"
 Include "Amicus18_SPI.inc"
 
'****************I2C declared pins  *****************************
 Symbol SDAPin = PORTC.4
 Symbol SCLPin = PORTC.3
 Declare SDA_Pin PORTC.4
 Declare SCL_Pin PORTC.3
 Declare Hints=On
'****************I2C declared pins  ******************************
  Declare I2C_Slow_Bus On
Dim i            As Word
Dim ver          As Word         
Dim Var1         As Word
Dim k            As Word

'Write and read to 24lc256 eeprom
Var1=10
For i =0 To 5
I2COut SDAPin, SCLPin,%10100000,i,[Var1]
DelayMS 10
I2CIn SDAPin, SCLPin,%10100001,i,[ver]
DelayMS 10
HRSOut  "i ",Dec i, "  ",Dec ver,13
DelayMS 10
Var1=Var1+2
Next i
'Read from  24lc256 eeprom
For k =0 To 5
I2CIn SDAPin, SCLPin,%10100001,k,[ver]
DelayMS 10
HRSOut  "i ",Dec k, "  ",Dec ver,13
DelayMS 10
Next k
End

Result on serial terminal:

Amicus18 Board Reset
i 0  10
i 1  12
i 2  14
i 3  16
i 4  18
i 5  20
i 0  0
i 1  0
i 2  0
i 3  0
i 4  0
i 5  20

Thank you for any suggestion why.

Are there some example codes with Proton basic using I2C fro managing eeprom writing and reading?

Regards

trastikata

#1
You are writing Word variables:
- Declare your variable as Byte
or
- Use a Word variable but write variable's High and Low byte separately while inserting a delay of 7mS in-between.

Note: Writing one cell in the EEPROM updates the entire Page, what reduces the life of the memory, therefore whenever possible do Page writes.

Not related, but from 0 to 5 there are 6 loops.

See_Mos

I2C.bas in the samples folder might help.

broderic

Thank you very much, trastikata and See_Mos, for your kind help.

Regards