I was wondering if anyone could give me some help porting this to the maple?
#include <SPI.h>
#define MISOPIN 12
#define SCLKPIN 13
byte byte1; byte byte2; byte byte3;
// declare 3 bytes = 24 bits
void setup()
{
Serial.begin(9600);
pinMode(SCLKPIN, OUTPUT); pinMode(MISOPIN, INPUT);
// corresponding to SCK pin and DRDY/DOUT pin on ADC
reset_adc();
// put ADC on reset at the outset
SPI.begin();
// initialize SPI (with default settings, including...
// CPOL = 0: so that SCLK is normally LOW
// CPHA = 0: data sampled on rising edge (LOW to HIGH)
// perhaps try changing CPHA ??
digitalWrite(SCLKPIN, LOW);
// release ADC from reset; now we're at a known point
// in the timing diagram, and just have to wait for
// the beginning of a conversion cycle
}
void loop()
{
if (digitalRead(MISOPIN) == HIGH) read_adc();
// "sort of" an interrupt to go to read_adc routine;
// can use hardware interrupt in future but now just poll
}
void reset_adc()
// to reset ADC, we need SCLK HIGH for min of 4 CONVCYCLES
// so here, hold SCLK HIGH for 5 CONVCYCLEs = 1440 usec
{
digitalWrite(SCLKPIN, HIGH);
delayMicroseconds(1440);
}
void read_adc()
{
drdy_wait();
// go to drdy_wait routine, where we wait for
// DRDY phase to pass, and thus for DOUT phase to begin
byte1 = SPI.transfer(0x00);
byte2 = SPI.transfer(0x00);
byte3 = SPI.transfer(0x00);
// read in adc data (sending out don't care bytes)
// and store read data into three bytes */
Serial.println(byte1, DEC);
Serial.println(byte2, DEC);
Serial.println(byte3, DEC);
Serial.println();
// print out data;
// will these instructions eat into time significantly?
// possible improvement: store all data from multiple cycles
// into array, and print out only later at end.
}
void drdy_wait()
// wait for DRDY to pass and to reach start-point of DOUT
{
delayMicroseconds(30);
// to be safe, 30 usec, instead of 27 usec, which is
// the expected period of DRDY phase
}
thanks