工具与软件:
大家好!
我一直在尝试将 DAC8760连接到 ESP 32、以便测试 DAC 以便在我们的电路中实施。
我采用了以下连接-
MOSI (GPIO23)- DIN
MISO (GPIO19)- SD0
SCLK (GPIO18)- SCLK
CS (GPIO05)- LATCH
我为 AVDD 引脚提供了+24V 电压、并为接地提供了-24V 电压、ESP 和 DAC 的两个接地引脚均已连接。
我尝试了使用以下代码
#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; }
我无法 同时接收4 -20 mA 输出和电压输出。 我还检查了内部基准电压、结果证明该电压是稳定的5V。 有什么我丢失的东西吗?
提前感谢您。
此致、
Abisheik