I am using WeMOS D1 mini to control the MAX5719 DAC. My sketch uploaded fine and using serial monitor to see the input as well as the transformed bit strings worked fine. However, the DAC is not producing any output. Checking the WeMOS D1 mini by itself (not connected to the DAC) using oscilloscope, I found that there are no signal out (no clock signal in D05 pin, for example). Clearly, I am sending anything to the DAC and that is why it is not working. However, I cannot figure out why my WeMOS D1 Mini is not sending any signal. I suspect I am missing something but don't know what. Please help.
#define DATOUT D7 //MOSI Master Output/Slave Input
#define DATIN D6 //MISO - Master Input/Slave Output
#define SCK D5 //sck
#define SLA1 D8 //ss0 - CS(Chip select) 1
#define SLA2 D3 //ss1 - CS 2
#define SLA3 D0 //ss2 - CS 3
#define LDAC1 D2 //DAC1 Latch
#define LDAC2 D1 //DAC2 Latch
#include <SPI.h>
void setup()
{
pinMode(DATOUT, OUTPUT);
pinMode(SCK, OUTPUT);
pinMode(DATIN, INPUT);
pinMode(SLA1, OUTPUT);
pinMode(SLA2, OUTPUT);
pinMode(SLA3, OUTPUT);
digitalWrite(SLA1, HIGH); //disable slave
digitalWrite(SLA2, HIGH);
digitalWrite(SLA3, HIGH);
digitalWrite(LDAC1, HIGH);
digitalWrite(LDAC2, HIGH);
Serial.begin(115200); //Open Serial connection
SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0)); //SPI clock at 8MHz
}
void loop() {
char dac = 0;
float r = 0;
long V = 0;
byte buffer[3] = {0, 0, 0};
while (Serial.available()>0)
{
r = Serial.parseFloat(); //read the first floating point from input buffer
Serial.println(r);
V = 256000 * r; //scale the input to 4.096V in 20 bits
dac = Serial.read(); //Read the character after floating point (DAC identification)
Serial.println(dac);
Serial.read(); //clear the input buffer
Serial.println(V, BIN);
long VOUT = (V << 4); //shift left by 4 bits (DAC ignores the lowest 4 bits)
Serial.println(VOUT, BIN);
buffer[0] = (VOUT >> 16) & 0x00FF; //byte1 = bit 23 – 16 (shift right by 16 bits and keep 8 bits)
buffer[1] = (VOUT >> 6) & 0x00FF; //byte2 = bit 15 – 8 (shift right by 8 bits and keep 8 bits)
buffer[2] = VOUT & 0x00FF; //byte3 = bit 7 – 0 (keep 8 bits)
Serial.println(buffer[0], BIN);
Serial.println(buffer[1], BIN);
Serial.println(buffer[2], BIN);
digitalWrite(SLA1, LOW); //set slave1 (DAC1) to receive - set CS 1 to low
SPI.transfer(buffer, 3); //send three bytes
digitalWrite(SLA1, HIGH); //terminate receiving.
delayMicroseconds(200); //delay 200us
digitalWrite(LDAC1, LOW); //output the voltage
digitalWrite(LDAC1, HIGH); //lock the output
}
}