#ifndef _MAX122x_H_ #define _MAX122x_H_ // SPI communication settings #define SPI_SETTINGS SPISettings(4000000, MSBFIRST, SPI_MODE0) // max 4.8MHz readout clock speed on MAX122x // MAX122x Mode 11 registers // Conversion MSBFirst: BIT7:1|BIT6:CHSEL3|BIT5:CHSEL2|BIT4:CHSEL1|BIT3:CHSEL0|BIT2:SCAN1|BIT1:SCAN0|BIT0:TEMP #define MAX122x_CONVERT_CH0 0b10000110 // Initiates single ADC conversion on Ch0 #define MAX122x_CONVERT_CH1 0b10001110 // Initiates single ADC conversion on Ch1 #define MAX122x_CONVERT_CH2 0b10010110 // Initiates single ADC conversion on Ch2 #define MAX122x_CONVERT_CH3 0b10011110 // Initiates single ADC conversion on Ch3 #define MAX122x_CONVERT_CH4 0b10100110 // Initiates single ADC conversion on Ch4 #define MAX122x_CONVERT_CH5 0b10101110 // Initiates single ADC conversion on Ch5 #define MAX122x_CONVERT_CH6 0b10110110 // Initiates single ADC conversion on Ch6 #define MAX122x_CONVERT_CH7 0b10111110 // Initiates single ADC conversion on Ch7 #define MAX122x_CONVERT_CH8 0b11000110 // Initiates single ADC conversion on Ch8 #define MAX122x_CONVERT_CH9 0b11001110 // Initiates single ADC conversion on Ch9 #define MAX122x_CONVERT_CH10 0b11010110 // Initiates single ADC conversion on Ch10 #define MAX122x_CONVERT_CH11 0b11011110 // Initiates single ADC conversion on Ch11 #define MAX122x_CONVERT_TMP 0b10000001 // Initiates single TMP conversion // Setup MSB first: BIT7:0|BIT6:1|BIT5:CKSEL1|BIT4:CKSEL0|BIT3:REFSEL1|BIT2:REFSEL0|BIT1:DIFFSEL1|BIT0:DIFFSEL0 #define MAX122x_SETUP_0 0b01110000 // External Timed by SCLK, Internal Reference w/ wakeup time, no unipolar/bipolar register write #define MAX122x_SETUP_1 0b01111000 // External Timed by SCLK, Internal Reference w/o wakeup time, no unipolar/bipolar register write #define MAX122x_SETUP_2 0b01100000 // Internally timed, use of EOC signal, Internal Reference w/ wakeup time, no unipolar/bipolar register write #define MAX122x_SETUP_3 0b01101000 // Internally timed, use of EOC signal, Internal Reference w/o wakeup time, no unipolar/bipolar register write // Averaging // Not implemented because Mode 11 does not allow averaging and scanning // Reset (all registers to 0) #define MAX122x_RESET_ALL 0b00011000 // Resets all registers #define MAX122x_RESET_FIFO 0b00010000 // Clears FIFO only // Unipolar mode setup & bipolar mode setup // Not implemented since unipolar, single ended is default case // May be needed depending on Arduino version #if (ARDUINO >=100) #include "Arduino.h" #else #include "WProgram.h" #endif struct ADCresults0to3{ uint16_t result_ch0,result_ch1,result_ch2,result_ch3; }; struct ADCresults0to7{ uint16_t result_ch0,result_ch1,result_ch2,result_ch3,result_ch4,result_ch5,result_ch6,result_ch7; }; struct ADCresults0to11{ uint16_t result_ch0,result_ch1,result_ch2,result_ch3,result_ch4,result_ch5,result_ch6,result_ch7,result_ch8,result_ch9,result_ch10,result_ch11; }; // Create class for MAX122x ADC class MAX122x_library { public: // Constructor MAX122x_library(bool displayMsg=false); // Methods float max122xreadTemp(uint8_t Chipselect_Pin); uint16_t max122xreadADCsingle(uint8_t Chipselect_Pin, byte channel); struct ADCresults0to3 max122xReadADC0to3(uint8_t Chipselect_Pin); struct ADCresults0to7 max122xReadADC0to7(uint8_t Chipselect_Pin); struct ADCresults0to11 max122xReadADC0to11(uint8_t Chipselect_Pin); float max122xFloatToVoltage(uint16_t adc_raw_value); private: uint8_t SPI_delay_commandSkip = 8; // in microseconds uint8_t SPI_delay_conversionTime = 65; // in microseconds }; #endif // _MAX122x_H_