Hello everyone,
I am working with Arduino Uno and DAC80504EVM, and I would like to connect them via SPI.
Since I am at the beginning stage of understanding SPI, I would like to establish a simple communication, where I send a voltage level from Arduino to SPI, and then from the output 0 of the DAC (DAC0), I get the voltage that I read on the analog pin (A0) of the Arduino board.
So far, I have tried it, but unsuccessfully. Here is code that I have been trying out, and the image of connections between the devices I am sending you attached:
// inslude the SPI library:
#include <SPI.h>
const int slaveSelectPin = 10;
int sensorPin = A0;
int sensorValue = 0;
void setup() {
Serial.begin(9600);
// set the slaveSelectPin as an output:
pinMode(slaveSelectPin, OUTPUT);
// initialize SPI:
SPI.beginTransaction(SPISettings(50000000, MSBFIRST, SPI_MODE0));
}
void loop() {
// take the SS pin low to select the chip:
digitalWrite(slaveSelectPin, LOW);
// send in the address and value via SPI:
SPI.transfer(0x08); // because the address of DAC0 register is 1000
SPI.transfer(0x00); // upper byte of data
SPI.transfer(0x08); // lower part of data (randomly chosen)
sensorValue = analogRead(sensorPin); // read data from A0
Serial.println(sensorValue*5.0/1023.0);
// take the SS pin high to de-select the chip:
digitalWrite(slaveSelectPin, HIGH);
}
When I run this code, and try to see what will I get when I change to what I connect the A0 pin (for example, I try to connect it to SCLK) and I don't get the pulsing signal on the serial plotter, instead I get some kind of random signal. I am sending you attached also the output of serial plotter when I connect A0 to SCLK, SDO, SDI, CS and Vref.
I would very much appreciate it if somebody could provide me with information if I am doing this correctly, or how should I change my code?
Thanks everyone in advance. I would appreciate any comment or suggestion.
Kind regards,
Dejana






