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.

CCS/EK-TM4C123GXL: CRC8 Wrong value

Part Number: EK-TM4C123GXL

Tool/software: Code Composer Studio

I'm interfacing an external ADC. Here, I need to compute CRC8 value. For that, I'm trying to use Software CRC library and its API. As a first step, I'm trying to just print the CRC value for the word = 0x654321. The expected answer is 0x86. But I get 0x91. Here's how my algo is written. I must be doing something wrong in the way I'm computing CRC value. Please correct me.

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_i2c.h"
#include "inc/hw_ints.h"
#include "driverlib/ssi.h"
#include "driverlib/interrupt.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sw_crc.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"


#include "inc/hw_nvic.h"
#include "inc/hw_memmap.h"
//#include "drivers/pinout.h"

#define NUM_SSI_DATA 4
uint32_t g_ui32SysClock,ADC=0,IF=0, rgchk=0, gpconfig=0,ch[4],setup[4],filter[4],offset[4],gain[4], ID2,flag=0,crc,ID3=0,F0,F1;




//Macros for swtich
#define Button_PERIPH SYSCTL_PERIPH_GPIOF
#define ButtonBase GPIO_PORTF_BASE
#define Button GPIO_PIN_4
#define ButtonInt GPIO_INT_PIN_4



#define POLYNOMIAL 0x107  /* 100000111 */

uint32_t pui32DataRx_1[NUM_SSI_DATA];
uint32_t pui32DataTx_1[NUM_SSI_DATA];
uint32_t ui32Index;
uint32_t temp;



float temp2 = 0,x=0;
uint32_t pui32DataRx[5],values[1000];
volatile uint_fast8_t ui8Delay;

uint32_t pui32DataTx[NUM_SSI_DATA];
uint32_t ID_REGISTER[3];
uint32_t temp3,mask,i=0,ifm=0;
uint8_t k=0;
int register_value=0;
char a;

uint8_t *p;



uint8_t Crc8CCITT(uint8_t ui8Crc, const uint8_t *pui8Data, uint32_t ui32Count);

//*****************************************************************************
//
// Configure the UART and its pins.  This must be called before UARTprintf().
//
//*****************************************************************************


//UART configuration
void ConfigureUART(void)
{
    //
    // Enable the GPIO Peripheral used by the UART.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    //
    // Enable UART0
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Configure GPIO Pins for UART mode.
    //
    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Use the internal 16MHz oscillator as the UART clock source.
    //
    UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);

    //
    // Initialize the UART for console I/O.
    //
    UARTStdioConfig(0, 115200, 16000000);
    UARTEnable(UART0_BASE);

    UARTprintf("UART config successful\n");
}


void main()
{

    //g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ|SYSCTL_OSC_MAIN|SYSCTL_USE_PLL |SYSCTL_CFG_VCO_480), 80000000);//Sets the clock Frequency
//    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); // Sets the clock at 80MHz
    ConfigureUART();

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOA)){}
    SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);
//    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_SSI2)){}
//    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
//    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOD)){}
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);


    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3);

    GPIOPinConfigure(GPIO_PB4_SSI2CLK);
    GPIOPinConfigure(GPIO_PB5_SSI2FSS);
    GPIOPinConfigure(GPIO_PB6_SSI2RX);
    GPIOPinConfigure(GPIO_PB7_SSI2TX);

    GPIOPinTypeSSI(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);

//    UARTprintf("%d\n",SysCtlClockGet());
    SSIConfigSetExpClk(SSI2_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_3,  SSI_MODE_MASTER, 10000000, 8);
    SSIEnable(SSI2_BASE);


    while(SSIDataGetNonBlocking(SSI2_BASE, &pui32DataRx[0]))
       {
       }


    uint8_t a[3];
    a[2]=0x21;
    a[1]=0x43;
    a[0]=0x65;


//    k = Crc8CCITT(0, a[0], 1);
//    k = Crc8CCITT(k, a[1], 1);
//    k = Crc8CCITT(k, a[2], 1);

      k = Crc8CCITT(0, *a,3);
    UARTprintf("%x",k);

  }