Shield Code 6.0
Loading...
Searching...
No Matches
Max1148.cpp
Go to the documentation of this file.
1#include <Max1148.hpp>
3uint16_t Max1148::adc_read_avg(int avg_num){
4 int total_data = 0;
5 //SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE));
6 for(int i = 0; i < avg_num; i++){
7 //separate variable for debugging
8 uint16_t data = adc_read();
9 total_data += data;
10 }
11 //SPI.endTransaction();
12 return (uint16_t)(total_data / avg_num);
13}
14
15//probe left side of R3 for data in
17 //set up SPI, macros in Max1148.hpp
18 //SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE));
19 //data from each sample
20 uint16_t data = 0;
21 //total data from all samples
22 //send command to congfigure ADC channel
23 csl();
24 //note - manual delay removed because we are on external clock now.
25 SPI.transfer(channel);
26 //delayMicroseconds(50);
27 //send dummy byte to get first byte of data
28 data = SPI.transfer(ADC_READ) << 8;
29 //Max1148 is a 14 bit ADC - so we have to do two SPI transfers to get all the data.
30 data |= SPI.transfer(ADC_READ);
31 //add data to total. Shifted right because result is left justified - Jacob
32 csh();
33 //SPI.endTransaction();
34 return data;
35}
36
39 digitalWrite(cs_pin, LOW);
40}
41
44 digitalWrite(cs_pin, HIGH);
45}
Header file for the Max1148 library for Dartmouth's 317 Lab. Manages ADC communication through SPI.
#define ADC_READ
Definition: Max1148.hpp:37
void csh()
Sets the chip select pin to high.
Definition: Max1148.cpp:43
void csl()
Sets the chip select pin to low.
Definition: Max1148.cpp:38
uint16_t adc_read()
Reads a single ADC value from the Max1148 ADC. Used in adc_read_avg.
Definition: Max1148.cpp:16
uint8_t channel
Channel for the ADC. Selected in the constructor.
Definition: Max1148.hpp:70
int cs_pin
Chip select pin for the ADC.
Definition: Max1148.hpp:66
uint16_t adc_read_avg(int avg_number)
Reads an average ADC value from the Max1148 ADC. Uses Arduino's SPI library. We don't use this anymor...
Definition: Max1148.cpp:3