Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Having Trouble Reading and Writing From LTC6803-3

  1. Jun 4, 2013 #1
    Hello everyone,

    I've been hard pressed to complete something that seems relatively simple to do, but I just can't seem to get it working properly.

    I'm currently attempting to read and write from the configuration registers of six daisy-chained LTC6803-3's, whose datasheet can be found here: http://cds.linear.com/docs/en/datasheet/680313fa.pdf

    This daisy-chain is controlled by an Arduino Uno board.

    There are two issues I've found so far. One is that the MISO line never seems to be active (I don't have an oscilloscope, so these observations are coming from monitoring the line using an LED). The other is that the data I read out does not match the data I write in, with the PEC byte I read out not matching the PEC byte I write to the board.

    Here is my code:
    Code (Text):
    #include <SPI.h>

    byte config[6] = {0x61,0x00,0x00,0x00,0x00,0x00};

    byte WRCFG = 0x01;
    byte RDCFG = 0x02;

    byte WRPEC = 0xC7;
    byte RDPEC = 0xCE;

    const int CS0 = 4;
    const int CS1 = 5;
    const int CS2 = 6;
    const int DECODER_EN = 7;
    const int SCKPIN = 13;
    const int V1_EN = 10;

    //Function to calc PEC from [PLAIN]http://calsol.googlecode.com/svn-history/r238/trunk/BMS/bps.h[/PLAIN] [Broken]
    byte getPEC(byte * din, int n) {
      byte pec, in0, in1, in2;
      pec = 0x41;
      for(int j=0; j<n; j++) {
        for(int i=0; i<8; i++) {
          in0 = ((din[j] >> (7 - i)) & 0x01) ^ ((pec >> 7) & 0x01);
          in1 = in0 ^ ((pec >> 0) & 0x01);
          in2 = in0 ^ ((pec >> 1) & 0x01);
          pec = in0 | (in1 << 1) | (in2 << 2) | ((pec << 1) & ~0x07);
        }
      }
      return pec;
    }

    void setup()
    {
      pinMode(CS0,OUTPUT);
      pinMode(CS1,OUTPUT);
      pinMode(CS2,OUTPUT);
      pinMode(DECODER_EN,OUTPUT);
      pinMode(SCKPIN,OUTPUT);
      pinMode(V1_EN,OUTPUT);
     
        //set up CS
      digitalWrite(DECODER_EN,LOW);
      digitalWrite(CS0,HIGH);
      digitalWrite(CS1,HIGH);
      digitalWrite(CS2,HIGH);
      digitalWrite(SCKPIN,HIGH);
      digitalWrite(V1_EN,HIGH);
     
     
      Serial.begin(9600);
      SPI.begin();
      //SPI.setClockDivider(SPI_CLOCK_DIV64);
      SPI.setDataMode(SPI_MODE3);
      SPI.setBitOrder(MSBFIRST);
      SPI.setClockDivider(SPI_CLOCK_DIV64);
     
      digitalWrite(DECODER_EN,HIGH);
      digitalWrite(CS1,LOW);
        //set config
      SPI.transfer(WRCFG);
      //delay(10);
      SPI.transfer(WRPEC);
     
      delay(1000);
     
      for(int i=0; i<6; i++){
        SPI.transfer(config[i]);
        Serial.println(config[i],HEX);
        delay(10);
      }
      SPI.transfer(getPEC(config,6));
      Serial.println(getPEC(config,6),HEX);
      delay(10);
      digitalWrite(CS1,HIGH);
      Serial.println("");
      delay(100);
       
    }

    void loop()
    {
        //read registers
      digitalWrite(CS1,LOW);
      SPI.transfer(RDCFG);
      delay(10);
      SPI.transfer(RDPEC);
      delay(10);
     
      byte rconfig[6];
      for(int i=0; i<6; i++){
        rconfig[i] = SPI.transfer(RDCFG);
        delay(10);
        Serial.print(rconfig[i],HEX);
        Serial.println();
      }
      byte pec = SPI.transfer(RDCFG);
      delay(10);
      Serial.println(pec,HEX);
      Serial.println();
      delay(10);
      digitalWrite(CS1,HIGH);
      delay(1000);
    }
    The LTC daisy-chain is hooked up to an SPI isolator, and the CS0, CS1, CS2, and DECODER_EN pins are used to control the chip select decoder. There's a few individual ADCs on the board as well, but I'm positive those are working just fine. I've tested the decoder and isolator by themselves, and they're functioning properly, which leads me to believe there's something funky going on with my code.

    The PEC calculation function is working properly, as I tested it with the example given in the LTC datasheet.

    I'm completely lost as to where to go next. I'm hoping someone else has had experience working with these chips before and can give me a nudge in the right direction. Thanks!
     
    Last edited by a moderator: May 6, 2017
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted



Similar Discussions: Having Trouble Reading and Writing From LTC6803-3
  1. Having Trouble in EE (Replies: 7)

Loading...