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 CCS Technical Support

PIC18F66K22 EEPROM Functions

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mayur.k.vadukul



Joined: 07 Jul 2022
Posts: 42

View user's profile Send private message

PIC18F66K22 EEPROM Functions
PostPosted: Tue Feb 04, 2025 8:13 am     Reply with quote

I am writing a code whereby I need more than 256 bytes of data to store.
I have checked the datasheet and it suggests the PIC18F66K22 has 1024 Bytes of storage.
However, when I am using the library function write_eeprom, it does not write beyond 256 bytes and starts overriding it.

i.e. if I write ADD = 10, Data = 56; write_eeprom (ADD,DATA), it works fine. But if I try to write at the address 300 with Data = 56, it changes the data of address (300-256).

PS: I have also changed the header file section as below:-

Code:
// EEPROM Prototypes:
/*
#ifndef __EEADDRESS__
 #if getenv("DATA_EEPROM")>256
  #define __EEADDRESS__ unsigned int16
 #else
  #define __EEADDRESS__ unsigned int8
 #endif
#endif
*/
#define __EEADDRESS__ unsigned int16


Any direction?
_________________
MVadukul
temtronic



Joined: 01 Jul 2010
Posts: 9370
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Feb 04, 2025 8:36 am     Reply with quote

I don't have that PIC, never used the write_eeprom()...
but
since your PIC has 1024 bytes of storage, I'd always use unsigned int16 for the address.
It may be 'something' in the library has defaulted to 8 bit.
Maybe your code uses the same variable name and it's 8 bit ?

I don't know but pretty sure someone who has used this will reply soon !
mayur.k.vadukul



Joined: 07 Jul 2022
Posts: 42

View user's profile Send private message

PIC18F66K22 EEPROM Functions
PostPosted: Tue Feb 04, 2025 10:26 am     Reply with quote

The problem is solved now.

The issue was that the variable I used was 16 bit unsigned integer, but the offset which was passed to obtain the storage address was unsigned 8 bit integer.

I was storing from offset 119 to 329. However, when the counter went beyond 255, it turned 0.

i.e. unsigned 16 bit int a = offset (119) + required location (this was unsigned 8 bit integer);

The above should work technically as the stored variable is larger in size but it didn't work. But once I made the variable which was passed into the loop as unsigned 16 bit integer as well, it started working correctly.
_________________
MVadukul
temtronic



Joined: 01 Jul 2010
Posts: 9370
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Feb 04, 2025 11:36 am     Reply with quote

whew you FOUND it ! great !!!

sometimes little problems can cause BIG headaches.
Ttelmah



Joined: 11 Mar 2010
Posts: 19649

View user's profile Send private message

PostPosted: Tue Feb 04, 2025 12:43 pm     Reply with quote

Classic. Very Happy

Well done finding it. Flag the thread as solved please.
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