Part Number: DAC8760
Tool/software:
Hello everyone,
I've been trying to Interface DAC8760 to an ESP 32 for testing out the DAC in order to implement in our circuit.
I used the following connections-
MOSI(GPIO23) - DIN
MISO(GPIO19) - SD0
SCLK(GPIO18) - SCLK
CS (GPIO05) - LATCH
I supplied +24v to AVDD pin and -24v to ground, both ground pins of esp and dac were connected.
I tried using the following code
#include <SPI.h>
#define MOSI_PIN 23 // GPIO23 for MOSI
#define SCLK_PIN 18 // GPIO18 for SCLK
#define CS_PIN 5 // GPIO5 for CS (Chip Select)
#define MISO_PIN 19 // GPIO19 for MISO
// DAC8760 register addresses
#define DAC_WRITE_CR 0x02 // Control Register address
#define DAC_READ_STATUS 0x05 // Status Register address
// Initialize SPI and DAC
void setup() {
Serial.begin(9600);
// Set up SPI pins
SPI.begin(SCLK_PIN, MISO_PIN, MOSI_PIN, CS_PIN);
// Initialize DAC8760
pinMode(CS_PIN, OUTPUT);
digitalWrite(CS_PIN, HIGH);
// Send initialization commands to DAC8760
dac8760Init();
}
void loop() {
// Read status register to check initialization status
uint8_t status = readDACStatus();
Serial.print("DAC Status: ");
Serial.println(status, HEX);
delay(1000); // Check status every 1 second
}
// Function to initialize the DAC8760
void dac8760Init() {
// Write to Control Register (Configure DAC for current output 4-20 mA)
// Data to write: Bit 15 (DAC Enable) = 1, Bit 13-11 (Output Range) = 100 for 4-20 mA
digitalWrite(CS_PIN, LOW); // Select DAC
SPI.transfer(DAC_WRITE_CR); // Send command to write to Control Register
SPI.transfer(0xA0); // High byte: 0xA0 (DAC Enable, 4-20mA output range)
SPI.transfer(0x00); // Low byte: 0x00 (No additional configurations in low byte)
digitalWrite(CS_PIN, HIGH); // Deselect DAC
// Optionally, you could write again for different configurations (e.g., for voltage output)
// This example configures for 4-20mA current output
}
// Function to read DAC status register
uint8_t readDACStatus() {
uint8_t status;
digitalWrite(CS_PIN, LOW); // Select DAC
SPI.transfer(DAC_READ_STATUS | 0x80); // Send command to read status register (with MSB = 1 for read)
status = SPI.transfer(0x00); // Receive status byte
digitalWrite(CS_PIN, HIGH); // Deselect DAC
return status;
}
i was not able to receive both 4-20 mA output and voltage output. i also checked the internal reference voltage which turned out to be a stable 5v. Is there anything i am missing?
Thank you in advance.
Regards,
Abisheik