I bought the DAC7612 and would like to make it communicate with a PIC18F26K80 microcontroller. It is specified on the Farnell website that you can use SPI communication, but there is nothing about SPI in the DAC7612 datasheet.
Indeed, the microcontroller must send 14 bits to the DAC (2 to choose the output of the DAC and 12 data bits). The SPI communication allows to send 8 bits at a time. It is therefore not possible to use it I guess.
So I decided to use bit banging but I don't get any voltage at the output of the DAC7612. However, I can observe with the oscilloscope the signals sent by the microcontroller (CLK, SDI, CS, LOADDACs). Here is the code:
void loadDAC(uint16_t d)
{
uint16_t dac;
uint8_t i;
dac = d | 0x2000; // DAC Port A
LOADDACS_SetHigh();
CS_DAC_SetLow(); // CS_DAC low level
__delay_us(0.03);
for(i = 0; i < 14u; i++)
{
if(dac & 0x2000)
SDO_DAC_SetHigh(); // SDO high level
else
SDO_DAC_SetLow(); // SDO low level
CLK_DAC_SetHigh(); // SCK high level
__delay_us(0.1);
CLK_DAC_SetLow(); // SCK low level
dac <<= 1;
}
__delay_us(0.03);
CS_DAC_SetHigh(); // CS_DAC high level
LOADDACS_SetLow();
__delay_us(0.03);
LOADDACS_SetHigh();
}
Thank you for reading.
Code for SPI Communication but still nothing:
dac_value =0xFFF; // 12 bits resolution
LOADDACS_SetHigh();
SPI_Open(SPI_DEFAULT);
CS_DAC_SetLow();
SSPBUF = (uint8_t)(dac_value >> 6)| 0x80; // 0x80 : select DAC Port A and send 4 MSB
while(!SSPSTATbits.BF);
SSPBUF = (uint8_t)(dac_value << 2 & 0x00FF); // Send 8 LSB
while(!SSPSTATbits.BF);
CS_DAC_SetHigh();
SPI_Close();
LOADDACS_SetLow();
__delay_us(0.03);
LOADDACS_SetHigh();