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

PIC24F32KA302 EEPROM Issue [solved]

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



Joined: 20 Oct 2009
Posts: 18

View user's profile Send private message

PIC24F32KA302 EEPROM Issue [solved]
PostPosted: Wed Oct 31, 2012 9:01 am     Reply with quote

Hi all.

I am having some issues with writing the internal EEPROM of my PIC24F32K3A02.

I tried using the built in CCS functions but they are not working for me. For this reason I followed the PIC datasheet and tried to create my own functions.

I am trying to erase the first location of EEPROM at 0x7FFE00 and write a word to this location.
Here the code:
Code:

void eeprom_write(unsigned int32 address,unsigned int16 data) // writes one word
{
   unsigned int y,high;
address=address+0x7ffe00;

   high=make8(address,2);
#asm

mov high,w0
mov w0,0X32
mov address,w9

mov data,w4
TBLWTL w4,[w9]

mov #0x4004,w2
repeat #30 //dont understand this, but without NVMCON not set properly
nop
mov w2,nvmcon
disi #5
mov #0x55,w0
mov w0,0x766
mov #0xaa,w0
mov w0,0x766
bset nvmcon,15
nop
repeat #10
nop
#endasm
while(bit_Test(nvmcon,15));
output_toggle(led_green);
}

void eeprom_erase(unsigned int32 address,unsigned int16 block_size)
{
   unsigned char high;
address=address+0x7ffe00;   

high=make8(address,2);   
   #asm asis

mov block_size,w3 // move erase operation required
repeat #30
nop
mov w3,0x760
mov.b high,w0
mov w0,0X32 // tbplpag register
mov address,w0 // move address
TBLWTL w0,[w0]
disi #5
mov #0x55,w0
mov w0,0x766
mov #0xaa,w0
mov w0,0x766
bset 0x760,15
nop
repeat #10
nop
#endasm
while(bit_Test(nvmcon,15));
output_toggle(led_green);
   
}   

unsigned int16 eeprom_read(unsigned int32 address)
{
   unsigned int y,high;
address=address+0x7ffe00;

   high=make8(address,2);
#asm

mov high,w0
mov w0,0X32
mov address,w9

TBLrdl [w9],w4
mov w4,high
#endasm

return high;
}   


from main I call these function like this
Code:

val2=0xa0a0;
output_high(led_red);
eeprom_erase(0,0x4058); // command for entire eprom
val=eeprom_read(0);
eeprom_write(0,val2); // write a single byte
output_low(led_red);
val=eeprom_read(0);
delay_ms(1000);


Any ideas why I always get 0 for EEPROM read?
The operations seem to be taking a few ms as expected when I measure the length of time the RED led is on for. My processor speed is default 8mhz FRC.
Eoin87



Joined: 20 Oct 2009
Posts: 18

View user's profile Send private message

PostPosted: Thu Nov 01, 2012 6:37 am     Reply with quote

My bad, I had the global EEPMD bit disabled.
Problem solved.
habip



Joined: 26 Nov 2015
Posts: 1

View user's profile Send private message Send e-mail

PostPosted: Thu Nov 26, 2015 4:49 am     Reply with quote

Eoin87 wrote:
My bad, I had the global EEPMD bit disabled.
Problem solved.


thank you
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