Hi all,
I'm using two separate MCP3201 ADC's (http://search.digikey.com/us/en/products/MCP3201-BI%2FP/MCP3201-BI%2FP-ND/319425) on one SPI bus but I cannot get them to both communicate accurately. I have connected all the MISO pins to pin 50, one of slave selects to 53, and the other slave select to 49. The MOSI pin is not needed for this device. Each ADC works by itself when the other ADC isn't on the same bus but not together. Is there anything obvious that I'm missing or is this a problem with the ADC? This is the code I am using:
#include <SPI.h> // SPI Library
unsigned int li_bit = 0; // Sunlight bit count
unsigned int hih_bit = 0; // Humidity bit count
const int lipin = 53; // Slave select pins
const int hihpin = 49;
void setup(){
Serial.begin(1200); // Begin serial moniter
pinMode(hihpin,OUTPUT);
digitalWrite(hihpin,HIGH);
pinMode(lipin,OUTPUT);
digitalWrite(lipin,HIGH);
SPI.begin(); // Start SPI
SPI.setBitOrder(MSBFIRST); // Set SPI protocols
SPI.setDataMode(SPI_MODE0);
Serial.println("Type to Start"); // Wait for serial signal
while(!Serial.available());
}
void loop(){
li_bit = mcp3201(lipin); // Find licor digital value
hih_bit = mcp3201(hihpin);
Serial.print(li_bit); // Print
Serial.print(" ");
Serial.println(hih_bit);
delay(1000); // Delay
}
unsigned int mcp3201(const int pinnum){ // Function to interact MCP3201 ADC -- Pass Slave Select pin in
word bitnum = 0; // Initialize return
digitalWrite(pinnum, LOW); // Start communication
byte msb = SPI.transfer(0); // Communicate
byte lsb = SPI.transfer(0);
digitalWrite(pinnum, HIGH); // End communication
bitnum = ((bitnum | msb) << 8) | lsb; // Concatenate bytes into word
bitnum = bitnum >> 1; // Remove extraneous data
bitnum = bitnum << 4;
bitnum = bitnum >> 4;
return(bitnum); // Return number of bits
}
Thanks in advance for any and all help!