Main Menu

Pointer problems.

Started by Ty, March 24, 2004, 08:02:51 AM

Previous topic - Next topic

Ty

I am trying to read a string of bytes in my Flash memory at a specific address that I placed in my startup assembly file. I am using a 89LPC932 and the Keil C compiler.  I am doing the following.

To declare a pointer in my C code to the fixed byte string in FLASH I do this.

char* data_ptr = (char*) 0x0030 ;

To get to the bytes in my code I do this.

byte_data = data_ptr[counter] ; ( Where I increment the counter as I go )

This doesn't seem to work and I have asked a number of experienced coders around where I work and they don't understand why this wouldn't work. I have tried messing with this in many different ways with no success. I look at the assembly instructions and it would seem the compiler should be able to do this in about 2 instructions, but it is doing a whole bunch of instructions and calls this C?CDLOPTR function and does some more instructions, but always comes up with bogus data.

So do you have to do something weird to get something like this to work.

Andy Ayre

Use:

char code *data_ptr = (char code *)0x0030;

byte_data = data_ptr[counter++];

or you can increment the counter on the next line if you prefer.

Without the code keyword, you are attempting to access the default memory space for the memory model you have selected. See the section in the C51 manual regarding the memory models.

Embedded Systems Academy, Inc.
support at esacademy dot com

Ty

Thanks,

I am sorry I realized afterwards this is board is for flash magic. I was getting fustrated and wasn't thinking. For some reason the Keil help window won't let me get to half of the help for some reason.

Yes after beating my head around for most of the morning I finally figured it out. I had tried it before but you have to be very carful about where you put the "code" keyword.

This doesn't work (which was one of the first things I tried)- it gets a compiler parse error.

code char * data_ptr = (code char*) 0x0030 ;

This works!!!

code char * data_ptr = (char code *)  0x0030 ;

Go figure.... I would think it should matter what order it is in.

I also noticed that if you do this.

char code * data_ptr = (char code *) 0x0030 ;

This will compile, but it doesn't put the pointer into Code memory like you think it should.