我尝试使用 Arduino SPI 通信来控制 DAC81416EVM、但当我尝试发送多个数据时、它不会改变输出、始终输出为5V。
连接:
Arduino SCK -> J8.8
Arduino MISO -> J8.3
Arduino MOSI -> J8.4
Arduino SS -> J8.2
VCC ->电源相差15V
VDD/VAA -> 5V 电源
VIO -> Arduino 为5V
VSS -> GND
J10 -> 2-3
Arduino 代码:
void setup(){
Serial.begin(115200);
SPI.beginTransaction(SPISettings(100000、MSBFIRST、SPI_MODE1);
SPI.begin();
延迟(100);
//设置 DAC[15:12]范围0-5V//
digitalWrite (SS、low);
DAC_WRITE (R_DACRANGE0);
SPI.transfer (0x00);
SPI.transfer (0x00);
digitalWrite (SS、HIGH);
延迟(100);
//设置 DAC[11:8]范围0-5V//
digitalWrite (SS、low);
DAC_WRITE (R_DACRANGE1);
SPI.transfer (0x00);
SPI.transfer (0x00);
digitalWrite (SS、HIGH);
延迟(100);
//设置 DAC[7:4]范围0-5V//
digitalWrite (SS、low);
DAC_WRITE (R_DACRANGE2);
SPI.transfer (0x00);
SPI.transfer (0x00);
digitalWrite (SS、HIGH);
延迟(100);
//设置 DAC[3:0]范围0-5V//
digitalWrite (SS、low);
DAC_WRITE (R_DACRANGE3);
SPI.transfer (0x00);
SPI.transfer (0x00);
digitalWrite (SS、HIGH);
延迟(100);
//为 SPI 读取启用 SDO //
digitalWrite (SS、low);
DAC_WRITE(R_SPIC856);
SPI.transfer (0x0A);
spi.transfer (0x84);
digitalWrite (SS、HIGH);
延迟(100);
//为所有通道加电//
digitalWrite (SS、low);
DAC_WRITE (R_DACPWDWN);
SPI.transfer (0x00);
SPI.transfer (0x00);
digitalWrite (SS、HIGH);
延迟(100);
//启用广播//
digitalWrite (SS、low);
DAC_WRITE (R_BRDCONFIG);
spi.transfer (0xFF);
spi.transfer (0xFF);
digitalWrite (SS、HIGH);
延迟(100);
//将所有通道设置为异步模式//
digitalWrite (SS、low);
DAC_WRITE (R_SYNCCONFIG);
SPI.transfer (0x00);
SPI.transfer (0x00);
digitalWrite (SS、HIGH);
延迟(100);
}
void loop(){
while (1)
{
//将代码写入 R_Brdcast
digitalWrite (SS、low);
DAC_WRITE (R_Brdcast);
SPI.TRANSMIT(255);
SPI.TRANSMIT(255);
digitalWrite (SS、HIGH);
延迟(500);
//将代码写入 R_Brdcast
digitalWrite (SS、low);
DAC_WRITE (R_Brdcast);
spi.transfer (0);
spi.transfer (0);
digitalWrite (SS、HIGH);
延迟(500);
}
延迟(300);
}
void DAC_WRITE (int DAC_reg)
{
int DAC_regW = DAC_reg | 0x00;
spi.transfer (DAC_regW);
}