Hi
I will put my schematic of arduino board and program i have used here.
i want to use two channels of LTC2414. but with the below code...output data is a fixed...in variable input, no changes happens in output....whats the problem?
#include <stdint.h>
#include <SPI.h>
// LTC2418 single-ended configuration bytes
// these are the binary commands converted to hex to be sent through MISO
#define LTC2418_CH0 0xB0
#define LTC2418_CH1 0xB8
#define LTC2418_CH2 0xB1
#define LTC2418_CH3 0xB9
#define LTC2418_CH4 0xB2
#define LTC2418_CH5 0xBA
#define LTC2418_CH6 0xB3
#define LTC2418_CH7 0xBB
#define LTC2418_CH8 0xB4
#define LTC2418_CH9 0xBC
#define LTC2418_CH10 0xB5
#define LTC2418_CH11 0xBD
#define LTC2418_CH12 0xB6
#define LTC2418_CH13 0xBE
#define LTC2418_CH14 0xB7
#define LTC2418_CH15 0xBF
/*macros*/
/********************************************************/
// set pin low
#define output_low(pin) digitalWrite(pin, LOW)
// set pin high
#define output_high(pin) digitalWrite(pin, HIGH)
// return the state of pin
#define input(pin) digitalRead(pin)
/********************************************************/
#define CS_multiplex 10
#define CS_accel 9
#define CS_mag 8
// constants
// constants defined within the LTC2418.h file are hex values corresponding to commands (when converted to binary) for reading each channel in single-ended mode
const uint8_t BUILD_COMMAND_SINGLE_ENDED[16] = {LTC2418_CH0, LTC2418_CH1, LTC2418_CH2, LTC2418_CH3,
LTC2418_CH4, LTC2418_CH5, LTC2418_CH6, LTC2418_CH7,
LTC2418_CH8, LTC2418_CH9, LTC2418_CH10, LTC2418_CH11,
LTC2418_CH12, LTC2418_CH13, LTC2418_CH14, LTC2418_CH15
};
const uint16_t MISO_TIMEOUT = 1000; // the MISO timeout (ms)
// function prototypes
int8_t LTC2418_EOC_timeout(uint8_t cs, uint16_t miso_timeout); // check LTC2418 to see if end of conversion
void LTC2418_single_read_raw(uint8_t cs, uint8_t adc_command, uint32_t *adc_code); // read single channel raw data
void setup() {
// set chip select pins as output pins
pinMode(CS_multiplex, OUTPUT);
pinMode(CS_accel, OUTPUT);
pinMode(CS_mag, OUTPUT);
SPI.begin();
SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
output_high(CS_multiplex); // pulls DAQ multiplexer chip select high
output_high(CS_accel); // pulls accelerometer chip select high
output_high(CS_mag); // pulls magnometer chip select high
Serial.begin(115200); // begin serial port with specified baud rate
}
void loop()
{
while (1)
{
uint32_t raw_output;
uint8_t tx_command;
tx_command = BUILD_COMMAND_SINGLE_ENDED[8]; // build ADC command
Serial.print("\nReading channel 8...\n");
if (LTC2418_EOC_timeout(CS_multiplex, MISO_TIMEOUT == 1)) // check for EOC
{
Serial.print("Wait for EOC timed out\n");
}
LTC2418_single_read_raw(CS_multiplex, tx_command, &raw_output);
Serial.print("RAW TX: ");
Serial.print(tx_command, HEX);
Serial.print("\n");
Serial.print("RAW RX: ");
Serial.print(raw_output, HEX);
Serial.print("\n");
delay(2000);
}
}
// function definitions
// Checks for EOC with a specified timeout
int8_t LTC2418_EOC_timeout(uint8_t cs, uint16_t miso_timeout)
{
uint16_t timer_count = 0; // Timer count for MISO
output_low(cs); //! 1) Pull CS low
while (1) //! 2) Wait for SDO (MISO) to go low
{
if (input(MISO) == 0)
{
break; //! 3) If SDO is low, break loop
}
if (timer_count ++ > miso_timeout) // If timeout, return 1 (failure)
{
output_high(cs); // Pull CS high
return(1);
}
else
delay(1);
}
return(0);
}
// Reads single channel raw data on LTC2418
void LTC2418_single_read_raw(uint8_t cs, uint8_t adc_command, uint32_t *adc_code)
{
union union_int32_4bytes
{
uint32_t LT_uint32; // 32-bit unsigned integer
int32_t LT_int32; // 32-bit signed integer
uint8_t LT_byte[4]; // 4 bytes unsigned (4 * 8-bit integers)
} data, command;
command.LT_byte[0] = adc_command;
command.LT_byte[1] = 0;
command.LT_byte[2] = 0;
command.LT_byte[3] = 0;
output_low(cs); //! 1) Pull CS low
data.LT_byte[0] = SPI.transfer(command.LT_byte[0]);
data.LT_byte[1] = SPI.transfer(command.LT_byte[1]);
data.LT_byte[2] = SPI.transfer(command.LT_byte[2]);
data.LT_byte[3] = SPI.transfer(command.LT_byte[3]);
output_high(cs); //! 3) Pull CS high
Serial.print("TX:\n");
Serial.print("LT_byte[0] = "); Serial.print(command.LT_byte[0], BIN); Serial.print("\t");
Serial.print("LT_byte[1] = "); Serial.print(command.LT_byte[1], BIN); Serial.print("\t");
Serial.print("LT_byte[2] = "); Serial.print(command.LT_byte[2], BIN); Serial.print("\t");
Serial.print("LT_byte[3] = "); Serial.print(command.LT_byte[3], BIN); Serial.print("\t");
Serial.print("\n");
Serial.print("RX:\n");
Serial.print("LT_byte[0] = "); Serial.print(data.LT_byte[0], BIN); Serial.print("\t");
Serial.print("LT_byte[1] = "); Serial.print(data.LT_byte[1], BIN); Serial.print("\t");
Serial.print("LT_byte[2] = "); Serial.print(data.LT_byte[2], BIN); Serial.print("\t");
Serial.print("LT_byte[3] = "); Serial.print(data.LT_byte[3], BIN); Serial.print("\t");
Serial.print("\n");
*adc_code = data.LT_int32;
}

