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

Problem Writing to eeprom PIC18F4431
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ralph
Guest







Problem Writing to eeprom PIC18F4431
PostPosted: Thu Sep 24, 2009 2:54 pm     Reply with quote

Hello,

I try to write to the eeprom of the PIC18F4431 but in difference to all other models I used before, this is not working.

Once I wrote a function - ok I have seen, functions like this are already existing but was working properly nevertheless.
Code:

void write_to_eeprom(int place, unsigned long value)
{
   write_eeprom(place*2,(value&0xFF00)>>8);
   write_eeprom((place*2)+1,value&0x00FF);
}


Code:

#include <18F4431.h>
#fuses NOWDT,NOPROTECT,NOBROWNOUT,NOMCLR, NOLVP, INTRC
#use delay(clock=4000000)

Meanwhile I measure some PWM ranges and want to store the max and min value.
Code:

write_to_eeprom(0,max);
delay_ms(10);
write_to_eeprom(1,min);
delay_ms(10);

When I put the chip back to the programmer and read the eeprom - its empty. Has anybody experienced something similar with this pic and can help me?
Thanks a lot.
Ralph
barryg



Joined: 04 Dec 2006
Posts: 41

View user's profile Send private message

Re: Problem Writing to eeprom PIC18F4431
PostPosted: Thu Sep 24, 2009 5:55 pm     Reply with quote

It would be rather hard to pin down a problem that was specific to that chip, unless someone has found it before. Meanwhile, there may be questions about the values you write to the EEPROM, so I'd suggest something like this...the world's simplest test:
Code:
write_eeprom(0, 7);
write_eeprom(1, 6);
write_eeprom(2, 5);
write_eeprom(3, 4);

Then take that chip back to your programmer and see if it wrote anything. Then you'll know which way to proceed.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Sep 24, 2009 6:23 pm     Reply with quote

Make sure you're not accidently erasing the eeprom with your
programmer. See this thread and the link in it:
http://www.ccsinfo.com/forum/viewtopic.php?t=38325
Ralph
Guest







PostPosted: Fri Sep 25, 2009 12:12 am     Reply with quote

Hey,

I tried again, this time I simplified so that there can be no other reason but still not working.

I have also put in the read_eeprom command to check if he may can read the things I have saved. Not working.
But what is even worse - I have saved values to the eeprom with

#rom 0xf00000={1,2,3,4}

- but even these values he cant read during running. In the programming device its possible to read them.

As it looks to my I don't have any access during running to the eeprom.!?

Is it possible that this device has a strange address range for the eeprom?

Thanks
Ralph
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Sep 25, 2009 12:46 am     Reply with quote

Post a short but complete test program. It must be compilable.
It must have the #include, #fuses, #use delay, etc.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Fri Sep 25, 2009 1:55 am     Reply with quote

I used a PIC18F4431 with great success in a couple of projects.. I have the line:

Code:
#rom int 0xf00000={ 20, 0, 192, 0, 49, 1, 1, 1}


with a load and save routine that looks like:

Code:
void config_load_save ( int rw ) {
   int i;

   for (i=0;i<=(sizeof(system_config)-1);++i) {
      switch (rw) {
         case load : *(( (int8 *) &config) + i) = read_eeprom(i);
                  break;

         case save : write_eeprom( i, *(( (int8 *) &config) + i) );
                  break;
      }
   }
}


Besides your postable test code, what IDE/Programmer are you using?

I used MPLAB with an ICD2 or ICD3 -- CCS runs inside that. (PCWHD 4.099)

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Ttelmah
Guest







PostPosted: Fri Sep 25, 2009 2:15 am     Reply with quote

The obvious keyword here, is ICD.
Are you programming using the ICD as well?.
There are two possible problems here.

The fuses for write protection, on the EEPROM etc., _only_ get cleared, if you perform a full 'high voltage' erase function. I'd be suspecting, that these have been set at some point in the past, and are still set.
Try reading the fuses back from your chip. What is shown for the EEPROM write protection fuse (WRTD).
There should be an option on the programmer to perform a full erase. I'd guess this has been turned off, and only the program memory is being erased, leaving the fuses unchanged.

