I have gotten the shield to work fine with an Arduino Uno, using the code supplied by the manufacturer of the shield, but I need more space for my program, The manufacturer only supports the Uno and bitbangs the SPI interface, so I decided to port it to the SAMD51 platform and use the SPI library on the Metro M4.
Using SPI, I am able to read data via the ADC with no problem, but writing to the DAC produces no output on my oscilloscope. Anyone see what I could be doing wrong?
Setup code:
Code: Select all
union SpiData {
uint16_t value; /**< value */
struct {
uint8_t loByte; /**< low byte */
uint8_t hiByte; /**< high byte */
};
};
void setup(){
//ACD_CS = 7 per manufacturer
//DAC_CS = 8 per manufacturer
pinMode(ADC_CS, OUTPUT);
digitalWrite(ADC_CS, HIGH);
pinMode(DAC_CS, OUTPUT);
digitalWrite(DAC_CS, HIGH);
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
SPI.begin();
}
Code: Select all
int read(){
SpiData adc;
digitalWrite(ADC_CS, LOW);
adc.hiByte = SPI.transfer(0x00) & 0x1F;
adc.loByte = SPI.transfer(0x00);
digitalWrite(ADC_CS, HIGH);
return (adc.value >> 1);
}
Code: Select all
void write(int value) {
// DAC_CONFIG = 0x30
byte firstByte = DAC_CONFIG | ((value >> 8) & 0xF);
byte secondByte = value;
digitalWrite(DAC_CS, LOW);
SPI.transfer(firstByte);
SPI.transfer(secondByte);
digitalWrite(DAC_CS, HIGH);
}