Problem communicating between Uno and MX7705 using SPI

Hi Everyone,

I’m trying to establish communication between my Uno and MX7705 (16 bit A-D Converter) using SPI. The code I’ve written is very similar to the SPI example that comes built with the Arduino Library.

I think I am able to get the IC to setup but when I try to read the AD converted value, all I get is 1s. Basically my output remains stuck at 65535, sometimes I get 32768. The problem, I think is in the ReadReg() function (below is the code).

I’ve also attached MX7705 datasheet for reference, its not the easiest chip to work with. I’ve been at this for more than a week am out of ideas now. So any help on this is much appreciated. (Please ignore the LCD stuff, its only for viewing the data).

#include <SPI.h>
#include <LiquidCrystal.h>

const int DRDY = 8;          //Data Ready Pin
const int CS = 7;            //Chip Select Pin

LiquidCrystal LCD(10,9,6,5,4,3);

const byte CommReg = 0x00;
const byte SetupReg = 0x10;
const byte ClockReg = 0x20;
const byte DataReg = 0x30;

int i = 0;

void setup()
{
  LCD.begin(8,2);
  
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV32);
  
  pinMode(DRDY, INPUT);
  pinMode(CS, OUTPUT);
  
  WriteReg(ClockReg, 0x0C);    //Clock Parameters
  WriteReg(SetupReg, 0x40);    //Setup Paramteres
  delay(10);                   //Give time to 7705 for setup
}

void loop()
{
  if(digitalRead(DRDY) == false)
  {
    unsigned int x = ReadReg();
    
    LCD.clear();
    LCD.setCursor(0,0);
    LCD.print(i++);
    LCD.setCursor(0,1);
    LCD.print(x);
    delay(50);
  }
}

void WriteReg(byte Reg, byte Val)
{
  digitalWrite(CS, LOW);
  SPI.transfer(Reg);
  SPI.transfer(Val);
  digitalWrite(CS, HIGH);
}

unsigned int ReadReg()
{
  unsigned int result = 0;
  byte OneByte, TwoByte;
  
  digitalWrite(CS, LOW);
  SPI.transfer(0x38);                   //Read from Data Register
  OneByte = SPI.transfer(0x00);         //First Byte of Data Register
  TwoByte = SPI.transfer(0x00);         //Second Byte of Data Register
  result = (OneByte << 8) | TwoByte;    //Combine the Two Bytes
  digitalWrite(CS, HIGH);
  
  return(result);
}

MX7705.pdf (664 KB)