Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC18f4620 EEPROM issue

Status
Not open for further replies.

adnan012

Advanced Member level 1
Joined
Oct 6, 2006
Messages
468
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Activity points
4,923
hi,

I want to save data in PIC18F4620 EEPROM. I am using MPlabx and XC8 compiler.

I am using bulit in functions. PIC18F4620 has 1k EEPROM. Is there any issue in 10bit EEprom addressing?

eeprom_write(address, value);
value = eeprom_read (address)

I am unable to read back correct data.
 

We have no idea how this functions works. May be some delay needed to perform correct writing. For such cases I prefer to write my own functions according manual.
 
The functions are for writing 1 byte data. For writing 10 bit data you have to use

Code:
eeprom_write(address + 1, (unsigned char)(value >> 8)); //low byte 
value = eeprom_read (address + 1)
value <<= 8;

eeprom_write(address, (unsigned char)value); //low byte 
value |= eeprom_read (address)
 
According to a comment in eeprom_routines.h, the library version does wait for write completion. But I would inspect the generated code to be sure.

The macro EEPROM_READ() is NOT safe to use immediately after any write to EEPROM, as it does NOT wait for WR to clear. This is by design, to allow minimal code size if a sequence of reads is desired. To guarantee uncorrupted writes, use the function eeprom_read() or insert while(WR)continue; before calling EEPROM_READ().
 
The functions are for writing 1 byte data. For writing 10 bit data you have to use
I'm not sure that's true, the question referred to 10-bit ADDRESSING not 10 bits of data. However, the 18F4620 does have two 8-bit address registers for EEPROM access, EEADR and EEADRH with the two MSB of the address going to EEADRH. I'm not sure if XC8 takes that into account although I would be suprised if it didn't. I do not have a copy at hand to look at the code it produces at the moment.

Brian.
 
  • Like
Reactions: Okada

    Okada

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top