#include <SPI.h>
void setup(){
// initialize the bus for a device on pin 52
SPI.begin(52);
SPI.setClockDivider(52, 21);
}
void loop(){
SPI.transfer(52, 0xFF, SPI_CONTINUE); //transfer 0xFF to the device on pin 52, keep the chip selected
digitalWrite(3, HIGH);
delay(1000);
SPI.transfer(52, 0x00, SPI_CONTINUE); //transfer 0x00 to the device on pin 52, keep the chip selected
digitalWrite(3, LOW);
delay(1000);
}
Anyway, if voltage doesn't move on DAC1 pin, you might have burn your DAC. Always connect at least a 1.5 KOhms resistor in serie with DAC0 or DAC1 since these pins can't output much current without burning.
FYI, a multimiter is somehow an infinite load... There is an issue whenever you connect a DAC to a very light load, hence the suggested 1.5 K Ohms resistor since a DAC can output a maximum of
3 mA.
No, the internal DAC will not produce rail to rail voltage outputs. It only produces from 1/6 to 5/6 of the reference voltage, that is, 0.55 V and 2.75V with Vref = 3.3 V.
See this project for a way of correcting this by using an operational amplifier. Correcting the output range
#include <SPI.h>
void setup(){
// initialize the bus for a device on pin 52
SPI.begin(52);
SPI.setClockDivider(52, 21);
}
void loop(){
SPI.transfer(52, 0xFF, SPI_CONTINUE); //, SPI_CONTINUE); //transfer 0xFF to the device on pin 52, keep the chip selected
//digitalWrite(3, HIGH);
//delay(1);
SPI.transfer(52, 0x00, SPI_LAST); //, SPI_CONTINUE); //transfer 0x00 to the device on pin 52, keep the chip selected
//digitalWrite(3, LOW);
//delay(1);
}
At least I ve got output from the due now
due_pin52
due_sck
due_mosi
OUT
doesn't look like there is actual SPI data getting transmitted
Also look at the data sheet for the MCP49x1, you wil see you need to set some status bits in the most significant nibble of the higher byte, not just put zero in it.
No.
You only need to send 16 bits, that is two bytes, not 3.
Why do you still use a number in the brackets in the SPI begin when the documentation says it takes no parameters?
Why have you not set your chip select pin to be an output?
You only need to send 16 bits, that is two bytes, not 3.
Where does it send 3 bytes? I think it sends 4x 1 byte including these don't care bits
Why do you still use a number in the brackets in the SPI begin when the documentation says it takes no parameters?
Why have you not set your chip select pin to be an output?
Yes and that PDF was full of the author saying “I don’t know ….” To me this says that he doesn’t know so why take his word for anything that contradicts the official documentation?
Yes it matters, without releasing the chip select the chip will not work correctly.
What bits are these? I can’t see any reference to don’t care. At the moment this doesn’t matter as you are not sending any data on those pins anyway, but once you get that bit going then it will matter to the A/D chip.
In your only diagram you didn’t indicate what actual PIN numbers you used for data and clock.