Avoiding EEPROM corruption
Serial EEPROM Solutions vs. Parallel Solutions - The cost break even point for serial I2C non-volitile memory from useing multiple 32kx8 EEPROMs to using parallel flash memory with an I2C controller is at about 128k as of late 1999.
Ian Chapman <firstname.lastname@example.org> says:
BTW, I've just spotted an interesting point in AN709 about I2C EEPROMs which can power up in an incorrect state. The following initialisation sequence after power-up is recommended to resolve this:
- START bit
- Clock in nine bits of '1'
- START bit
- STOP bit
I haven't seen this in any examples of I2C master code before, but AN709 gives a good explanation of why it is needed to avoid the possibility of an erroneous write to the EEPROM.
Extending lifetime and reliability in EEPROMs
This code will write the EEPROM on the 16F628 in chunks.
; Written: 14-Apr-2002, Chuck McManis
; Uses the temporary variable EE_LEN, EE_SRC, and EE_DST
; During write Source is RAM and Destination is EEPROM
; Note: Due to a bug in the 16F628 you can "overrun" the ability
; of the chip to write the EEPROM if you just monitor the WR bit
; in EECON1 (if you write immediately after it goes low the EEPROM
; may not be written.
; Thus this macro assumes that when it starts there is not a write
; currently in progress!
; Usage: EEWRITE <data bytes address (0-0xff)>, <eeprom address>, <len>
; On the 16F628, EE_LEN, EE_SRC, and EE_DST should be in the range
; 0x70 - 0x7F (mirrored on all ram banks)
EEWRITE MACRO SRC_ADDR, DST_ADDR, LEN
MOVLW LEN ; Get length
MOVWF EE_LEN ; Store it in count
MOVLW SRC_ADDR ; Get the source address
MOVWF EE_SRC ; Store in the source addr
MOVLW DST_ADDR ; EEPROM Destination address
MOVWF EE_DST ; Store it too
BCF PIR1, EEIF ; Clear this flag...
MOVF EE_SRC,W ; Source Address
MOVWF FSR ; Store in FSR
MOVF INDF,W ; Get a data byte
BSF STATUS, RP0 ; Switch to Bank 1
MOVWF EEDATA ; Store the data byte in EE Data
MOVF EE_DST,W ; Get the destination address
MOVWF EEADR ; .. this byte goes here
BSF EECON1, WREN ; Enable Writes to EEPROM
; BTFSS EECON1, WR ; This should work but doesn't (see
; GOTO $-1 ; below) it only writes 2 of n bytes.
BCF INTCON, GIE ; Interrupts off.
MOVLW H'55' ; Magic Sequence (Sequence Start)
MOVWF EECON2 ; ...
MOVLW H'AA' ; ...
MOVWF EECON2 ; ...
BSF EECON1, WR ; and Write it! (Sequence End)
BSF INTCON, GIE ; Interrupts are allowed again.
BCF EECON1, WREN ; Disable future writes.
BCF STATUS, RP0 ; back to bank 0
BTFSS PIR1, EEIF ; Wait for it to finish, this slows
GOTO $-1 ; ... us down! (bug! see above)
INCF EE_SRC, F ; Add 1 to source and destination
INCF EE_DST, F ; ... addresses (no overlap)
DECFSZ EE_LEN,F ; Decrement the length and ...
GOTO WLOOP ; ... loop if non-zero.
For another example of reading the EEPROM, see PIC 16F876 full initialization sample program /techref/microchip/16f877/snipp.htm .
|file: /Techref/mem/eeproms.htm, 9KB, , updated: 2013/7/22 17:09, local time: 2023/6/2 09:13,
|©2023 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://www.piclist.com/Techref/mem/eeproms.htm"> EEPROMs</A>
|Did you find what you needed?|
PICList 2023 contributors:
o List host: MIT, Site host massmind.org, Top posters @none found
- Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.
Welcome to www.piclist.com!