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.

DAC8760: CRC-8-ATM Calculation algorithm

Part Number: DAC8760

How is the CRC calculated for the DAC8760? Could you please provide source 'C' code or enough information so I can get the job done?

  • Hi Michael,

    Welcome to E2E and thank you for your query. We don't have any CRC C code implementation. But I found some third-party sources that might help:

    www.rajivchakravorty.com/.../crc8_8c-source.html

    https://crccalc.com/

    Regards,
    Uttam Sahu
    Applications Engineer, Precision DACs
  • Hi,

    I'm pretty much doing just as the links you provided, except I'm not using a table yet. I wanted to verify that I can communicate with the DAC using the CRC before creating the table.

    Here's the code:

    BYTE CalcCRC8(int count, BYTE *pdata)
    {
      int bit, i = 0;
      BYTE crc = 0x00;

      while(i < count) // for each byte
      {
        crc ^= *pdata; // Get the data byte
        for(bit = 0; bit < 8; bit++)
        {
          if((crc & 0x80) != 0x00)
            crc = (crc << 1) ^ CRC8_ATM;  // CRC8_ATM = 0x07
          else
            crc <<= 1;
        } // end for
        pdata++; // next byte
        i++;
      } // end while

      return crc;
    } /* End CalcCRC8 */

    and below is the calling function:

    void DAC8760_Out_crc(const int ch, const uint value)
    {
      W2B val;
      uint junk;
      int time;
      BYTE msg[3];
      BYTE crc;

      val.w = value;

      // Address byte = DAC REG
      msg[0] = DAC8760_DAC_REG;
      msg[1] = val.b[1]; // MSB
      msg[2] = val.b[0]; // LSB
      crc = CalcCRC8(3, msg);

      // Address byte
      DAC_SPI_OUT_BUF = DAC8760_DAC_REG;
      time = DAC_SPI_WAIT_TM;
      WAIT4_SPI2_XMIT;
      while((!DAC_SPI_RBF) && (time-- > 0)); // wait till finished
      junk = DAC_SPI_IN_BUF;
      DAC_SPI_OUT_BUF = val.b[1]; // MSB
      time = DAC_SPI_WAIT_TM;
      WAIT4_SPI2_XMIT;
      while((!DAC_SPI_RBF) && (time-- > 0)); // wait till finished
      junk = DAC_SPI_IN_BUF;
      DAC_SPI_OUT_BUF = val.b[0]; // LSB
      time = DAC_SPI_WAIT_TM;
      WAIT4_SPI2_XMIT;
      while((!DAC_SPI_RBF) && (time-- > 0)); // wait till finished
      junk = DAC_SPI_IN_BUF;
      DAC_SPI_OUT_BUF = crc; // the CRC
      time = DAC_SPI_WAIT_TM;
      WAIT4_SPI2_XMIT;
      while((!DAC_SPI_RBF) && (time-- > 0)); // wait till finished
      junk = DAC_SPI_IN_BUF;

      ENTER_CRITICAL_SECTION(50);

      DAC8760_Latch_Low(ch);
      DAC8760_Latch_High(ch);

      EXIT_CRITICAL_SECTION();

      return;
    } /* End DAC8760_Out_crc */

    As you can see I'm sending the 32 bits which includes the CRC, and the DAC doesn't set the output accordingly.

    When I don't enable the CRC in the DAC and therefore only send 24 bits (from a different function that doesn't append the CRC) it works great!! Except for the other devices on the SPI bus which most likely are causing the data to be "mis-aligned" when they are receiving data over the SPI bus or some other phenom that causes the DAC to drop it's output, but that's a different issue I will need to deal with...First the CRC??

    Does the above code look like it should work?

    Regards,

    Mike

  • Now that you have device specific queries, I am assigning the thread to my colleague Garrett who handles this part.

    Regards,
    Uttam
  • Hi Michael,

    It is difficult for me to tell if this code is correctly generating the CRC based on the SPI frame. Can you provide what SPI frame you are writing and what the corresponding 8-bit CRC your code is generating? It would also be helpful if you provided a scope capture of the entire 32-bit frame with SDO, SCLK, and LATCH in one plot.

    A few other questions:

    1. Did you set the CRCEN bit in the configuration register?
    2. Is the ALARM pin go low after you write the 32-bit frame?
    3. Are you able to get an output from the DAC?

    Thanks,
    Garrett
  • Hi Michael,

    Any update on this?

    Thanks,
    Garrett
  • Hi Garrett, Yes I set the CRC Enable bit in the DAC, and once the bit is set it appeared that I could no longer communicate with the IC. I do get output and have no trouble with communication as long as I do not enable the CRC. We have made some modifications to the circuit (SPI) removing one of the other devices from sharing the SPI with the DACs. Since then I haven't had time to try the CRC. Maybe I will get some time today. I'll let you know. Thanks for your help. Mike

  • Hi Mike,

    Did you have a chance to try the CRC again after your modifications?

    Thanks,
    Garrett