Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Data EEPROM of PIC questions

Status
Not open for further replies.

bananasiong

New Member
Hi,
I have just read the notes of data EEPROM.
The write will not initiate if the above sequence is not exactly followed (write 55h to EECON2,
write AAh to EECON2, then set WR bit) for each byte. We strongly recommend that interrupts be
disabled during this code segment.
Interrupt is disabled so that no interrupt happen when half way writing to the EEPROM.
So is it good or bad to write to the EEPROM in the ISR?

Can I read or write to the EEPROM using similar method of indirect addressing, such as:
Code:
.
.
incf	EEADR,	f
movf	EEDATA,	w
.
.

Thanks
 
Hello, I have a similar a related question, so I'll post it here and not in a new topic.

I have been trying to read and write to an 16f627's eeprom.

The read procedure I am using:
Code:
       bsf		STATUS, RP0
	movlw	0x03
	movwf	EEADR
	bsf		EECON1,	RD
	movf	EEDATA, W
	bcf		STATUS, RP0

And the write procedure:
Code:
	bcf		STATUS, RP0
	movlw	0x03
	movlw	EEADR

	movlw	1
	movwf	EEDATA

    bsf		STATUS, RP0
	bsf		EECON1, WREN
	bcf		INTCON, GIE
	movlw	H'55'
	movwf	EECON2
	movlw	H'AA'
	movwf	EECON2
	bsf		EECON1, WR
	bsf		INTCON, GIE

;---
    bsf		STATUS, RP0
	movf	EEDATA, W

	subwf	EEDATA, W
	btfss	STATUS, Z
	goto	write_err
the whole code is here **broken link removed**

While writing to the eeprom write_err never got called, but if I try to read the eeprom with the programmator (K8048) the eeprom is filled with FFs.
The read procedure get the same, just FFs.

Can you help me to figure out what I am doing wrong?

Thank you :)
 
bananasiong said:
Hi,

So is it good or bad to write to the EEPROM in the ISR?

Thanks

It can be bad to write to EEPROM in the ISR if it occurs often as there is a limit of about 1,000,000 writes in the life of many pics.
If you do write in the ISR then you need to calculate how long the chip will last.

Can I read or write to the EEPROM using similar method of indirect addressing, such as:
Code:

. . incf EEADR, f movf EEDATA, w . .


For writing to the eeprom, you have to use the recommended code methods to ensure that it writes properly. This involves using the special write sequence and waiting for write completion before doing another write.
If you don't follow this then it won't work.

For reading, your code will not work because you have to set a read flag
BSF EECON1,RD
This is in bank 3 and is automatically reset after each read.

This applies to 16F types. If you are using 18F types then there are extra commands to make sequential reading EEPROM much easier.
 
Yes, I know that 0x55 and 0xaa need to be written into EECON2, and other EEPROM writing procedures ;)
Just wonder I can read or write to the EEPROM without specifying the address all the time (only the first time), just read/write the next address of EEPROM (just like indirect addressing).
 
bananasiong said:
Just wonder I can read or write to the EEPROM without specifying the address all the time (only the first time), just read/write the next address of EEPROM (just like indirect addressing).

The data sheets on the 64K by 8 parts I looked at have a sequential read and block write.

With the sequential read you specify the address for the first read. After that the mem sends you a byte after you ack the one you just read until you stop acking them.
 
He's not asking about serial eeproms. The internal eeprom will suffice with a simple increment of EEADR to accomplish sequential read.

Mike.
 
Pommie said:
He's not asking about serial eeproms. The internal eeprom will suffice with a simple increment of EEADR to accomplish sequential read.

Mike.
Yes! That's what I wanted to know. Thanks :)
How about the write cycle, same as what I said?

Another question of the write cycle is, the required sequence (such as writing 0x55 and 0xaa to EECON2) is needed to be done every time the address (EEADR) is updated? Or I can write to any address and do the required sequence for only once?
Am I right that the PIC takes 8 ms (max) to write to each address of the EEPROM? Or the whole process of writing to the EEPROM?

What is serial EEPROM? Is it external EEPROM IC that interfaced with the PIC?

*Thanks picasm for reminding about the lifespan of the PIC.
 
You have to do the 0x55, 0xaa sequence every time you write to EEPROM. As it takes up to 8mS (typically 4mS) to write to each location, the extra time involved in the sequence is irrelevant.

Serial EEPROM is an external chip that is accessed serially. Google 24LC64.

Mike.
 
Pommie said:
You have to do the 0x55, 0xaa sequence every time you write to EEPROM. As it takes up to 8mS (typically 4mS) to write to each location, the extra time involved in the sequence is irrelevant.

Serial EEPROM is an external chip that is accessed serially. Google 24LC64.

Mike.
Thanks :)

I've read the data EEPROM notes of Microchip, saying that
When the device is code protected, the CPU may continue to read and write the data EEPROM
memory. The device programmer can no longer access this memory.
So I was thinking, whether I can write a very short program, to write to the EEPROM, with code protected. Then program into the PIC and turn on the PIC to enable the writing.
Then I write another program which is reading from the EEPROM (no writing to the EEPROM in this program) and program into the same PIC. Can this be done?
 
bananasiong said:
So I was thinking, whether I can write a very short program, to write to the EEPROM, with code protected. Then program into the PIC and turn on the PIC to enable the writing.
Then I write another program which is reading from the EEPROM (no writing to the EEPROM in this program) and program into the same PIC. Can this be done?

I've no idea what you're even asking?, but why on earth would you want to do something like that?.
 
Nigel Goodwin said:
I've no idea what you're even asking?, but why on earth would you want to do something like that?.
:|
What I thought after reading the notes from Microchip is, when the chip is code protected, the EEPROM will not be erased by the programmer when it is reprogrammed. So it is supposed to be true that if I read from the EEPROM, I can get the data which is previously programmed in?
 
bananasiong said:
:|
What I thought after reading the notes from Microchip is, when the chip is code protected, the EEPROM will not be erased by the programmer when it is reprogrammed. So it is supposed to be true that if I read from the EEPROM, I can get the data which is previously programmed in?

If the chip is code protected, you have to wipe it entirely in order to remove the code protection - this is fairly obvious, otherwise it wouldn't be very good protection would it?.
 
But the notes say that
The device programmer can no longer access this memory.
means the EEPROM will not be cleared with bulk erased, can only be erased by writing erase routine in the program?
 
The programmer can no longer read or write to the EEPROM. It can however clear it with bulk erase.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top