Hi guys,
I have been visiting and reading off this forum for quite some time now. You guys have been very helpful since the time I started my first arduino project. However, this is my first post so please bear with me as I try to explain my situation as clear as possible.
So I am trying to read from the MAX11060 16-bit ADC. Its 4 channel simultaneous sampling ADC that works through SPI. Configuring and reading the ADC is pretty straightforward and easy as I have already done this using myrio and labview. I am trying to do the same with the arduino just to compare results.
I am able to write to and read from all the registers except from the data register. The data register on the ADC is 12 bytes long where each channel takes 3 bytes. Of these 3 bytes the first two bytes are the data and the last byte is the channel number (0, 1, 2 or 3). I am currently trying to read only 2 channels (6 bytes). When I put together the read data I get 32767 for both channels. However, the third byte (channel number) is correct.
I am very confused. It is the same code structure as in labview and I am able to write to and read from the configuration and datarate registers without a problem.
Appreciate any help with this.
Link to the datasheet: https://datasheets.maximintegrated.com/en/ds/MAX11040K-MAX11060.pdf
Here is my code:
#include <SPI.h>
#include <math.h>
#define cs 6
#define drdy 7
#define spispeed 400000
void setup()
{
Serial.begin(115200);
pinMode (cs, OUTPUT);
pinMode (drdy, INPUT);
digitalWrite(cs, HIGH);
SPI.begin();
SPI.beginTransaction(SPISettings(spispeed, MSBFIRST, SPI_MODE2));
digitalWrite(cs, LOW); //write to the configuration register
SPI.transfer(0b01100000);
SPI.transfer(0b00000000);
digitalWrite(cs, HIGH);
digitalWrite(cs, LOW); //write to the datarate register
SPI.transfer(0b01010000);
SPI.transfer(0b00000000);
SPI.transfer(0b00000000);// Set datarate to 16ksps
digitalWrite(cs, HIGH);
SPI.endTransaction();
delay(100);
}
void loop()
{
long int X = 0;
long int Xadd = 0;
long int Y = 0;
long int Yadd = 0;
long int conf = 0;
long int rate = 0;
byte data[12];
SPI.beginTransaction(SPISettings(spispeed, MSBFIRST, SPI_MODE2));
while (digitalRead (drdy)){} //wait for the dataready signal to go LOW
digitalWrite(cs, LOW);
SPI.transfer(0b11110000); //read command
for(int x = 0; x<=5; x++) //read and store data in an array
{
data[x] = SPI.transfer(0);
Serial.println(data[x]);
}
X = data[0]; //put together raw data, channel 0
X <<= 8;
X |= data[1];
Xadd = data[2]; //channel number
Y = data[3]; //put together raw data, channel 1
Y <<= 8;
Y |= data[4];
Yadd = data[5]; //channel number
digitalWrite(cs, LOW); //read from the configuration register
SPI.transfer(0b11100000);
conf = SPI.transfer(0);
digitalWrite(cs, HIGH);
digitalWrite(cs, LOW); //read from the datarate register
SPI.transfer(0b11010000);
rate |= SPI.transfer(0);
rate <<= 8;
rate |= SPI.transfer(0);
digitalWrite(cs, HIGH);
Serial.print("X = ");
Serial.println(X);
Serial.print("Xadd = ");
Serial.println(Xadd);
Serial.print("Y = ");
Serial.println(Y);
Serial.print("Yadd = ");
Serial.println(Yadd);
Serial.println(" ");
Serial.println(conf);
Serial.println(rate);
SPI.endTransaction();
delay(100);
}