EmbDev.net

Forum: µC & Digital Electronics CodeVision AVR: pointer type problem


Author: X- Rocka (x-rocka)
Posted on:

Rate this post
0 useful
not useful
Hi,

my CodeVision AVR is doing crazy things, but okay, more probable is that 
I don't see my mistake...
I get the following error message (latest CV-version 2.04.4a, for 
ATmega168P)
Error: D:\...\project_sercom.c(639), included from: project_0-1.c: function argument #1 of type 'char' is incompatible with required parameter of type 'char *'
// function call which the error refers to:
CRC_calc(*data_buf0, *datbuf0_cnt);

// the used global char array:
char data_buf0[DATA_BUF0_MAX];

// function:
void CRC_calc(char *data_buf, unsigned char *buf_cnt)
{
  unsigned char i = 0;
  unsigned char local_buf_cnt = 0;
  unsigned int ui_CRC = 0;
  char CRC_ASCII_byte[3] = { 0, 0, 0 };

  local_buf_cnt = *buf_cnt;

  // Calculate 16bit unsigned int CRC
  ui_CRC = ui_CRC ^ address;
  for ( i = 0; i < buf_cnt; i++ )
  {
    ui_CRC = ui_CRC ^ *(data_buf + i);
    if ( ( 0x0001 && ui_CRC ) == 1 ) ui_CRC = ( 0x7FFF & ( ui_CRC >> 1 ) ) ^ 0xA001;
    else ui_CRC = 0x7FFF & ( ui_CRC >> 1 );
  }

  // put CRC into 3 ASCIIs:
  CRC_ASCII_byte[0] = 0x40 | ( 0x000F & ( ui_CRC >> 12 ) );
  CRC_ASCII_byte[1] = 0x40 | ( 0x003F & ( ui_CRC >> 6 ) );
  CRC_ASCII_byte[2] = 0x40 | ( 0x003F & ui_CRC );

  // add the 3 CRC ASCIIs to buffer:
  for( i = 0; i < 3; i++ ) *(data_buf + local_buf_cnt + i) = CRC_ASCII_byte[i];
  *buf_cnt = local_buf_cnt + 3;
}

somewhere else in the code the pointers work perfectly, a string (char 
array) is copied to a data buffer. no problems there.

please help!

X

Author: 12er Dude (Guest)
Posted on:

Rate this post
0 useful
not useful
hello x,

please try this:

CRC_calc(data_buf0, *datbuf0_cnt);

or

CRC_calc(&data_buf0[0], *datbuf0_cnt);

the declaration of datbuf0_cnt is missing in your code.

Tschü Dude

Author: X- Rocka (x-rocka)
Posted on:

Rate this post
0 useful
not useful
Dude!

THANKS! ouch, WTF did I put the "*" into the function call...

Thanks, now it works!

Did I say thanks?!

X

Author: SIna (Guest)
Posted on:

Rate this post
0 useful
not useful
What does this error message mean? " ']' not expected "
Tnx

Author: bracket (Guest)
Posted on:

Rate this post
0 useful
not useful
The balance of braces is odd.

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.