Some ICD's, also have limitations about the EEPROM, with restrictions like "won't update till chip is powered down". You need to check for any such limitations on yours.

Best Wishes
Ralph
Guest







PostPosted: Fri Sep 25, 2009 2:35 am     Reply with quote

Hey guys, thanks for your input.

I use a programmer by sprut - this is a very skilled private guy. I think there are thounds of programmers used according to his design. He also provides the programming software.

www.sprut.de

In this software you can check a box "Config from Hex-File", which means that all fuses are set directly from the code.

I gonna check with the fuse - but that doesnt explain why i cant even read the data which i have stored by

#rom int 0xf00000={ 20, 0, 192, 0, 49, 1, 1, 1}

I'm also going to try with a PIC of different type in soon to make sure - every thing else is working properly

Ralph
Ttelmah
Guest







PostPosted: Fri Sep 25, 2009 4:25 am     Reply with quote

You are missing the point.
In the programming software, there ought to be an _option_ for performing full erase. It is quite common to deliberately turn this off, since otherwise if (for instance) you store claibration constants in the EEPROM, these get destroyed if you reprogram the chip. There have been several posts here in the past, asking how to turn it off, for exactly this reason. On the fuses, the protection fuses are deliberately protected, so _once turned on_, they cannot be disabled by a normal programming cycle, with the chip having to be completely erased to disable them. I suspect that the 'full erase' option has been turned off in your programming software, probably 'by design', and at some point, the protection fuse has been set. You also refer to the EEPROM 'being empty'. _Empty_ PIC memory locations (after erase), read as '1'. Fom your comment, I suspect you are seeing zeros, in which case an erase is definately needed...

Best Wishes
Ralph
Guest







PostPosted: Mon Sep 28, 2009 6:06 am     Reply with quote

I dont think that this is the problem... I have an extra button "Erase PIC" which I have used several times.

No the eeprom is not showing zeros, its showing nothing.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Sep 28, 2009 12:24 pm     Reply with quote

Again:
Post a short but complete test program. It must be compilable.
It must have the #include, #fuses, #use delay, etc.

Also post your compiler version.
Ralph
Guest







I did
PostPosted: Thu Oct 01, 2009 1:44 pm     Reply with quote

Hey,

So thats very easy code - and working properly on PIC18F4550 but not on the 18F4431.
Code:

#include <18F4431.h>
#fuses NOWDT,NOPROTECT,NOBROWNOUT,NOMCLR, NOLVP, INTRC
#use delay(clock=4000000)

#define Status_LED PIN_C5
#define Bit4 PIN_A4
#define Bit3 PIN_A5
#define Bit2 PIN_E0
#define Bit1 PIN_E1
#define Bit0 PIN_E2

#rom 0xf00000={1,2,3,4}

int InitPIC(void)
{
   set_tris_a(0x00);
   set_tris_b(0x00);
   set_tris_c(0x04);
}


void main() {

int a;
int b;

InitPIC();

output_low(Bit1);
output_low(Bit2);
output_low(Bit3);
output_low(Bit4);
output_low(Bit0);

write_eeprom(9,5);
write_eeprom(10,6);
write_eeprom(11,7);

a = read_eeprom(2);
b = read_eeprom(9);

if (a==2) output_high(Bit2);
if (b==5) output_high(Bit4);

}
Ralph
Guest







PostPosted: Thu Oct 01, 2009 1:46 pm     Reply with quote

My compiler is version 3.249
Ralph
Guest







PostPosted: Thu Oct 01, 2009 1:56 pm     Reply with quote

Ok, a further comment from my side - the code on the 18F4431 can read from the eeprom - but it cant write.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 01, 2009 2:11 pm     Reply with quote

1. Are you testing this on a real hardware board, or is this being done
with the Proteus or Oshonsoft simulator ?

2. If it's a real hardware board, is it possible that you have damaged
the Data EEPROM on this PIC chip, by writing to it thousands of times
in a loop, in some previous test program ? The data eeprom has a
limited number of write operations that can be done, before it's burned up.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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