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.

EEPROM Read Problem

Status
Not open for further replies.

megan

New Member
Hey There,

I actually have a problem with my EEPROM access in the PIC16F877A.

I saved a string of 5 bytes transferred from an SMS received in the handphone to my PIC and saved in EEPROM but when i read these 5 bytes again from the EEPROM and send it to another handphone, i get all 5 bytes showing the "Pound symbol" (Ascii 0x156) instead.



1) I have used the memory locations 0x00-0x04 for the saving of the 5 bytes into EEPROM.
2)I have also taken into consideration the 0xaa and 0x55 special hexcodes

I know I should be posting my code but my code is a thousand lines long and would be pretty inconvenient. So before I get into the details, Im wondering if there's any fundamental issues that i should address first if anyone has ever encountered this same problem

Thanks!
 
The most common problem with writing to EEPROM is not waiting for the write to finish before doing something else. The simplest way to know if the write is complete is to check the WR bit (in EECON1) and if it's still set then the write hasn't completed and you should wait.

As for code, you could just post the read/write routines.

Edit, BTW how can a byte contain 0x156. The max is 0xff.

Mike.
 
Last edited:
Thank you for your reply :)

BTW how can a byte contain 0x156. The max is 0xff

yeah that baffles me too. The 5 bytes that appear on my handphone screen is £££££

The most common problem with writing to EEPROM is not waiting for the write to finish before doing something else. The simplest way to know if the write is complete is to check the WR bit (in EECON1) and if it's still set then the write hasn't completed and you should wait.

Yes I have taken that into consideration as well.
The following are my routines

WRITE:

Code:
EEWrite:

		BANK3
Wait2Start:
		btfsc	EECON1,WR
		goto	Wait2Start
		
		BANK2
		movf	EEMemAdd,w
		movwf	EEADR
		movf	EEByte,w
		movwf	EEDATA
		
		BANK3
		bcf		EECON1,EEPGD
		bsf		EECON1,WREN
		

		;;special line;;
		movlw	0x55
		movwf	EECON2
		movlw	0xaa
		movwf	EECON2

		bsf		EECON1,WR	;START WRITE OPERATION!
		nop
		nop

Wait2End:
		btfsc	EECON1,WR
		goto	Wait2End
		
		bcf		EECON1,WREN		;PREVENT ACCIDENTAL WRITES;

		BANK0
		
		RETURN



READ:
Code:
EERead:
		BANK2
		movf	EEMemAdd,w
		movwf	EEADR
		
		BANK3
		bcf		EECON1,EEPGD
		bsf		EECON1,RD
		
		BANK2

		movf	EEDATA,w
		
		BANK0

		RETURN


btw, there are no interrupts that im using in my code.
 
I know I should be posting my code but my code is a thousand lines long and would be pretty inconvenient. So before I get into the details, Im wondering if there's any fundamental issues that i should address first if anyone has ever encountered this same problem

Thanks!

hi,
You could post your FULL code as an *.asm file rather than as an image file.
 
Your code looks fine. My only question is, which bank is EEMemAdd in?

Edit, You could read the EEPROM with your programmer to make sure the correct data is in the right locations. Also £ is 0xA3.

Mike.
 
Last edited:
In your routines you are accessing EEMemAdd in Bank 2.

Mike.
 
Last edited:
Would this implementation be correct to select bank 2 (selecting hexcode 0x120)?

cblock 0x120
EEMemAdd
EEByte

endc
 
You can do it that way but that means that in your main code you need to select bank 2. The other way is to select bank 0 in your EEPROM routines before accessing it or place it in the common area at 0x70-0x7f.

Mike.
 
The £ sign on a cellphone is encoded as 0x01. The encoding is not ASCII, although it uses the same codes as ASCII for all the usual characters. You certainly store "£" in one EEPROM location if you are receiving from a cellphone.

You should use a programmer to find what you code has written in the EEPROM, if anything.
 
hmm...

The £ sign on a cellphone is encoded as 0x01. The encoding is not ASCII, although it uses the same codes as ASCII for all the usual characters. You certainly store "£" in one EEPROM location if you are receiving from a cellphone.


why does that happen? is it a default thing if a cellphone accesses an EEPROM?
 
Last edited:
I don't think that the cellphone is accessing the EEPROM that you are working with. As I understand it, you are receiving a text on a cellphone, reading it with a PIC16F877A, and storing the result in the EEPROM on the PIC. Then you are reversing the process, and reading the values from the EEPROM on the PIC, and sending them as part of the text to another cellphone.

I don't think that the default for a cell phone is 0x01. I think that the 0x01 is a result of your code not reading or writing the EEPROM correctly, and £ is how it appears on the cellphone.

GSM 03.38 Default Character Set shows the character set for SMS.
 
I think Diver300 is correct. I think you are writing and reading from one location due to bank switching problems.

Mike.
 
my EEPROM read and write is working now:)

thank you so much mike, diver300.=) benefited a lot from ya'll=)

also thank you mr. eric gibbs for your reply..sorry i overlooked your post=)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top