At a glance, it looks like the "counter = 8?" decision block should probably have a "NO" path that feeds back to, probably, "the bit 15 CRC = 1?" decision block input. And the existing output of the "counter = 8?" decision block should be labelled "YES"...
As for the implementation, I'm having some trouble making sense of it. What is test_crc
and where is it defined? Shouldn't dta
be a pointer in the function signature? I made some updates to the code in your post to improve readability.
I faithfully implemented a function based on the block diagram and my assumption and ran it in IDEOne and get the result I think you expected... here's my code.
#include <stdio.h>
#include <stdint.h>
unsigned int crc16(uint8_t * data, uint8_t length)
{
uint16_t CRC = 0;
uint16_t A = 0, B = 0;
uint8_t index = 0, Counter = 0;
for( index = 0; index < length; index++ )
{
uint8_t byte = data[index];
A = CRC / 256;
A = A ^ byte;
A = A * 256;
B = CRC & 0xFF;
CRC = A | B;
for( Counter = 0; Counter < 8; Counter++ ){
if( CRC & 0x8000 )
{
CRC = CRC * 2;
CRC = CRC ^ 0x8005;
}
else
{
CRC = CRC * 2;
}
}
}
return CRC;
}
int main(int argc, char *argv[]){
uint8_t data[] = { 0x01, 0xBF, 0x15, 0x0F, 0x94, 0x95, 0x96, 0x97, 0x9F, 0x9E, 0xA2, 0xA0, 0x98, 0x99, 0x72, 0x6B, 0x6A, 0x88, 0x89, 0x64, 0x62, 0x63, 0x65, 0x66, 0x03 };
uint8_t length = sizeof(data);
uint16_t crc = 0;
printf("Length = %d\n", length);
crc = crc16(data, length);
printf("CRC = %04x", crc);
return 0;
}
It outputs:
Length = 25
CRC = ac2d
This may help, from my reading the E4 or G4 designation seems to be based on the RoHS information; E4 and G4 are basically the same but the E values are used for JEDEC marking while the G values are used for TI-Green marking.
As for the pricing I can only speculate that Texas Instruments would prefer to sell one part (the G4 part in this case) over the other options.
Best Answer
For an ADC whose natural format is offset binary, 2's complement is the natural way to represent signed numbers. All it has to do is invert the MSB.