91 voltage = (float)adc_code;
92 voltage = vref * voltage / (4095);
97 if ((adc_code & 0x8000) == 0x8000)
99 adc_code = (adc_code ^ 0xFFFF)+1;
102 voltage = sign*(float)adc_code;
103 voltage = vref * voltage / 2047;
void LTC2302_read(uint8_t cs, uint16_t adc_command, uint16_t *adc_code)
Reads the ADC and returns 16-bit data.
static uint8_t adc_command
static uint8_t uni_bipolar
Default set for unipolar mode.
LTC2302: 12-Bit, 1-Channel 500ksps SAR ADC with SPI Interface.
float LTC2302_code_to_voltage(uint16_t adc_code, float vref, uint8_t uni_bipolar)
Calculates the LTC2302 input voltage given the data, range, and unipolar/bipolar status.
void spi_transfer_word(uint8_t cs_pin, uint16_t tx, uint16_t *rx)
Reads and sends a word.
LT_SPI: Routines to communicate with ATmega328P's hardware SPI port.