View previous topic :: View next topic |
Author |
Message |
vetinaspin
Joined: 19 Nov 2005 Posts: 5 Location: Devon, England
|
pointer error on PIC18F452 |
Posted: Sat Nov 19, 2005 4:55 am |
|
|
Hi There.
New user, so may be lacking in forum etiquette.
I have a problem with a pointer using CCS compiler 3.163 and PIC18F452.
We are using the Progressive Learning Resources code for SD/MMC control.
In that code a pointer is delared char* fp->fpntr;
Later the pointer is incremented to point inside a 512 byte buffer.
After 2 days of digging deeper and deeper into the code I find that the statement fp->fpntr++; works fine until 0x2ff when it rolls over to 0x200 not 0x300 !! This then points to another area of memory and trashes everything.
Is this a known compiler problem?
Aren't all PIC18F pointers 16-bit ? I tried #device *=16 but made no difference
I considered upgrading the compiler, but am waiting for DSPIC suport. Does anyone know if I am better or worse off to upgrade compiler now and then upgrade to DSPIC later or should I wait and do it all inone go?
Thanks for any help. |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
Re: pointer error on PIC18F452 |
Posted: Sat Nov 19, 2005 12:29 pm |
|
|
vetinaspin wrote: | char* fp->fpntr;
fp->fpntr++; works fine until 0x2ff when it rolls over to 0x200 not 0x300 !! |
Why did you declare the pointer variable as a Char? Thats only a byte. Your not trying to point to a byte your trying to point to an address.For more than 256 addresses you need the pointer to be 2 bytes. I seldom seen the use of -> in embeded code. You can reach any RAM address with a 16bit pointer. |
|
|
vetinaspin
Joined: 19 Nov 2005 Posts: 5 Location: Devon, England
|
Re: pointer error on PIC18F452 |
Posted: Sun Nov 20, 2005 10:15 am |
|
|
Hi Neutone
Thanks for your reply.
Quote: | Why did you declare the pointer variable as a Char? Thats only a byte. |
I didn't. That's the code from Progressive Learning. Anyway shouldn't all pointers be 16 bit by default? - but they need to know whether they are pointing to an 8-bit, 16-bit or 32-bit value, so I think the declaration is valid. Despite that, I did try changing the code to a 16-bit value, with no effect.
Quote: | Your not trying to point to a byte your trying to point to an address. |
But it's a 16-bit pointer, pointing to an 8-bit value.
Quote: | For more than 256 addresses you need the pointer to be 2 bytes. |
My point (excuse the pun) is that I thought the compiler determined the pointer size, not the declaration, or have I got this horribly wrong? If I have an array of char starting at say, location 0x300 (determined by the compiler) I would declare this as char my_array[10] = "ABCDEFGHI" or char* my_array; and then populate my_array. But my_array would be the address which would be 16-bit, and my_array+3 would be 0x303 which would point to "D".
If I dereference the pointer by e.g. x = *my_array then x will be "A", an 8-bit value as this was the original declaration type.
I'll go back and look at their code again to see if I can find the error.
I wondered if anybody else had come across this with CCS version 3.163? |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
Re: pointer error on PIC18F452 |
Posted: Sun Nov 20, 2005 10:21 am |
|
|
vetinaspin wrote: |
I considered upgrading the compiler, but am waiting for DSPIC suport. Does anyone know if I am better or worse off to upgrade compiler now and then upgrade to DSPIC later or should I wait and do it all inone go?
|
I doubt very seriously that upgrading is going to get you dspic support. That will be another compiler. CCS already has PCB, PCM, PCH for the different PICs so it seems to reason they would have a separate one for the DSPIC.
As for your problem, post a small test program showing the error. |
|
|
|