pastebin - collaborative debugging tool
blankb.kpaste.net RSS


DS28CM00R Serial ID
Posted by Anonymous on Thu 5th Nov 2015 21:46
raw | new post

  1. //Arduino UNO code to read the
  2. // DS28CM00R-A00+T
  3. // DS28CM00R
  4. // Security ICs / Authentication ICs I2C/SMBus Silicon Serial Number
  5. // Tested with arduino.cc 1.5.8
  6.  
  7. #include <Wire.h>
  8.  
  9. byte incomingData[9]={ 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00 };
  10. void setup()
  11. {
  12.  
  13.   byte retV;
  14.  
  15.   Serial.begin(9600);
  16.  
  17.   for (int i=0; i<5; i++)
  18.   {
  19.     Serial.println("Boot...");
  20.    
  21.     delay(500);
  22.   }
  23.  
  24.  
  25.  
  26.   Wire.begin();
  27.  
  28.   delay(100);
  29.   Serial.println("Trying to read\n");
  30.  
  31.   delay(100);
  32.   retV=Wire.requestFrom(0x50, 9);
  33.   Serial.print("Result: [");
  34.   Serial.print(retV,DEC);
  35.   Serial.println("]");
  36.  
  37.   int incomingPointer=0x00;
  38.   while(Wire.available())    // slave may send less than requested
  39.   {
  40.     byte c = Wire.read();    // receive a byte as character
  41.     if (c<0x10) {Serial.print("0");}
  42.     Serial.print(c &0xFF,HEX);         // print the character
  43.     Serial.print("-");
  44.     incomingData[incomingPointer]=(byte)(c);
  45.     incomingPointer++;
  46.   }
  47.   Serial.println("------------");
  48.  
  49.   int deviceFamily=incomingData[0];
  50.   unsigned long serialNumber=0x00;
  51.   unsigned long upperSerialNumber=0x00;
  52.  
  53.   byte calcChecksum=0x00;
  54.  
  55.   for (int i=0; i<9; i++)
  56.   {
  57.     Serial.print(i,DEC);
  58.     Serial.print("=0x");
  59.     if (incomingData[i]<0x10) {Serial.print("0");}
  60.     Serial.print(incomingData[i]&0xFF,HEX);
  61.     Serial.print(",");
  62.     Serial.print(incomingData[i],DEC);
  63.     Serial.println(" ");
  64.   }
  65.  
  66.  
  67.   upperSerialNumber+=((unsigned long)incomingData[5])<<0;
  68.   upperSerialNumber+=((unsigned long)incomingData[6])<<8;
  69.   upperSerialNumber+=((unsigned long)incomingData[0])<<16;
  70.  
  71.   serialNumber+=((unsigned long)incomingData[1])<<0;
  72.   serialNumber+=((unsigned long)incomingData[2])<<8;
  73.   serialNumber+=((unsigned long)incomingData[3])<<16;
  74.   serialNumber+=((unsigned long)incomingData[4])<<24;
  75.  
  76.   byte checkSum=incomingData[7];
  77.  
  78.  
  79.   Serial.println("================");  
  80.  
  81.   Serial.print("DeviceFamily=");
  82.   Serial.print(deviceFamily,HEX);
  83.   Serial.println(" ");
  84.  
  85.   Serial.print("Upper 32 Bit ID=0x");
  86.   Serial.print(upperSerialNumber,HEX);  
  87.   Serial.print(" =  DEC ");
  88.   Serial.print(upperSerialNumber,DEC);
  89.   Serial.println(" ");
  90.  
  91.  
  92.   Serial.print("Lower 32 Bit ID=0x");
  93.   Serial.print(serialNumber,HEX);  
  94.   Serial.print(" =  DEC ");
  95.   Serial.print(serialNumber,DEC);
  96.   Serial.println(" ");
  97.  
  98.  
  99.   calcChecksum=CRC8(incomingData,7);
  100.   Serial.print("Checksum=");
  101.   Serial.print(checkSum,HEX);
  102.   Serial.print(" == ");
  103.   Serial.print(calcChecksum,HEX);
  104.   Serial.print(" ");
  105.   if (checkSum==calcChecksum) Serial.print("MATCH");
  106.     else Serial.print("NO Match");
  107.   Serial.println(" ");
  108.   Serial.println("Note: Upper Serial # contains deviceFamily + bits 40 to 47 + bits 32 to 39");
  109.  
  110.   Serial.println("Done");
  111. }
  112.  
  113.  
  114. void loop()
  115. {
  116. }
  117.  
  118.  
  119.  
  120.  
  121. //CRC-8 - based on the CRC8 formulas by Dallas/Maxim
  122. //code released under the therms of the GNU GPL 3.0 license
  123. //https://github.com/rpicopter/AvrMiniCopter-Arduino/blob/master/crc8.h
  124. byte CRC8(const byte *data, byte len)
  125. {
  126.   byte crc = 0x00;
  127.   while (len--)
  128.   {
  129.     byte extract = *data++;
  130.     for (byte tempI = 8; tempI; tempI--)
  131.     {
  132.       byte sum = (crc ^ extract) & 0x01;
  133.       crc >>= 1;
  134.       if (sum)
  135.       {
  136.         crc ^= 0x8C;
  137.       }
  138.       extract >>= 1;
  139.     }
  140.   }
  141.   return crc;
  142. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}





All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at