This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADS112C04: Could I have a sample program for ADS112C04 CRC checking?

Part Number: ADS112C04

 Hello guys,

 One of my customers is evaluating ADS112C04. But CRC error is happened in CRC check process. They requested us any sample program for CRC checking because their CRC check program may be wrong.

So could you please give me any sample program in C language?

 Your reply would be much appreciated.

 Best regards,

 Kazuya Nakai.

  • Hi Nakai-san,

    The ADS112C04 uses a 16-bit CRC and is computed for the entire data being returned (all except the actual CRC data).  It would be helpful to know what operation is taking place (RDATA, RREG, etc.) when the CRC is transmitted.  One example of the CRC calculation is shown below:

    /**
     * Calculation of 16-bit CRC.
     *
     * \details CRC result based on data sent to function and calculated as 16-bit
     * CRC. The calculation is returned as an unsigned short.
     *
     * \param 	u8Data The captured data.
     * \param	u8Length The length of the data in bytes for the calculation.
     *
     * \returns The 16-bit calculated CRC value.
     */
    uint16_t calcCRC(uint8_t *u8Data, uint8_t u8Length)
    {
    	uint8_t u8i;
    	uint16_t u16CRC		= 0xFFFF;			/* Initial value of crc register 	*/
    	uint16_t u16Poly	= 0x1021;			/* CRC polynomial (excluding bit 8) */
    	uint32_t u32Data 	= 0;				/* Data storage variable			*/
    	uint32_t u32MsbMask = 0x80000000;		/* Location of data's MSb			*/
    	bool bDataMSb;							/* MSb of data bytes				*/
    	bool bCrcMSb;							/* MSb of crc byte					*/
    	/* Construct data word from data bytes */
    	for(u8i = 0; u8i < u8Length; u8i++)
    	{
    		u32Data |= (uint32_t) ( u8Data[u8i] << 8*(u8Length - u8i - 1) );
    	}
    	/* Reduce the number of calculation cycles (by skipping any unused bytes) */
    	u32MsbMask >>= 8 * (4-u8Length);
    	/* CRC algorithm */
    	while (u32MsbMask > 0)
    	{
    		/* Check MSb values */
    		bDataMSb = (bool)(u32Data & u32MsbMask);
    		bCrcMSb 	= (bool)(u16CRC & 0x8000);
    		if (bDataMSb ^ bCrcMSb)	{ u16CRC = (u16CRC << 1) ^ u16Poly; } /* Shift and XOR */
    		else					{ u16CRC <<= 1; }				 /* Shift only 	  */
    
    		/* Shift MSb pointer and ensure that right-shift always produces a 0 */
    		u32MsbMask = (u32MsbMask >> 1) & 0x7FFFFFFF;
    	}
    	return(u16CRC);
    }

    Best regards,

    Bob B