Go Down

Topic: Problem reading from MAX11060 16bit ADC (Read 167 times) previous topic - next topic

shahadr

Apr 30, 2018, 03:31 pm Last Edit: Apr 30, 2018, 03:33 pm by shahadr
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:


Code: [Select]
#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);
}



pylon

I guess you're doing this with an Arduino UNO (as didn't specified another model). You should set the SS pin (pin 10 on the UNO) as an output, otherwise the SPI hardware won't work correctly.

How did you wire the chip to the Arduino? The UNO runs on 5V but none of the MAX11060 pins allows more than 4V. Do you use a level converter?

shahadr

I am using the arduino mega. Does the same apply to the mega as well?
I have connected the ADC directly to the arduino (no level converters), do you think I will have to use one? I assumed the arduino could handle 3v3 logic as it has outputs with 3.3V.

pylon

On the Mega the SS pin that needs to be in mode OUTPUT is pin 53.

Quote
do you think I will have to use one?
According to the datasheet: yes. You might have already damaged the chip.

Quote
I assumed the arduino could handle 3v3 logic as it has outputs with 3.3V.
On the SPI bus only MISO is an input (which usually tolerates 3.3V), all other pins are outputs and provide a 5V level.

shahadr

Thank you for your reply. I feared I might have burnt the chip. Fortunately it works when connected back to the myRio.
I have ordered the arduino pro mini that should work with 3.3V logic.

Go Up