AnsweredAssumed Answered

AD7176 ReadRegister CRC code

Question asked by Tom_Spargo on Dec 2, 2014
Latest reply on Dec 11, 2014 by jcolao

I have the ADI C code for the AD7176-2 (see below). When CRC is enabled, shouldn't there be a CRC calculation for the write command to the Communications Register that occurs before the read operation? The CRC result should be added to 'buffer' and then SPI_Read would be called...?

 

Thanks,

 

Tom

 

int32_t AD7176_ReadRegister(st_reg* pReg)

{

    int32_t ret       = 0;

    uint8_t buffer[8] = {0, 0, 0, 0, 0, 0, 0, 0};

    uint8_t i         = 0;

    uint8_t check8    = 0;

  uint8_t msgBuf[8] = {0, 0, 0, 0, 0, 0, 0, 0};

 

    /* Build the Command word */

    buffer[0] = COMM_REG_WEN | COMM_REG_RD | pReg->addr;

   

    /* Read data from the device */

    ret = SPI_Read(AD7176_SLAVE_ID,

                   buffer,

                   ((AD7176_st.useCRC != disable) ? pReg->size + 1

                                                  : pReg->size) + 1);

    if(ret < 0)

        return ret;

 

    /* Check the CRC */

    if(AD7176_st.useCRC == use_CRC)

    {

    msgBuf[0] = COMM_REG_WEN | COMM_REG_RD | pReg->addr;

    for(i = 1; i < pReg->size + 2; ++i)

    {

    msgBuf[i] = buffer[i];

    }

    <Shouldn't there be a CRC calculation here?>

    check8 = AD7176_ComputeCRC8(msgBuf, pReg->size + 2);

    }

    if(AD7176_st.useCRC == use_XOR)

    {

        msgBuf[0] = COMM_REG_WEN | COMM_REG_RD | pReg->addr;

        for(i = 1; i < pReg->size + 2; ++i)

        {

            msgBuf[i] = buffer[i];

        }

        check8 = AD7176_ComputeXOR8(msgBuf, pReg->size + 2);

    }

<snipped>

Outcomes