crc16 supplied code

Thanks Guys for the fast responses,

im happy the code is right i actually tried sending a array must have done something stupid (as usual).....

Thanks mark i agree your code looks better and easier to read :slight_smile:

MarkT:
You are trying to set a variable of char * type to 7. 7 is an integer, not a pointer-to-char.

Why not something like

void whatever ()

{
  unsigned char buffer [BUFLEN] ;
  .. put stuff in buffer
  unsigned int reply = uiCrc16Cal (buffer, BUFLEN) ;
  .. use the crc...




In Arduino you don't need to say "short" as ints are already 16 bit.


Personally I'm not a fan of verbose coding style with types encoded in the variable names, and that
function is probably a lot easier to understand rewritten more concisely with better var names:


unsigned int uiCrc16Cal (byte * buf, byte len)
{
  unsigned int crc = PRESET_VALUE ;
  for (byte i = 0; i < len; i++)
  {
    crc ^= buf [i] ;
    for (byte j = 0; j < 8; j++)
    {
      unsigned int feedback = (crc & 0x0001) == 0 ? 0 : POLYNOMIAL ;
      crc = (crc >> 1) ^ feedback ;
    }
  }
  return crc ;
}

ok sorry i know i read in some books i must put it in "" totally slipped my mind thank you!!

[quote author=Nick Gammon link=topic=141151.msg1060824#msg1060824 date=1357545875]

unsigned char const * cardno = 7;

Do you mean:

unsigned char const * cardno = "7";

Your code had the address of a pointer to who-knows-what at address 7.

[/quote]
Thank you Rob, i have looked at that and i wasnt sure if that is the same as this(or would compute the same :fearful:

robtillaart:
you can also consider using - avr-libc: <util/crc16.h>: CRC Computations -

ok now to get working again :slight_smile:

Thanks everyone ill report back how it goes :smiley:

regards
Willie