Hi,
I am using the SPI to output 16 bits to a DAC. As I try to squeeze the max speed out of the Due I noticed there is a gap between the 8 bit bursts coming out of the SPI. The delay between bursts is about 1.2 uS. Is there a way to reduce this delay?
Here is the code:
#include <SPI.h>
// Defining DAC channel orders
#define DAC_CS 52
void setup() {
SPI.begin(DAC_CS);
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(DAC_CS, 0);
SPI.setClockDivider(DAC_CS, 21); // 4MHz
}
void loop() {
// put your main code here, to run repeatedly:
WriteDacChannel(0,0x0555);
delay(1);
}
// write value to the DAC. chan = 1 tp 8, val = 0 to 4095
void WriteDacChannel(uint8_t chan, uint16_t val)
{
uint16_t thisVal;
thisVal |= val & 0xFFF; // trim val to 12 bits and OR in
SPI.transfer(DAC_CS, thisVal >> 8, SPI_CONTINUE);
SPI.transfer(DAC_CS, thisVal, SPI_LAST);
}