View previous topic :: View next topic |
Author |
Message |
toto
|
Posted: Tue Oct 22, 2013 9:50 pm Post subject: EEPROM weird behavior |
|
|
Hello,
I need to fill a 24lc512 eeprom, but on 0x100 as you can see below, the first 3 bytes are not written properly, (it seems that the line is once written properly but then rewriteen with a 3 byte shift.) but on the next line (starting 0x110) everything goes to normal again.
Coincidentally 0x100 is 256 in decimal, right when the MSByte of the address is filled.
Does anyone have an ideia what might be the cause of this weird behavior?
regards
EEPROM:
0F0 | 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10
100 | 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 0E 0F 10
110 | 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10
CODE:
Code: | For i = 1 To 16
Dia(i) = i
Next i
while diacol < 10000
gosub E_writepage
diacol = diacol + 16
wend
E_writepage:
E_ah = High(diacol)
E_al = Low(diacol)
I2cstart
I2cwbyte E_ctlw
I2cwbyte E_ah
I2cwbyte E_al
I2cwbyte Dia(1)
I2cwbyte Dia(2)
I2cwbyte Dia(3)
I2cwbyte Dia(4)
I2cwbyte Dia(5)
I2cwbyte Dia(6)
I2cwbyte Dia(7)
I2cwbyte Dia(8)
I2cwbyte Dia(9)
I2cwbyte Dia(10)
I2cwbyte Dia(11)
I2cwbyte Dia(12)
I2cwbyte Dia(13)
I2cwbyte Dia(14)
I2cwbyte Dia(15)
I2cwbyte Dia(16)
I2cstop
'Waitms 15
Return |
(BASCOM-AVR version : 2.0.7.6 ) |
|
Back to top |
|
|
Arera
Joined: 23 Sep 2007 Posts: 386 Location: Wuppertal, Germany
|
Posted: Wed Oct 23, 2013 9:15 am Post subject: |
|
|
Tell us how you DIMed the variables, please. |
|
Back to top |
|
|
toto
|
Posted: Wed Oct 23, 2013 9:35 am Post subject: |
|
|
dim dia(16) as byte
dim diacol as word
dim E_ah as byte
dim E_al as byte |
|
Back to top |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Wed Oct 23, 2013 9:37 am Post subject: |
|
|
Hi,
Maybe if you change the page that's beeing written to you need to include a short delay to allow the chip to swap pages.
Have a look at the specs for the chip, maybe there's something about page select times.
Regards
Ian Dobson _________________ Walking on water and writing software to specification is easy if they're frozen. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Wed Oct 23, 2013 9:44 am Post subject: |
|
|
have a look at the provided i2c samples.
and also : checkout the special eeprom driver lib that allows an external eeprom to be used as an internal eeprom, allowing the ERAM 'variable'
At the on line help you can find samples too. _________________ Mark |
|
Back to top |
|
|
toto
|
Posted: Wed Oct 23, 2013 10:00 am Post subject: |
|
|
As far as i can remember the datasheet says that the page buffer has 128bytes and the time to wait is 5ms between pages.
Even with 15ms of wait between each 16bytes (as you can see commented in the code) it has the same behavior. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Wed Oct 23, 2013 10:12 am Post subject: |
|
|
you should check the ERR flag after the i2cstart and writes. but first i would recommend to try another chip.
and have a look with a scope at the signals and vcc. _________________ Mark |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Wed Oct 23, 2013 12:00 pm Post subject: |
|
|
toto wrote: | As far as i can remember the datasheet says that the page buffer has 128bytes and the time to wait is 5ms between pages.
Even with 15ms of wait between each 16bytes (as you can see commented in the code) it has the same behavior. |
You can better use ack polling to determine if the eeprom is ready with writing, then you never waitms to long or to short.
Code: |
Sub M24_write_eeprom(byval Adress As Word , Byval Value As Byte)
Local Tempadress As Byte
I2cstart 'start condition
I2cwbyte Address_rf_w 'slave address
Tempadress = High(adress)
I2cwbyte Tempadress 'highbyte adress of EEPROM
Tempadress = Low(adress)
I2cwbyte Tempadress 'lowbyte adress of EEPROM
I2cwbyte Value 'value to write
I2cstop 'stop condition
Do 'Polling for ACK, see datasheet page33
I2cstart 'generate start
I2cwbyte Address_rf_sec_w 'slave adsress
I2cstop
Loop Until Err = 0
End Sub
|
Some eeprom's need also page alignment, check this in your datasheet. Then you must write is the page before you can file the next one. _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
toto
|
Posted: Wed Oct 23, 2013 2:17 pm Post subject: |
|
|
I isolated the code and found out that i was assigning the address in another part of the code. Where i set the function dayofyear() to a byte instead of a word (the problems that come when you reuse variables).
I tend to forget to check for the simple stuff first. -_-
Thank you all for helping narrowing down the options to finally solve the problem. =) |
|
Back to top |
|
|
|