CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

ds18b20:CRC Function instead of CRC table

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
FFT



Joined: 07 Jul 2010
Posts: 92

View user's profile Send private message

ds18b20:CRC Function instead of CRC table
PostPosted: Fri Nov 26, 2010 11:25 am     Reply with quote

Hi All,

I'm trying to replace the crc table with a function that calculates 8-bit crc for ds18b20 sensor because of limited ROM space, but no chance.

I'm using exactly that code in:
http://www.ccsinfo.com/forum/viewtopic.php?p=126649#126649

I've found this function:
Code:
//calc_CRC - INTERNAL FUNCTION
//Purpose:    To calculate an 8-bit CRC based on a polynomial and the series
//            of data bytes
//Note:       Polynomial used x^8 + x^5 + x^4 + 1 = 10001100
//Inputs:     A pointer to an array of the data bytes and an int saying how many
//            bytes there are in the data array
//Outputs:    An int8 which is the calculated CRC
int8 ds18b20_calc_CRC(int8* data, int8 bytes)
{
   #define CRC_POLY      0x8C
   int8 shift_register = 0, i, datab, bits;

   for(i = 0; i < bytes; ++i)
   {
      datab = *(data + i);
      for(bits = 0; bits < 8; ++bits)
      {
         if(bit_test((shift_register ^ datab), 0))
         {
            shift_register = shift_register >> 1;
            shift_register ^= CRC_POLY;
         }
         else
            shift_register = shift_register >> 1;
         datab = datab >> 1;
      }
   }
   return shift_register;
} //calc_CRC


Just I've changed the row in ds1820_read() function:
Code:
if (scratch[8] == dowcrc)

to
Code:
if (scratch[8] == ds18b20_calc_CRC(scratch[0], 7)) // Calculate a 8-bit crc for all 7 scratch bytes
In the linked code, but it does not work.

Also I've tried it as:
Code:
// One wire crc
int8 ow_crc(int8 x)
{
//   dowcrc = dscrc_table[dowcrc^x];
   dowcrc = ds18b20_calc_CRC(x,8);
   return dowcrc;
}

As said in : http://www.ccsinfo.com/forum/viewtopic.php?t=41878

As another way I've found this link:
http://www.phanderson.com/PIC/16C84/crc.html
The C function on link should call for every byte I think, I tried some variants to import it into my code but could not make it works too...

I need help to replace crc table with a function for reducing rom usage.

Best regards
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Nov 27, 2010 7:50 pm     Reply with quote

This is basically a Google question, where you search for code.
There are ds18b20 CRC routines on this forum:
http://www.ccsinfo.com/forum/viewtopic.php?t=40106&start=14
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group