-
Jump into eeprom address
Hi all,
i'm receiving through a max232 a string (ex. XYTest Com1).
With Serin2 I'm waiting for a string and if it has XY I save the following
9 characters into a string (long).
I save 'long' into a 24c64 eeprom with i2cwrite then i check with i2cread and
Serout2 if long has been saved. After that I increase ADD by 9 and I jump
to start waiting for the next available string.
The first 3 strings are saved fine:
Address 0000 Test Com
Address 0009 1Test Co
Address 0010 m1Test C
Address 0018 om1
Now when the fourth string is coming at address 27 (1B) the first 5
characters are correctly saved into 27-28-29-30-31 (1B-1C-1D-1E-1F)
and the last 4 are saved into address 0-1-2-3 instead of 32-33-34-35
(20-21-22-23)
Address 0000 Com1 Com
Address 0009 1Test Co
Address 0010 m1Test C
Address 0018 om1Test
I got lost, I do not understand why !!
Thanks for your help.
Here is the prg:
DEFINE OSC 4
SDA VAR PORTA.0
SCL VAR PORTA.1
ADD VAR WORD
EEP CON $A0
OUT VAR BYTE[9]
long VAR BYTE[9]
BAUD VAR BYTE
RX VAR PORTA.3
TX VAR PORTA.2
BAUD = 84 ' 9600,8,N,1
ADD=0
Pause 1000
Start:
SerIn2 RX, BAUD, [wait("XY"),STR long\9]
Pause 2000
I2CWrite SDA,SCL,EEP,ADD,[STR long\9]
Pause 10
Pause 2000
I2CRead SDA,SCL,EEP,ADD,[STR OUT\9]
Pause 10
SerOut2 TX, BAUD, [#ADD," ", STR OUT\9,13,10]
ADD=ADD+9
GoTo START
End
-
Check if your particular EEPROM allows you to write more than one byte before initiating a 10mS wait - this information will be found in your manufacturers Datasheet for the device. You are outputting 9 bytes in one string with no delays, it is possible you are violating the timing requirement of the EEPROM. The fact the first strings are save correctly is no guarantee that any others will be.
-
Melanie, thanks for yr reply.
The eeprom is manufactured by ST. I checked the datasheet http://www.tranzistoare.ro/datasheets/400/227040_DS.pdf and according
to the table nr. 16 the waiting time is for the N series 10ms.
I really do not know what's wrong.
thanks for any further help.
-
If they tell you 10mS, then you should give it 10mS PER BYTE and not 10mS AFTER sending nine bytes.
-
Hi again,
I feel this is might be a stupid question !
It's enough (too easy) Pause 90 instead of Pause 10 ?
Otherwise how can i make a 10ms pause after each byte ?
Thanks again
-
A 90ms Wait ist not right.
I think, the EEPROM can access its memory in pages of 32 Bytes.
So, if you write inside this page, it can be written back in one event just needing 10ms pause.
But if you are crossing this pages, you must adress the new page with a new I2C-Command.
Just read the dokumentation and see, if if is possible for you to use pages. Maybe it will be ok, if you drop every 5 Bytes at the end of a page ?
-
SerIn2 RX, BAUD, [wait("XY"),STR long\9]
Pause 2000
For CounterA=0 to 8
Address=ADD+CounterA
I2CWrite SDA,SCL,EEP,Address,[STR(CounterA)]
Pause 10
Next CounterA
-
@ BigWumpus
Yes you are right. I saw (datasheet) that Page Write mode allows up to 32
bytes per writing cycle.
Now let's see how to 'cheat' the 24c64 !
@ Melanie
Thanks for the code.
Unfortunatly I receive a compiling error on line:
I2CWrite SDA,SCL,EEP,Address,[STR(CounterA)] = Bad Expression
I tried some small chances but no success.
I'm sorry I'm not a Pro and I still need your help.
Thanks
-
Probably needs an intermediate variable because I don't think variable indexed arrays are allowed with I2CREAD or I2WRITE... try this...
CounterA var BYTE
DataA var BYTE
SerIn2 RX, BAUD, [wait("XY"),STR long\9]
Pause 2000
For CounterA=0 to 8
Address=ADD+CounterA
DataA=STR(CounterA)
I2CWrite SDA,SCL,EEP,Address,[DataA]
Pause 10
Next CounterA