I'm trying to use an AD5678 DAC on my custom SAMD51 board, using the SPI bus on sercom5.
DAC Datasheet:
(https://www.analog.com/media/en/technical-documentation/data-sheets/AD5678.pdf)
The DAC has 8 channels, A B G and H are 16bit channels, while C D E and F are 12bit channels.
The example sketch that I'm using works perfectly fine for channels B, D, F and H (checked with an oscilloscope on their pins), but channels A C E and G are not working (I only got a steady voltage on those pins).
This is brief summary of the situation:
CHANNEL ADDRESS BITS WORKS?
A 0 16 no
B 1 16 yes
C 2 12 no
D 3 12 yes
E 4 12 no
F 5 12 yes
G 6 16 no
H 7 16 yes
coincidentally (or not?), the channels that are not working are all on the same side of the IC package. Of course I triple-checked the PCB, and found no shorts between the pins and other signals/supplies. And I'm probing with the oscilloscope directly on the DAC pins.
I'm wondering if there is something wrong with the code, that makes the even numbered channels not work.
In the meanwhile I ordered another IC in case I got a defective one.
this is the code:
#include <SPI.h>
#define PIN_SPI_DAC_CS 27
SPIClass ad5678spi(&sercom5, -1, 30, 29, SPI_PAD_0_SCK_1, SERCOM_RX_PAD_3);
void setup() {
ad5678spi.begin();
ad5678spi.beginTransaction(SPISettings(20000000, MSBFIRST, SPI_MODE1));
digitalWrite(PIN_SPI_DAC_CS, LOW);
ad5678spi.transfer(0b0111); // command: Reset
ad5678spi.transfer(0);
ad5678spi.transfer(0);
ad5678spi.transfer(0);
digitalWrite(PIN_SPI_DAC_CS, HIGH);
for(int i = 0; i < 8; i++) {
ad5678write(i, 0);
}
}
void loop() {
for(int i=0; i<65535; i++) {
ad5678write(0, i);
delayMicroseconds(50);
}
}
void ad5678write(uint8_t channel, uint16_t value) {
if(channel >= 2 && channel <= 5) {
value <<= 4;
}
digitalWrite(PIN_SPI_DAC_CS, LOW);
ad5678spi.transfer(0b00000011); // command: Write to and update DAC Channel n
ad5678spi.transfer((channel << 4) | (value >> 12));
ad5678spi.transfer(value >> 4);
ad5678spi.transfer(value << 4);
digitalWrite(PIN_SPI_DAC_CS, HIGH);
}