Go Down

Topic: [SOLVED]Writing Commands to MAX11632 ADCs without SPI (Read 446 times) previous topic - next topic

awesomelyjen

May 29, 2013, 09:53 pm Last Edit: May 30, 2013, 02:48 pm by awesomelyjen Reason: 1
Hey guys,

So I'm trying to interface with a MAX11632 ADC using an Arduino UNO board without using any SPI through the MISO, MOSI, CS, and SCK pins. The data sheet for this specific ADC can be found here: http://pdf1.alldatasheet.com/datasheet-pdf/view/434696/MAXIM/MAX11632.html.

This is the code I've written so far:
Code: [Select]
#include <SPI.h>

//Pin definitions
const int CS0 = 4;
const int CS1 = 5;
const int CS2 = 6;
const int DECODER_EN = 7;
const int MOSIPIN = 11;
const int MISOPIN = 12;
const int SCKPIN = 13;

//packet structure bytes
byte START_BYTE = '*';
byte END_BYTE = '#';
byte DELIMITER = ',';

//enumeration of channels for loops
//enum channels { CH0, CH1, CH2, CH3, CH4, CH5, CH6,
 //CH7, CH8, CH9, CH10, CH11, CH12, CH13, CH14, CH15 };

//array of conversion registries
byte channels[] = {B10000100, B10001100, B10010100,
B10011100, B10100100, B10101100, B10110100, B10111100, B11000100,
B11001100, B11010100, B11011100, B11100100, B11101100, B11110100,
B11111100};

//Other two setup registries
byte setupReg = B01111000;
byte averageReg = B00111100;
byte reg1 = B10000100;
byte reg2 = B10001100;
byte convReg = reg1;

void setup()
{
 pinMode(CS0,OUTPUT);
 pinMode(CS1,OUTPUT);
 pinMode(CS2,OUTPUT);
 pinMode(DECODER_EN,OUTPUT);
 pinMode(MISOPIN,INPUT);
 pinMode(SCKPIN,OUTPUT);
 pinMode(MOSIPIN,OUTPUT);
 
 
 Serial.begin(9600);
 
 //Set up ADC we wish to comm with
 //But don't start comm
 //This circuit has a chip select decoder to determine which of the 5 adcs to look at
 digitalWrite(DECODER_EN,LOW);
 digitalWrite(CS1,HIGH);
 digitalWrite(CS0,HIGH);
 digitalWrite(CS2,HIGH);
 
 //Set clock low to prepare for data write
 digitalWrite(SCKPIN,LOW);
 delay(2500);
}
void loop()
{
 byte result;
//  Serial.println(START_BYTE);
//  for(int i = 0; i < 2; i++){
//    byte convReg;
//    if (i == 0){
//      convReg = reg1;
//    }
//    else{
//      convReg = reg2;
//    }
   //First we give the ADC register settings
   //takes input on rising clock edge
   digitalWrite(DECODER_EN,HIGH);
   digitalWrite(SCKPIN,HIGH);
   analogWrite(MOSIPIN,setupReg);
   analogWrite(MOSIPIN,averageReg);
   analogWrite(MOSIPIN,convReg);
   
   //We then let the ADC run conversion
   digitalWrite(DECODER_EN,LOW);
   delay(10);
   
   //sends data to DOUT on falling clock edge
   digitalWrite(SCKPIN,LOW);
   result = analogRead(MISOPIN);
   //start comm with ADC again
   digitalWrite(DECODER_EN,HIGH);
   //read result from dataout
   
   //once we have data cut off comm
   digitalWrite(DECODER_EN,LOW);
   
   //print out result
   Serial.println(result,DEC);
   //Serial.println(DELIMITER);
   delay(1000);
 //}
 //Serial.println(END_BYTE);
 Serial.println();
}


I'm pretty sure the ADC is not working the way it should, as I'm getting pretty much the exact same numbers no matter whether I'm reading from a channel connected to a Hall-effect sensor or a channel connected to a thermistor.

Any sort of nudge in the right direction would be much appreciated.

Thanks in advance!

johnwasser

Code: [Select]

const int MISOPIN = 12;
    result = analogRead(MISOPIN);


12 is not a valid analog input pin.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

awesomelyjen

Thanks!

I think I ended up resolving the problem, which was more of me not understanding how and when to use SPI.

I did need to use an SPI interface for this code and eventually got it working.

Go Up