I'm trying to control a DAC61401 with an arduino UNO using SPI

30 Views Asked by At

I'm using the DAC61401 to a project where I want to be able to choose four different voltages from 0 to 22 volts, however, I can only get 0v. I was trying to control the DAC trough an arduino UNO using SPI.

The code I am using is the following:

#include <SPI.h>
#include <Arduino.h>

#define CS 10

inline void CSON()
{
  digitalWrite(CS, LOW);
}
inline void CSOFF()
{
  digitalWrite(CS, HIGH);
}

void write_reg(uint8_t reg, uint16_t wdata)
{
  uint8_t lsb = ((uint16_t)wdata >> 0) & 0xFF;
  uint8_t msb = ((uint16_t)wdata >> 8) & 0xFF;
 
  SPI.beginTransaction(SPISettings(16000, MSBFIRST, SPI_MODE0)); 
  CSON();
  delayMicroseconds(10);
  SPI.transfer(reg);
  SPI.transfer(msb);
  SPI.transfer(lsb);
  CSOFF();
  delayMicroseconds(10);
  SPI.endTransaction();
}


void setup() {
  pinMode(CS, OUTPUT); // set the CS pin as an output
  SPI.begin();         // initialize the SPI library
  Serial.begin(9600);
  write_reg(0x03, 0x0004);  //power up the device             ---> SPI_CONFIG
  write_reg(0x04, 0x0000);  //power up the internal reference ---> GEN_CONFIG
  write_reg(0x09, 0xFFFE);  //power up the DAC output         ---> DAC_PWDWN
  write_reg(0x0A, 0x000A);  //configure the DAC range (24v)   ---> DACRANGE
}



void loop() {
  write_reg(0x10, 0xEAB0);  //configure the VOUT to 22V        ---> DAC

  delay(1000);
  Serial.println("Loop done");
}

I've checked the DAC's input voltages and they all seem to be correct. Is there something wrong with the code?

0

There are 0 best solutions below