CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Internal EEPROM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
SeeCwriter



Joined: 18 Nov 2013
Posts: 160

View user's profile Send private message

Internal EEPROM
PostPosted: Thu Apr 09, 2015 8:49 am     Reply with quote

I am still having problems reading and writing the internal EEPROM of an
18F8722. Plus I'm confused by the compiler manual. I'm using PCHW
v5.043.

In the Data EEPROM section of the manual, pg 63, it shows an example of
writing and reading the EEPROM:

write_eeprom(0x10, 0x1337); // Writes 0x1337 to data EEPROM location 10.
value=read_eeprom(0x0); // Reads data EEPROM location 10 returns 0x1337.

According to this section you can write and read 16-bit values.

But when I look at the function descriptions for read_eeprom() and write_eeprom(),
it says the read_eeprom() function returns "an 8 bit int", and that for the
write_eeprom() function the value it writes is "an 8 bit int".

So my first question is, which is correct?
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Thu Apr 09, 2015 9:25 am     Reply with quote

I believe the manual states you can write 8 bit or 16 bit depending on the part. The spec sheet for the 18F8722 states that 8 bits are to be written. If you need to write a 16 bit variable to the eeprom then you'll need to do it with two operations.

Ronald
SeeCwriter



Joined: 18 Nov 2013
Posts: 160

View user's profile Send private message

PostPosted: Thu Apr 09, 2015 9:56 am     Reply with quote

Actually, the manual only says the address a 8 bit or 16 bit int depending
on the part. The data is always specified as an 8 bit int. Which is fine, I just
needed clarity.

I am unable to read and write the data EEPROM, since the data does not
persist through a power cycle. Whenever I read the EEPROM after a power
cycle the data is always 0xFF.

Is there something wrong with the 2 functions I'm using to read and write?


Code:

void SaveParameter( u16 adr, u16 value_ )
{
   write_eeprom( adr,   make8(value_, 0) );
   write_eeprom( adr+1, make8(value_, 1) );
}

void GetParameter( u16 adr, u16  *value_ )
{
   byte val[2];

   val[0] = read_eeprom(adr);
   val[1] = read_eeprom(adr+1);

   *value_ = make16( val[1], val[0] );
}
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Thu Apr 09, 2015 11:43 am     Reply with quote

the datasheet is the governing document.
the eeProm writes a BYTE at a time
to a WORD offset - of which only 10 bits are used .

\
Quote:

The data EEPROM is a nonvolatile memory array,
separate from the data RAM and program memory, that
is used for long-term storage of program data. It is not
directly mapped in either the register file or program
memory space, but is indirectly addressed through the
Special Function Registers (SFRs). The EEPROM is
readable and writable during normal operation over the
entire VDD range.
Five SFRs are used to read and write to the data
EEPROM, as well as the program memory. They are:
• EECON1
• EECON2
• EEDATA
• EEADR
• EEADRH
The data EEPROM allows byte read and write. When
interfacing to the data memory block, EEDATA holds
the 8-bit data for read/write and the EEADRH:EEADR
register pair holds the address of the EEPROM location


so use the CCS read/write functions accoringly.
remember that the address is ZERO based.

and YES it looks like there is a problem with getparameter.
SeeCwriter



Joined: 18 Nov 2013
Posts: 160

View user's profile Send private message

PostPosted: Thu Apr 09, 2015 11:54 am     Reply with quote

I'm aware of what the data sheet says. But that does not mean that the
CCS library functions couldn't have been written to handle reading or
writing multiple byes with a single call.

Perhaps you could elaborate on where I went off the rails with GetParameter().
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Thu Apr 09, 2015 12:13 pm     Reply with quote

Don't always expect to have a byte of data gor internal eeprom...

dspic30,33 and pic 24 have 16 bit writes and read on internal eeprom (two bytes at time)...
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Thu Apr 09, 2015 12:53 pm     Reply with quote

Code:

unsigned int16 GetParameter( unsigned int16  adr )
{
   byte val;
   val = read_eeprom(adr++);
   return( make16( read_eeprom(adr) , val ));
}


see what the .LST file shows for this
compiled for 18f8722


Last edited by asmboy on Thu Apr 09, 2015 2:36 pm; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19339

View user's profile Send private message

PostPosted: Thu Apr 09, 2015 2:17 pm     Reply with quote

Funnily enough, a second thread about the EEPROM on a PIC30, is running at almost exactly the same time.

The manual is actually _wrong_ on the write EEPROM function for these later chips. However if you look at the example 'ex_intee.c', you will see how (and for which chips), CCS handle the switch between sizes.
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Thu Apr 09, 2015 2:26 pm     Reply with quote

asmboy wrote:
Code:

unsigned int16 GetParameter( unsigned int16  adr )
{
   byte val;
   val = read_eeprom(adr++);
   return( make16( read_eeprom(adr) , val ));
}


see what the .LST file shows for this


I'd like to test it too but for some reason, PCD is broken with write_eeprom...

Values inside the EEPROM always stays at 0xFFFF.

Code:

#include <30F6014A.h>
#FUSES XT_PLL16,NOPROTECT,NOWDT,BROWNOUT,BORV27,PUT64,NOCKSFSM,MCLR,NODEBUG
#use delay(clock=120mhz)

void main()
{
write_eeprom(0,0x10); // stays at 0xFFFF (default value in EEPROM)
   while(1)
   {
   }
}


I have to dig this more when I have more time on my hands...
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!


Last edited by ELCouz on Thu Apr 09, 2015 3:05 pm; edited 1 time in total
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Thu Apr 09, 2015 2:29 pm     Reply with quote

Ttelmah wrote:
Funnily enough, a second thread about the EEPROM on a PIC30, is running at almost exactly the same time.

The manual is actually _wrong_ on the write EEPROM function for these later chips. However if you look at the example 'ex_intee.c', you will see how (and for which chips), CCS handle the switch between sizes.


hehe he's not a sock puppet Razz
_________________
Regards,
Laurent

-----------
Here's my first visual theme for the CCS C Compiler. Enjoy!
SeeCwriter



Joined: 18 Nov 2013
Posts: 160

View user's profile Send private message

PostPosted: Thu Apr 09, 2015 3:34 pm     Reply with quote

I was looking at passing arguments by pointer before you posted. I was
remembering a previous PIC project from a few years ago where I was
burned by using pointers to pass a parameter to a function. And it bit
me in the a** again.
I was trying to make use of function overloading, and passing a pointer
seemed like the best option. Oh well. Removing the pointer and just returning the value fixed the problem.

This seems like a compiler bug. Or at least the compiler should give a
warning when passing pointers.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Sat Apr 11, 2015 8:41 am     Reply with quote

#1 - assume that parameters passed INTO the function code space by POINTER - can NOT be used to pass data back OUT.

if you think about it - that's why you can safely pass an argument in by value that is contained in an otherwise global VAR.

#2 when we execute "ADR++"
after first use - the external GLOBAL var passed as "ADR" is only a copy of the GLOBAL VAR -hence the source VAR for ADR in this case - is not altered by the function.

#3 -If you don't know how already -lean to read the .LST pseudo assembler file. SO much can be figured about about compiler behavior by reading and comprehending what it shows of the actual pic code .
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group