|
|
View previous topic :: View next topic |
Author |
Message |
Fabri
Joined: 22 Aug 2005 Posts: 275
|
write_eeprom and PIC16F684 |
Posted: Sat Aug 26, 2006 12:43 am |
|
|
Hi Everybody,
I have a problem with write_eeprom and PIC16F684. The same routine work fine with other pic, for example PIC16F877 and PIC16F690.
this is the part of routine:
Quote: |
#define adr_zero_l 10
#define adr_zero_m 11
#define adr_zero_h 12
unsigned int32 zero;
zero=0x00023280;
write_eeprom(adr_zero_h,make8(zero,2));
write_eeprom(adr_zero_m,make8(zero,1));
write_eeprom(adr_zero_l,make8(zero,0));
|
When I read, in second step, the 3 location I found the last value I tryed to write.
In adr_zero_h I found 0x80;
In adr_zero_m I found 0x80;
In adr_zero_l I found 0x80;
I tryed to save the 24bit of zero in more step and writing any byte and testing all but the result doesn't change.
I belive there's a problem in writing routine.
My compiler il PCWH V 3.249.
Somebody help me about ?
Regards,
[/quote] |
|
|
Ttelmah Guest
|
|
Posted: Sat Aug 26, 2006 8:48 am |
|
|
I have just tested it with the following code, and 3.249:
Code: |
#define adr_zero_l 10
#define adr_zero_m 11
#define adr_zero_h 12
void main()
{
unsigned int32 zero;
int8 temp;
zero=0x00023280;
write_eeprom(adr_zero_h,make8(zero,2));
write_eeprom(adr_zero_m,make8(zero,1));
write_eeprom(adr_zero_l,make8(zero,0));
temp=read_eeprom(adr_zero_h);
printf("high : %u/n",temp);
temp=read_eeprom(adr_zero_m);
printf("mid : %u/n",temp);
temp=read_eeprom(adr_zero_l);
printf("low : %u/n",temp);
while(1) ;
}
|
and it worked fine, giving 2, 50, 128. Also, reading the chip in the programmer after running, showed the bytes happily sitting in the EEPROM.
Two possibilities. The first is that you have a chip with a faulty EEPROM (or have 'worn it out', by doing some program loop with rapid writes - it is suprising how quickly the EEPROM like can be used up like this. The second is that something else is wrong in the code.
Best Wishes |
|
|
Fabri
Joined: 22 Aug 2005 Posts: 275
|
|
Posted: Sat Aug 26, 2006 1:43 pm |
|
|
Hi Ttelmah,
As I told you, the same program work fine with PIC16F690. I changed also chip without difference. I developed the program for PIC16F690 with ICD2 debugger and after I traslate it to PIC16F684 and I controlled data printing out as you done.
I don't realize were's the problem....
By the way, shall I install more then one version of compiler in the same PC ?
Thanks for test compiler versione,
Fabri |
|
|
Ttelmah Guest
|
|
Posted: Sat Aug 26, 2006 3:24 pm |
|
|
I tested it on a 684...
It runs fine.
Best Wishes |
|
|
Fabri
Joined: 22 Aug 2005 Posts: 275
|
|
Posted: Mon Aug 28, 2006 1:59 am |
|
|
Hi,
The problem was in printing out 32 bit of zero. Actually the eeprom location was right.
I used:
Quote: |
printf("zero= %LX",zero);
|
So I print out the 32 bit in three time.
Which the right way to print out 32 in one time ?
Thanks for help,[/quote] |
|
|
Guest
|
|
Posted: Mon Aug 28, 2006 4:18 am |
|
|
"%LX", prints out the whole 32bit number.
What you show is 'right'.
If you want the output to be constant length (as your input value, with leading zeroes), then use "%08LX".
To print the number as input, use "0x%08LX".
As an 'aside', though make8, and make32 exist, and work, they are 'non portable', if you ever want to move your code to another processor. Personally, I prefer to do the transfers using a union, which is standard C.
So:
Code: |
int8 ctr;
union {
int8 b[4];
int32 zero;
} join;
join.zero=0x00023280;
for (ctr=0;ctr<3;ctr++) write_eeprom(addr_zero_l+ctr,join.b[ctr+1]);
//Because we only transfer the low three bytes, there is an offset needed.
//Transfers all three bytes to the eeprom
join.zero=0;
for (ctr=0;ctr<3>0;) printf("Byte %d = %x/n",ctr,join.b[(ctr--)+1]);
|
Best Wishes |
|
|
Fabri
Joined: 22 Aug 2005 Posts: 275
|
|
Posted: Mon Aug 28, 2006 5:40 am |
|
|
Hi Everibody,
I'm sorry for confusion but I'm quite nervous about this software.
Printing out work fine with option "%LX" but the real problem, in my software, is convertion with make32.
I use make32 to load the 3 eeprom location in one 32 bit location so:
Quote: |
zero=make32(0,read_eeprom(adr_zero_h),read_eeprom(adr_zero_m)
,read_eeprom(adr_zero_l));
|
For example:
Location adr_zero_h contain 0x20;
Location adr_zero_m contain 0x30;
Location adr_zero_l contain 0x40;
I'm waiting for zero=0x203040 but make32 return me zero=0x404040.
otherwise,
Quote: |
p_h=read_eeprom(adr_zero_h);
p_m=read_eeprom(adr_zero_m);
p_l=read_eeprom(adr_zero_l);
zero=make32(0,p_h,p_m,p_l);
|
work fine and in zero I found the correct value,
Thanks for any opinion about, |
|
|
Ttelmah Guest
|
|
Posted: Mon Aug 28, 2006 7:37 am |
|
|
The problem here is that the function expects to receive numeric values, _not_ the output from other functions. There is only a single 'scratch' area used for return values, so when the third function is executed the return values from the earlier functions have been destroyed, giving you the '404040' result. You need to transfer the return values into variables, and call make32 with these. Using a union, is safer here, since the values are transferred to the required bytes of the union one at a time, getting rid of this problem, without needing three extra scratch variables...
Note that the manual, specifically lists the values needed for make32, as variables, for this reason.
Best Wishes |
|
|
Fabri
Joined: 22 Aug 2005 Posts: 275
|
|
Posted: Mon Aug 28, 2006 9:27 am |
|
|
Hi,
I changed return function with numeric value and now work fine.
I understand now but I don't realize why the software work with PIC16F690 and the return value of make32 is correct as I espect.
Regards,
Fabri |
|
|
|
|
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
|