Hey there, I am trying to send 19-bit word data from Arduino Uno to the AD5535 DAC. Sorry for the repeated-ish post since it is essentially a follow-up question from this topic: transfer 19 bit word, SPI, AD5535 - #33 by dougp.
However, I am trying to understand what is wrong with the SPI transferring as I am not receiving any voltage value even with hard-coded word data.
#include <SPI.h>
const int columnDACSelectPin = 6;
const int rowDACSelectPin = 7;
const int resetPin = 0;
boolean dataReady = false;
boolean recvInProgress = false;
void channel_write() {
/*
* A - Address Bit
* d - Data Bit
* x - Don't Care Bit
*
byte 3 | xxxx xxxx
byte 2 | AAAA Addd
byte 1 | dddd dddd
byte 0 | dddx xxxx
*/
uint8_t bytesToSend[3];
uint8_t addressValue = 0;
uint16_t dataValue = 0;
uint16_t dataValueBuffer = 0;
bool colWrite = false;
bytesToSend[0] = B00001111;
bytesToSend[1] = B10001011;
bytesToSend[2] = B00100000;
addressValue = (bytesToSend[0] >> 3) & 0x1F; // Mask (0001 1111)
dataValue = (bytesToSend[0]) & 0x7; // Mask (0000 0111)
dataValue = (dataValue << 11) & 0x3800; // Mask (0011 1000 0000 0000)
dataValueBuffer = (bytesToSend[1]) & 0xFF; // Mask (1111 1111)
dataValueBuffer = (dataValueBuffer << 3) & 0x7F8; // Mask (0000 0111 1111 1000)
dataValue |= dataValueBuffer;
dataValueBuffer = 0;
dataValueBuffer = (bytesToSend[2] >> 5) & 0x7; // Mask (0000 0111)
dataValue |= dataValueBuffer & 0x7;
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE1));
Serial.print("Row Address (DEC): "); Serial.print(addressValue, DEC); Serial.print(" -> Converted Voltage (DEC): "); Serial.print(dataValue, BIN);
Serial.print("\t(from Decimal: "); Serial.print(dataValue, DEC); Serial.println(")");
for (int i = 0; i < 3; i++)
{
if(i==0)
{
Serial.print("Row Btyes to Send: "); Serial.print("("); Serial.print(i); Serial.print(") "); Serial.print(bytesToSend[i], BIN); Serial.print("|");
}
else
{
Serial.print("("); Serial.print(i); Serial.print(") "); Serial.print(bytesToSend[i], BIN); Serial.print("|"); // Leading Zeros are not printed
} //Delay 0.1s, Minimal of 0.2ms Delay between Sucessive Write
}
digitalWrite(rowDACSelectPin, LOW); // Selects Row Chip
delay(100);
SPI.transfer(bytesToSend[0]);
SPI.transfer(bytesToSend[1]);
SPI.transfer(bytesToSend[2]);
delay(100);
digitalWrite(rowDACSelectPin, HIGH); // De-Selects Row Chip
SPI.endTransaction();
Serial.println();
dataReady = false;
recvInProgress = false;
}
void setup() {
Serial.begin(115200);
pinMode(rowDACSelectPin, OUTPUT);
SPI.begin();
}
void loop() {
long currentColChannelValue = 20;
int channelLoop = 0;
uint16_t v_out_col_bin = currentColChannelValue*pow(2,14)/(50*1);
const char startMarker = '<';
while(Serial.available() > 0 && (dataReady == false))
{
char rc = Serial.read();
if (rc == startMarker) {
recvInProgress = true;
} else if (recvInProgress) {
dataReady = true;
}
}
if (recvInProgress)
{
channel_write();
}
}
The hardware side is fine (as checked by my colleague) but I just can't figure what's wrong with the SPI transfer


