//******************************************************
// LMP91000EVM COde for Cyclic Voltametry
// The values of registers are based on the paper
// https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=8095460
// !2-06-2018
//******************************************************
#include <Wire.h>
#include "LMP91000.h"

LMP91000 lmp91000;

void setup(void){
      Serial.begin(9600);
      Serial.println("LMP91000EVM ");
      Wire.begin();
      
      // initialize the slot select pins to "not selected"
      pinMode(7, OUTPUT);  digitalWrite(7, LOW);
      pinMode(9, OUTPUT);  digitalWrite(9, LOW);
      pinMode(10, OUTPUT); digitalWrite(10, LOW);      
      digitalWrite(9, HIGH); // select CO
      
      // settings for voltametry
      uint8_t res = lmp91000.configure( 
            LMP91000_TIA_GAIN_35K | LMP91000_RLOAD_10OHM,
            LMP91000_REF_SOURCE_INT | LMP91000_INT_Z_50PCT 
                  | LMP91000_BIAS_SIGN_POS | LMP91000_BIAS_24PCT,
            LMP91000_FET_SHORT_DISABLED | LMP91000_OP_MODE_AMPEROMETRIC                  
      );
      
      Serial.print("Config Result: ");
      Serial.println(res);
      
      Serial.print("STATUS: ");
      Serial.println(lmp91000.read(LMP91000_STATUS_REG),HEX);
      Serial.print("TIACN: ");
      Serial.println(lmp91000.read(LMP91000_TIACN_REG),HEX);
      Serial.print("REFCN: ");
      Serial.println(lmp91000.read(LMP91000_REFCN_REG),HEX);
      Serial.print("MODECN: ");
      Serial.println(lmp91000.read(LMP91000_MODECN_REG),HEX);                  
      
}

void loop(void){

delay(100);
Serial.println("Vout = ");
Serial.println(A0);
Serial.println("Vref = ");
Serial.println(A1);
}