Hi all
So I'm copying code from a PIC project - so I have the data how to talk to the MAX.
Nothing working
As I have this now soldered my brand new PCB fresh from China - I can't change anything, but I have confirmed the pins are connected correctly
With two exceptions:
SCK is on pin 14, not 13 - was hurrying to get the PCB design out, saw that the LED is connected to pin 13 - so I picked the alternative pin
CS was put on a pin 10 - that should be ok
then I have a input pin that should go low when conversion is done
here is the code - please let me know if you see something obvious - else I need to get a logic analyzer and see what is going on
And note this is the first time I write directly to a SPI device, just been using libraries for LCD etc.
and yes, " if(digitalRead(EOC) == 0)" never gets true - If I just read it I get 0.
Running the Teensy at 96Mhz -
from the datasheet: " 10MHz 3-Wire SPI-/QSPI-/MICROWIRE-Compatible interface"
- Benni
So I'm copying code from a PIC project - so I have the data how to talk to the MAX.
Nothing working
As I have this now soldered my brand new PCB fresh from China - I can't change anything, but I have confirmed the pins are connected correctly
With two exceptions:
SCK is on pin 14, not 13 - was hurrying to get the PCB design out, saw that the LED is connected to pin 13 - so I picked the alternative pin
CS was put on a pin 10 - that should be ok
then I have a input pin that should go low when conversion is done
here is the code - please let me know if you see something obvious - else I need to get a logic analyzer and see what is going on
And note this is the first time I write directly to a SPI device, just been using libraries for LCD etc.
and yes, " if(digitalRead(EOC) == 0)" never gets true - If I just read it I get 0.
Running the Teensy at 96Mhz -
from the datasheet: " 10MHz 3-Wire SPI-/QSPI-/MICROWIRE-Compatible interface"
Code:
//
// MAX MAX11626–MAX11629/
// MAX11632/MAX11633
// Test code
// - not working
#include <SPI.h>
#define SS1 10
#define EOC 8
#define MAXCHANNEL_ADCA 7
void setup() {
Serial.begin(9600);
pinMode(SS1,OUTPUT);
pinMode(EOC,INPUT);
digitalWrite(SS1, HIGH);
delayMicroseconds(50);
SPI.setSCK(14);
SPI.begin();
delay(100);
SPI.beginTransaction (SPISettings (4000000, MSBFIRST, SPI_MODE0));
digitalWrite(SS1, LOW);
SPI.transfer(0b01101000); // setup register
delayMicroseconds(1);
SPI.transfer(0b00110100); // Averaging register, 8 measurments,
delayMicroseconds(1);
SPI.transfer(0b00011000); // reset FIFO
SPI.transfer(0b10000000 | ((MAXCHANNEL_ADCA-1)<<3)); // Start conversion
digitalWrite(SS1, HIGH);
SPI.endTransaction();
}
void readADC()
{
uint8_t adc_temp;
int i;
SPI.beginTransaction (SPISettings (4000000, MSBFIRST, SPI_MODE0));
digitalWrite(SS1, LOW);
if(digitalRead(EOC) == 0)
{
Serial.println("ADC RDY");
for(i=0; i<MAXCHANNEL_ADCA; i++)
{
adc_temp = SPI.transfer(0);
adc_temp <<= 8;
adc_temp += SPI.transfer(0);
}
Serial.print(adc_temp);
Serial.print(" ");
}
Serial.println();
digitalWrite(SS1, HIGH);
SPI.endTransaction();
}
void loop() {
readADC();
Serial.print(".");
delay(1000);
}
- Benni