Hi everyone, here is the problem. I am using a PMODDA4 DAC on an Arduino MEGA2560, but the simple example code I found doesn't give anything on the DAC's output pins. The thing is, I tried it on an Uno for another project, and it works perfectly. I think I am missing something very simple here, but I can't put my finger on it...
Here are the datasheets of the DAC :
PMODDA4
AD5628
Here is how the code is supposed to work : the DAC outputs different voltages on each of the 8 outputs. But when I check with a multimeter, nothing is outputted. The code I am using was written for an Uno, but apart from the CS pin, I didn't think there was anything to change here to make it work on MEGA. However I am less sure of it now.
Here is the code :
/************************************************************************
Test of the Pmod
*************************************************************************
Description: Pmod_DA4
The output voltage A to E ranges from 2.5V to 0.5V in steps of 0.5 V
Material
1. Arduino Mega (code written for Uno)
2. Pmod DA4
************************************************************************/
#define CS 53 // affectation of CS pin
#include <SPI.h> // include library
void setup()
{
SPI.begin(); // initialization of SPI port
SPI.setDataMode(SPI_MODE0); // configuration of SPI communication in mode 0
SPI.setClockDivider(SPI_CLOCK_DIV16); // configuration of clock at 1 MHz
pinMode(CS, OUTPUT);
digitalWrite(CS, LOW); // activation of CS line
SPI.transfer(0b00000111); // Power-on reset
delay(1);
SPI.transfer(0);
delay(1);
SPI.transfer(0);
delay(1);
SPI.transfer(0);
delay(1);
digitalWrite(CS, HIGH); // desactivation CS line
digitalWrite(CS, LOW); // activation of CS line
SPI.transfer(0b00001000); // configuration of converter N/A (configuration of REF register)
delay(1);
SPI.transfer(0);
delay(1);
SPI.transfer(0);
delay(1);
SPI.transfer(0b00000001); // configuration of converter N/A (internal reference voltage activeVREF=1,25V)
delay(1);
digitalWrite(CS, HIGH); // desactivation CS line
digitalWrite(CS, LOW); // activation of CS line
SPI.transfer(0b00000011); // configuration of converter N/A (write output of converter)
delay(1);
SPI.transfer(0b11110000); // configuration of converter N/A (8 voutput active)
delay(1);
SPI.transfer(0);
delay(1);
SPI.transfer(0);
delay(1);
digitalWrite(CS, HIGH); // desactivation of CS line
}
void loop()
{
// la sortie A du convertisseur est à 2,5V
digitalWrite(CS, LOW); // activation of CS line
SPI.transfer(0b00000011);
delay(1);
SPI.transfer(0b00001111);
delay(1);
SPI.transfer(0b11111111);
delay(1);
SPI.transfer(0);
delay(1);
digitalWrite(CS, HIGH); // desactivation of CS line
// la sortie B du convertisseur est à 2V
digitalWrite(CS, LOW); // activation of CS line
SPI.transfer(0b00000011);
delay(1);
SPI.transfer(0b00011100);
delay(1);
SPI.transfer(0b11001101);
delay(1);
SPI.transfer(0);
delay(1);
digitalWrite(CS, HIGH); // desactivation of CS line
// la sortie C du convertisseur est à 1,5V
digitalWrite(CS, LOW); // activation of CS line
SPI.transfer(0b00000011);
delay(1);
SPI.transfer(0b00101001);
delay(1);
SPI.transfer(0b10011010);
delay(1);
SPI.transfer(0);
delay(1);
digitalWrite(CS, HIGH); // desactivation of CS line
// la sortie D du convertisseur est à 1V
digitalWrite(CS, LOW); // activation of CS line
SPI.transfer(0b00000011);
delay(1);
SPI.transfer(0b00110110);
delay(1);
SPI.transfer(0b01100110);
delay(1);
SPI.transfer(0);
delay(1);
// la sortie E du convertisseur est à 0,5V
digitalWrite(CS, LOW); // activation of CS line
SPI.transfer(0b00000011);
delay(1);
SPI.transfer(0b01000011);
delay(1);
SPI.transfer(0b00110011);
delay(1);
SPI.transfer(0);
delay(1);
digitalWrite(CS, HIGH); // desactivation of CS line
}
On the wiring part, here is a picture of the connections :
The perspective can be misleading, so here is a summary of the connections :
Vcc - 5v (red)
GND - GND (white)
SCLK - 52 (violet)
DIN (MOSI) - 51 (blue)
SYNC (CS) - 53 (grey)
Any help would be greatly appreciated. Thanks in advance !
