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?
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.
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,
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
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