76 lines
2.2 KiB
C++
76 lines
2.2 KiB
C++
|
|
#include<math.h>
|
|
|
|
#include <SPI.h>
|
|
#define SCLK 13
|
|
#define MOSI 11
|
|
#define MISO 12
|
|
#define CS_ADC 10
|
|
|
|
#include "MAX122x.h"
|
|
MAX122x_library max122x_library(true);
|
|
// SPISettings MAX1229_SETTINGS(4000000, MSBFIRST, SPI_MODE0); // max 4.8MHz readout clock speed on MAX1229
|
|
|
|
uint16_t ch0_bit,ch1_bit,ch2_bit,ch3_bit,ch4_bit,ch5_bit;
|
|
float ch0_volt,ch1_volt,ch2_volt,ch3_volt,ch4_volt,ch5_volt;
|
|
float temperature;
|
|
struct ADCresults0to3;
|
|
|
|
|
|
void setup() {
|
|
|
|
// Initiate console
|
|
Serial.begin(9600);
|
|
Serial.setTimeout(1000000);
|
|
|
|
// Initialise SPI pins and SPI protocol
|
|
pinMode(CS_ADC, OUTPUT); // declare SS output
|
|
pinMode(MOSI, OUTPUT); // declare MOSI output
|
|
pinMode(MISO, INPUT); // declare MISO input (not stricly necessary)
|
|
pinMode(SCLK, OUTPUT); // declare SCLK output
|
|
SPI.begin();
|
|
//SPI.setClockDivider(SPI_CLOCK_DIV8);
|
|
digitalWrite(CS_ADC,HIGH);
|
|
}// end of setup()
|
|
|
|
void loop() {
|
|
// Readout values
|
|
temperature = max122x_library.max122xreadTemp(CS_ADC);
|
|
ch0_bit = max122x_library.max122xreadADCsingle(CS_ADC,0);
|
|
ch1_bit = max122x_library.max122xreadADCsingle(CS_ADC,1);
|
|
ch2_bit = max122x_library.max122xreadADCsingle(CS_ADC,2);
|
|
ch3_bit = max122x_library.max122xreadADCsingle(CS_ADC,3);
|
|
ch4_bit = max122x_library.max122xreadADCsingle(CS_ADC,4);
|
|
ch5_bit = max122x_library.max122xreadADCsingle(CS_ADC,5);
|
|
ch0_volt = max122x_library.max122xFloatToVoltage(ch0_bit);
|
|
ch1_volt = max122x_library.max122xFloatToVoltage(ch1_bit);
|
|
ch2_volt = max122x_library.max122xFloatToVoltage(ch2_bit);
|
|
ch3_volt = max122x_library.max122xFloatToVoltage(ch3_bit);
|
|
ch4_volt = max122x_library.max122xFloatToVoltage(ch4_bit);
|
|
ch5_volt = max122x_library.max122xFloatToVoltage(ch5_bit);
|
|
|
|
// Print out results on serial monitor
|
|
if(true){
|
|
Serial.println(ch0_volt);
|
|
Serial.println(ch1_volt);
|
|
Serial.println(ch2_volt);
|
|
Serial.println(ch3_volt);
|
|
Serial.println(ch4_volt);
|
|
Serial.println(ch5_volt);
|
|
Serial.println(temperature);
|
|
Serial.println();
|
|
}
|
|
if(false){
|
|
Serial.println(ch0_bit);
|
|
Serial.println(ch1_bit);
|
|
Serial.println(ch2_bit);
|
|
Serial.println(ch3_bit);
|
|
Serial.println(ch4_bit);
|
|
Serial.println(ch5_bit);
|
|
Serial.println(temperature);
|
|
Serial.println();
|
|
}
|
|
|
|
|
|
} // end of loop()
|