IAR C Compiler __eeprom pointer problem

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi there,

I have a serious problem using the IAR C compiler V5.11B.
My code is shown below:

volatile UC __eeprom *pData;

bool known_card(UC *data){
	UC validCounter;
	UC *dataStore;
	
	dataStore = data;
	pData = EEPROM_MEMORY_B_START;
	while (pData < (TOTAL_FRAMES * FRAME_BYTES) + EEPROM_MEMORY_B_START){
		validCounter = 0;
		data = dataStore;
		for (UC i = 0; i < 11; i++){
			if (*pData == *data){
				validCounter++;
			}
			pData++;
		}
		if (validCounter == 11){
			return true;
		}
	}
	return false;
}

And the way I call this function is:

test = known_card(&uartData[0]);

After building the application there are 2 errors:

1st:
Error[Pe042]: operand types are incompatible ("unsigned char volatile __eeprom *" and "int") E:\Projects\Project_RF_ID\Addressable System\version 2\RF-54\_code\cfiles\bios.c 251

2nd:
Error[Pe167]: argument of type "unsigned char volatile *" is incompatible with parameter of type "unsigned char *" E:\Projects\Project_RF_ID\Addressable System\version 2\RF-54\_code\cfiles\main.c 45

Could you please help me solve my problem???

I know that this forum is not for IAR C compiler users, but there is nowhere to post it in the www.avrfreaks.net

Thanks for your time,

Michael.

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I forgot to tell you that I use the controller ATmega88PV with internal EEPROM 512bytes.

Also the 1st Error represents the line of code:

while (pData < (TOTAL_FRAMES * FRAME_BYTES) + EEPROM_MEMORY_B_START){ 

where:
(TOTAL_FRAMES * FRAME_BYTES) + EEPROM_MEMORY_B_START
is a constant equals to 440

and the 2nd error represents the line of code:

test = known_card(&uartData[0]); 

Michael.

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Surely this is just standard C (though you haven't shown us the #define). Change:

pData = EEPROM_MEMORY_B_START; 

to be:

pData = (volatile UC __eeprom *)EEPROM_MEMORY_B_START;

Remember that in:

#define EEPROM_MEMORY_B_START 1234

the 1234 is of type "int" so you cannot just assign it directly to a pointer without a typecast

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok,

#define	FRAME_BYTES		11
#define	TOTAL_FRAMES		40

/* define EEPROM addresses */
/* Start of B memory (20 x 11 bytes frame - it means that 20 cards can be stored) */
#define EEPROM_MEMORY_B_START	0x00

/* Start of C memory (20 x 11 bytes frame - it means that 20 cards can be stored) */
#define	EEPROM_MEMORY_C_START	0xDC

But,

pData is a pointer and it points to a 512 byte's EEPROM (more than 8 bits address), unsigned char datas.

1st:

pData = (volatile UC __eeprom *)EEPROM_MEMORY_B_START; 

The constant EEPROM_MEMORY_B_START is an EEPROM address more than 8 bits, so casting this literal and load it to pData (not *pData) will cause crazy errors (not compile errors but programming errors).

2nd:
my problem is not at this line of code, but at the next where the pData is compared with another EEPROM address.

while (pData < (TOTAL_FRAMES * FRAME_BYTES) + EEPROM_MEMORY_B_START){ 

Althought I have test your suggestion, I think that there is not something wrong on this line, needs casting.

If I didn't get what you are trying to tell me, could you please be more detailed???

Michael.

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well again in the comparison you are comparing the value held in a pointer to an int. The compiler won't like this either. So you'll have to either cast the pointer contents to an int or the integer constant to be a pointer value of the same type as the pointer. That is either:

while ((int)pData < (TOTAL_FRAMES * FRAME_BYTES) + EEPROM_MEMORY_B_START){

or

while (pData < (volatile UC __eeprom *)((TOTAL_FRAMES * FRAME_BYTES) + EEPROM_MEMORY_B_START)){

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Cliff,

You are right, I got it and my problem is fixed.

Thanks for your help.

Michael.

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer