help: PIC16F628 and EEPROM

Sep 17, 2003 7 Replies

Hello guys, I'm desperately trying to write and read on the EEPROM of the PIC16F628 without any success ;-(( I use the following code : W_EEPROM MOVF ADRESSE,0 MOVWF EEADR MOVF VALEEPROM,0 MOVWF EEDATA BSF STATUS, RP0 BSF EECON1, WREN MOVLW H'55' MOVWF EECON2 MOVLW H'AA' MOVWF EECON2 BSF EECON1,WR BCF STATUS, RP0 RETURN



R_EEPROM MOVF ADRESSE,0 MOVWF EEADR BSF STATUS,RP0 BSF EECON1,RD BCF STATUS,RP0 MOVF EEDATA,0 MOVWF VALEEPROM RETURN



ADRESSE is the the data address where the VALEEPROM value should be stored . I tried the the adresses H'05' and H'06'



I tried it on a PIC16F84 and it worksIs the code wrong? How can I verify that the writing is correct? Can someone send a example wich I can use Thanks in advance for your help, Georges.



snipped-for-privacy@hotmail.com


You need to get the 16F62X datasheet errata from Microchip's website. That should show you the fix and get you aware of other problems.

Hallo Gary Kato !:

The 16F628 and 16F628A works fine (no problems with the eeprom). The 16F648A is rubbish !!!

You MUST detaily read the EEPROM-RW-Conditions. F.E. you must disable the interrupts for initialise of the r/w sequence.

From the Datesheet :

And don't forgot a while wait ..... (4-8 milliseconds) ;-) !

Grzegorz Zalot complex ltd. office tel/fax : +48 32 2505840 mobil : +48 501 301515 http://www.complex.org.pl/ mailto:complex@alpha.pl

When should I wait? "Grzegorz Zalot" a écrit dans le message de news: snipped-for-privacy@alpha.pl...

That

16F648A is

I tried with the errata... But...Actually I need to store 2 values. When I store the value at the address H'02' , the value at the address H'06' is also changed when I read it????? I used the serial port to send commands to store the values

"Grzegorz Zalot" a écrit dans le message de news: snipped-for-privacy@alpha.pl...

That

16F648A is

Georges, I found that changing the EEADR register in any way while a write was taking place would currupt the write.

I use the following BEFORE reads and writes

R_EEPROM btfsc EECON1,WR goto R_EEPROM

W_EEPROM btfsc EECON1,WR goto W_EEPROM

It allows the write to happen while other code is executing (maybe NOT a good idea on the F648...)

Good Luck

Robert

Hallo Georges Konstantinidis !:

For test use please the programmer (f.e. Picstart). I think, the error is probabily in your Serial port procedure .....

GZ.

Since you say that it works with one PIC and not the other, I have seen this problem. I don't have a manual in front of me, but there is a bit in EECON1 that needs to be cleared. I forgot the name of the bit, but a '1' writes to flash, and a '0' writes to EEPROM.

Many times people can do eeprom operations without any problems because the power-up values "usually" default to 0. However, on some parts, this particular bit is an unknown power-up value. So for 70% of the chips of one particular family, you might not have problems, but the other 30% will initialize this bit to a '1', and you'll think the chip is no good.

Try looking at the EECON1 register description. I think it is bit 6, and look at that bit's description to see if that is the one that selects the flash bank or the eeprom bank, and set it to a '0'. See if that helps.

-Mike

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required