MCP3208 through MAX14850 (Digital Isolator)


i'm trying connect mcp3208 max14850ase+ can't work.
datasheet: max14850



the test code works without max between two:
code: [select]
#define selpin 10     //selection pin
#define dataout 11    //mosi
#define datain  12    //miso
#define spiclock  13  //clock
int readvalue;

void setup(){
 //set pin modes
 pinmode(selpin, output);
 pinmode(dataout, output);
 pinmode(datain, input);
 pinmode(spiclock, output);
 //disable device start
 digitalwrite(selpin,high);
 digitalwrite(dataout,low);
 digitalwrite(spiclock,low);

 serial.begin(9600);
}

int read_adc(int channel){
  int adcvalue = 0;
  byte commandbits = b11000000; //command bits - start, mode, chn (3), dont care (3)

  //allow channel selection
  commandbits|=((channel-1)<<3);

  digitalwrite(selpin,low); //select adc
  // setup bits written
  for (int i=7; i>=3; i--){
    digitalwrite(dataout,commandbits&1<<i);
    //cycle clock
    digitalwrite(spiclock,high);
    digitalwrite(spiclock,low);    
  }

  digitalwrite(spiclock,high);    //ignores 2 null bits
  digitalwrite(spiclock,low);
  digitalwrite(spiclock,high);  
  digitalwrite(spiclock,low);

  //read bits adc
  for (int i=11; i>=0; i--){
    adcvalue+=digitalread(datain)<<i;
    //cycle clock
    digitalwrite(spiclock,high);
    digitalwrite(spiclock,low);
  }
  digitalwrite(selpin, high); //turn off device
  return adcvalue;
}


void loop() {
 readvalue = read_adc(1);
 serial.println(readvalue,dec);
 readvalue = read_adc(2);
 serial.println(readvalue,dec);
 serial.println(" ");
 delay(5000);
}

why don't want connect mcp3208 directly arduino? max14850 driven on both sides same 5v. make sense you?


Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > MCP3208 through MAX14850 (Digital Isolator)


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor