LT1867 ADC - What pin is the unit8_t cs pin actually referring too ?

Hi,
I have been going thru all of the libraries associated with DC806A (Linduino demo board) trying to find where the "cs" (Chip Select pin) is actually connected too on the arduino end. It seems the LT_SPI library is where they refer to this pin and set it up as an output but I can't anywhere find what Digital Output they refer to so that I can change it or just connect to it.

After 2 weeks and new grey hairs, my project is late, my customer unhappy, I'm learning alot and I understand you guys like us to learn ourselves but please can someone help me ?????

#include <Arduino.h>
#include <stdint.h>
#include "Linduino.h"
#include "LT_SPI.h"
#include "UserInterface.h"
#include "LT_I2C.h"
#include "QuikEval_EEPROM.h"
#include "LTC1867.h"
#include <SPI.h>
#include <Wire.h>
//! Initialize Linduino
void setup()
{
  char demo_name[]="DC806";      //!< Demo Board Name stored in QuikEval EEPROM
  uint16_t adc_code;
  
  quikeval_I2C_init();           // Configure the EEPROM I2C port for 100kHz
  quikeval_SPI_init();           // Configure the spi port for 4MHz SCK
  quikeval_SPI_connect();        // Connect SPI to main data port
  Serial.begin(115200);          // Initialize the serial port to the PC
  print_title();
  demo_board_connected = discover_demo_board(demo_name);
  if (demo_board_connected)
  {
    restore_calibration();
    LTC1867_read(LTC1867_CS, BUILD_COMMAND_SINGLE_ENDED[0], &adc_code); // Wakes up ADC if it was in sleep mode
    print_prompt();
  }
}

void loop(){

//! Read Channels in Single-Ended mode with Ch7 as COM
//! @return void
void menu_3_read_single_ended_com7()
{
  uint8_t user_command;
  uint8_t adc_command;                             // The LTC1867 command byte
  uint16_t adc_code = 0;                           // The LTC1867 code
  float adc_voltage;                               // The LTC1867 voltage
  while (1)
  {
    if (uni_bi_polar == LTC1867_UNIPOLAR_MODE)
      Serial.println(F("Single-Ended (COM=CH7), Unipolar mode:"));
    else
      Serial.println(F("Single-Ended (COM=CH7), Bipolar mode:"));

    Serial.println();                              // Display single-ended menu
    Serial.println(F("*************************"));
    Serial.println();
    Serial.println(F("CH7 as COM\n"));
    Serial.println(F("0-CH0"));
    Serial.println(F("1-CH1"));
    Serial.println(F("2-CH2"));
    Serial.println(F("3-CH3"));
    Serial.println(F("4-CH4"));
    Serial.println(F("5-CH5"));
    Serial.println(F("6-CH6"));
    Serial.println(F("7-ALL"));
    Serial.println(F("m-Main Menu"));
    Serial.print(F("Enter a Command: "));

    user_command = read_int();                     // Read the single command
    if (user_command == 'm')
      return;

    Serial.println(user_command);
    Serial.println();

    if (user_command == 7)
    {
      Serial.println(F("ALL with CH7 as COM"));

      adc_command = BUILD_COMMAND_SINGLE_ENDED_COM7[0] | uni_bi_polar;  // Build ADC command for channel 0 with channel 7 as a common pin
      LTC1867_read(LTC1867_CS, adc_command, &adc_code);                 // Throws out last reading
      delay(100);
      uint8_t x;                                                        //!< iteration variable
      for (x = 0; x <= 6; x++)                                          // Read all channels in single-ended mode with channel 7 as a common pin
      {
        adc_command = BUILD_COMMAND_SINGLE_ENDED_COM7[(x + 1) % 7] | uni_bi_polar;
        LTC1867_read(LTC1867_CS, adc_command, &adc_code);
        if (uni_bi_polar == LTC1867_UNIPOLAR_MODE)
          adc_voltage = LTC1867_unipolar_code_to_voltage(adc_code, LTC1867_lsb, LTC1867_offset_bipolar_code);
        else
          adc_voltage = LTC1867_bipolar_code_to_voltage(adc_code, LTC1867_lsb, LTC1867_offset_bipolar_code);
        Serial.println();
        Serial.print(F("  ****"));
        Serial.print(F("CH"));
        Serial.print(x);
        Serial.print(F(" with CH7 as COM: "));
        Serial.print(adc_voltage, 4);
        Serial.println(F("V"));
      }
    }
    else
    {
      adc_command = BUILD_COMMAND_SINGLE_ENDED_COM7[user_command]| uni_bi_polar;
      Serial.println();
      Serial.print(F("ADC Command: B"));
      Serial.println(adc_command, BIN);
      LTC1867_read(LTC1867_CS, adc_command, &adc_code);                 // Throws out last reading
      delay(100);
      LTC1867_read(LTC1867_CS, adc_command, &adc_code);
      Serial.print(F("Received Code: 0x"));
      Serial.println(adc_code, HEX);
      if (uni_bi_polar == LTC1867_UNIPOLAR_MODE)
        adc_voltage = LTC1867_unipolar_code_to_voltage(adc_code, LTC1867_lsb, LTC1867_offset_bipolar_code);
      else
        adc_voltage = LTC1867_bipolar_code_to_voltage(adc_code, LTC1867_lsb, LTC1867_offset_bipolar_code);
      Serial.println();
      Serial.print(F("  ****"));
      Serial.print(F("CH"));
      Serial.print(user_command);
      Serial.print(F(": "));
      Serial.print(adc_voltage, 4);
      Serial.println(F("V"));
    }
  }
}

There is other code that I have left out cause it's just so huge and irrelivant to what I am trying to do.
Below is my code so far (it does not compile and may have silly errors but it's not finished, until I can wire it up properly, I can't test.

So anyone who knows where this unit8_t CS (unit8_t cs pin (in libraries) ) is defined and can help, please do. Even if i have to pay you :slight_smile:

It's uint8_t (unsigned 8 bit integer), not unit8_t.
I've found it makes things much easier to find if you're looking for the correct thing. :slight_smile:

The ChipSelect is set in the include file.
In most cases something like this: #define LTC1867_CS QUIKEVAL_CS
The QUIKEVAL_CS is set in the "Linduino.h" file: #define QUIKEVAL_CS SS
And the 'SS' pin is the default ChipSelect of the SPI hardware of an Arduino. For an ATmega328p, that is Arduino pin 10 or PB2.

BlackSnake:
Hi,
I have been going thru all of the libraries associated with DC806A (Linduino demo board) trying to find where the "cs" (Chip Select pin) is actually connected too on the arduino end.

You do realize you could have simply added this to setup

  Serial.println (LTC1867_CS);

To print out the pin number?

MarkT +1 for outsmarting me :wink:

Thank you Mark T (very clever ) and No I didn't think of that.
Thank you Peter your information whilst a different tack is also great. I did got thru all the associated libraries and couldn't find where they defined the pin CS and am using my own board in conjunction with a Nano and it's tracked to use Pin 6 so now I hope I can succesfully change it. I have seen this code and hope it works as I tried it earlier but every mention of Unit8_t brings up an error code.
uint8_t CS = 6; // Seems obvious I know but in some instances it's cs (not CS).

Really grateful guy's

Can someone see why my code won't loop ? and why it won't read the analog voltage thru the ADC (LTC1867) ?????

#include <SPI.h>
#include <Wire.h>
#include <stdint.h>
#include "LT_SPI.h"
#include "LTC1867.h"
#include "Linduino.h"

//const uint8_t LTC1867_CS = 6; // LTC1867 Chip Select Pin
const uint8_t BUILD_COMMAND_SINGLE_ENDED_COM7 = {LTC1867_CH0_7COM | LTC1867_UNIPOLAR_MODE};

void setup(){
  pinMode(LTC1867_CS, OUTPUT);
  digitalWrite(LTC1867_CS, LOW);
  
 // Define LTC1867 SPI setup
 SPI.setBitOrder(MSBFIRST);
 SPI.setDataMode(SPI_MODE0);
 SPI.setClockDivider(SPI_CLOCK_DIV4);
 SPI.begin();
 
 // Start Serial Comms
 Serial.begin(9600);
}

void loop(){
  Serial.print(LTC1867_CS);
  int looped;
  looped = looped++;
  Serial.print("     loop count = ");
  Serial.println(looped);
  
  if(Serial.available() > 0){
  uint8_t adc_command;
  uint16_t adc_code;
  adc_command = BUILD_COMMAND_SINGLE_ENDED_COM7;  // Build ADC command for channel 0 with channel 7 as a common pin
     LTC1867_read(LTC1867_CS, adc_command, &adc_code);  // Throws out last reading
     delay(100);
     uint8_t x;                                                        //!< iteration variable
       for (x = 0; x <= 6; x++)                                          // Read all channels in single-ended mode with channel 7 as a common pin
        {
          adc_command = BUILD_COMMAND_SINGLE_ENDED_COM7;
          LTC1867_read(LTC1867_CS, adc_command, &adc_code);
          Serial.println(adc_code,DEC);
          // We need to work out the LSB & offset Bi-Polar code to change DAC to Volts
          //adc_voltage = LTC1867_unipolar_code_to_voltage(adc_code, LTC1867_lsb, LTC1867_offset_bipolar_code);
          //Serial.println(adc_voltage, 4);
        }
        Serial.print(adc_code, DEC);
  }
  else(Serial.println("No Serial Available"));
  
 delay(30);       
}
void LTC1867_read(uint8_t cs, uint8_t adc_command, uint16_t*adc_code);

When I comment out the Serial.available() >0 line of code I get "1" on the serial monitor else I get "1" repeated over and over.
I have a scope hooked up to Pin 6 (CS pin) and Im not getting anything on that pin. I changed the library to work on pin6 instead of pin 10 and confirmed this by printing LTC1867_CS (as suggested).
Any help would be greatly appreciated. Thank you
I have modified the LTC library and uncommented the code I believe I need but I'm out of my leauge and need YOUR help

  int looped;
  looped = looped++;

What value is in looped when the first statement is executed? If you said 0, you are wrong. If you said "some random garbage", you are correct. Now, why would you want to increment some random garbage?

PaulS:

  int looped;

looped = looped++;



What value is in looped when the first statement is executed? If you said 0, you are wrong. If you said "some random garbage", you are correct. Now, why would you want to increment some random garbage?

And looped will never exceed one more than its initial random value, as it's being reinitialised every time around loop().