This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LDC1000 Arduino Interface: Reading Zeros from proximity data registers

Other Parts Discussed in Thread: LDC1000EVM, MSP430G2553, ENERGIA

Hi there


I am attempting to interface Arduino with the LDC1000. I have simply snapped the LDC1000 and the coil off of the LDC1000EVM and I am using those. I am using an Arduino Uno. This is my code:

#include "SPI.h" // include arduino SPI library

const int CSB = 10; // chip select bit for Arduino Uno


void setup() 
{
  Serial.begin(9600);
  // start SPI library/ activate BUS
  SPI.begin();
 
  pinMode(CSB, OUTPUT);  
}

void loop() 
{
  unsigned int val = 0;
  byte READ = 0x80; // MSB = 1 which is a 'read' bit
  byte reg = 0x04; // register address
  
  
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0); // CPOL = 0 and CPH = 0 mode 3 also works
  SPI.setClockDivider(SPI_CLOCK_DIV4); // set SCLK @ 4MHz, LDC1000 max is 4MHz DIV2 also works
  
  // begin data transfer
  digitalWrite(CSB, LOW);
  byte data_2_send = READ + reg;
  SPI.transfer(data_2_send);
  val = SPI.transfer(0x00);
  
  // prints 8 bit decimal value between 0 and 255 found in desired register
  Serial.println(val);
  
  // end data transfer
  digitalWrite(CSB, HIGH);
    
  delay(500);
                 
}

I am able to obtain values from reading registers 0x00 to 0x20, that match the defaults specified in the LDC1000 data sheet. But reading the proximity registers in the same way I have read the other registers results in zeros.

I have left the INTB and TBCLK pins disconnected. I would just like to read the values of the proximity registers and so the INTB pin is of no use to me at this point (to my knowledge) and it would seem that connecting the TBCLK pin is only neccessary for reading frequency data?

I have scoped the INA and INB pins and there is a signal coming through from the coil so that connection seems fine.

Any help on why I am getting zeros would be greatly appreciated

Thank you in advance

  • I have found that the default Rpmin is greater than the default Rpmax. In an attempt to correct this, it was found that I am unable to initialize the threshold and Rpmin and max registers. I can read and write to the power mode register fine, but not the other registers.

    My method in initializing is setting the power mode to 0, writing to the register setting the power mode to 1 and then reading, but the read value is the default value.

    Any suggestions?

  • Problem of initializing is solved. Registers were initialized in the following way:

    PWRCONFIG:      0x00

    RpMax:               0x12
    RpMin:                0x0A
    SENSORFREQ: 0x45 default
    LDCCONFIG:     0x1B default
    CLKCONFIG:     0x01 default
    INTCONFIG:       0x00

    ThresHiLsb:    0x50
    ThresHiMsb:   0x14
    ThresLoLsb:   0xC0
    ThresLoMsb:   0x12

    PWRCONFIG:      0x01

    Still, no proximity data readings other than 0!

  • Nevermind, I am getting proximity readings now.

    P.S I have enjoyed this conversation with myself

  • Would you mind posting your working Arduino code? I am not having much success in correctly writing to the registers. Thanks in advance!

  • Helloooo Christian

    The code posted here is pretty much it! But if you absolutely need more, I have just uploaded code (in .txt files because I can't upload .ino files) . I have also uploaded a PDF which roughly explains what I did step by step.

    This can all by found under my Files in my profile

    Hope it helps

    Otherwise do not hesitate to give me a shout.

    Pelonomi

  • Hello Pelonomi,

    Nicely done documenting your findings.  Thanks for sharing!  I will try this myself.

    George

  • Dear Pelonomi,

    Nicely done!

    Thank you for sharing the code and very nicely documented note.

    Jin

  • Your work is very helpful. Thank you!

  • Hello All,

    I am glad this is resolved. Please let us know if you have any questions.

    Best Regards,

    Natallia Holubeva

  • may i get the working code for ldc1000. your code posted above for help full understanding but i did not get any value from reg.
  • Hello Satheesh,

    We support MSP430 development. The firmware can be downloaded from the product's page.

    Best Regards,
    Natallia Holubeva
  • Hello Natallia,

    Thanks for your reply. I am using msp430g2553. I have used the code mentioned above but i am getting the value from the register is zero. i didn't got any other value. can you please suggest how to load the register configuration value and read the ldc1000 output.
  • Hello Satheesh,

    The datasheet describes the SPI protocol that is used to read/write the data. Could you please attache the scope shot representing what you are reading? I only need to see the SPI.

    Best Regards,
    Natallia Holubeva
  • /****************** Main File *****************/
    
    
    #include <LiquidCrystal.h>
    #include "SPI.h" // include arduino SPI library
    
    LiquidCrystal lcd(8, 9, 10, 11, 12, 13);
    const int CSB = P1_0; // chip select bit for Arduino Uno
    
    
    
      byte RpMax= 0x0E; 
      byte RpMin= 0x36;
      byte SENSORFREQ= 0x45;
      byte LDCCONFIG= 0x1B; 
      byte CLKCONFIG= 0x01; 
      byte INTCONFIG= 0x00;
    
      byte ThresHiLsb= 0x50;
      byte ThresHiMsb= 0x14;
      byte ThresLoLsb= 0xC0;
      byte ThresLoMsb= 0x12;
     
      
    void setup() 
    {
      Serial.begin(9600);
      SPI.begin();	// start SPI library/ activate BUS
      lcd.begin(16, 2);
      pinMode(CSB, OUTPUT);
      
      digitalWrite(CSB, LOW);
    
     // SPI.transfer(0x01); Address of RpMax
      SPI.transfer(RpMax);
    
      //SPI.transfer(0x02); Address of RpMin
      SPI.transfer(RpMin);
    
      //SPI.transfer(0x03); Address of SenSor Fequ register
      SPI.transfer(SENSORFREQ);
    
      //SPI.transfer(0x04); Addressof LDC Config reg
      SPI.transfer(LDCCONFIG);
    
      //SPI.transfer(0x05); Address of clk reg
      SPI.transfer(CLKCONFIG);
    
      //SPI.transfer(0x0A);Address of interrupt cofig reg
      SPI.transfer(INTCONFIG);
    
      //SPI.transfer(0x06); Address of threshold reg lsb
      SPI.transfer(ThresHiLsb);
    
      //SPI.transfer(0x07); Address of threshold reg Msb
      SPI.transfer(ThresHiMsb);
    
      //SPI.transfer(0x08); Address of threshold reg lsb
      SPI.transfer(ThresLoLsb);
    
      //SPI.transfer(0x09); Address of threshold reg Msb
      SPI.transfer(ThresLoMsb);
     
      digitalWrite(CSB, HIGH);
    }
    
    void loop() 
    {
      unsigned int val, valu;
      byte READ = 128; // 0x80; // MSB = 1 which is a 'read' bit
      byte reg = 4; //0x04; // register address
       
      SPI.setBitOrder(MSBFIRST);
      SPI.setDataMode(SPI_MODE0); // CPOL = 0 and CPH = 0 mode 3 also works
      SPI.setClockDivider(SPI_CLOCK_DIV4); // set SCLK @ 4MHz, LDC1000 max is 4MHz DIV2 also works
      
      // begin data transfer  
      digitalWrite(CSB, LOW);
      delay(500);
      byte data_2_send = READ + reg;
      SPI.transfer(data_2_send);
      val = SPI.transfer(0xA1);
      valu = SPI.transfer(0xA2);
      
      // prints 8 bit decimal value between 0 and 255 found in desired register
      Serial.print(val);
      lcd.setCursor(0, 0);
      lcd.print("lsb:");
      lcd.print(val);
    
      Serial.print(' ');
    
      Serial.println(valu);
      lcd.setCursor(0, 1);
      lcd.print("msb:");
      lcd.print(valu);
      
      // end data transfer
      digitalWrite(CSB, HIGH);
        
      delay(500);
                     
    }
    
    
    
    
    
    
    /********************* Spi.h File ******************/
    /*
     * Copyright (c) 2010 by Cristian Maglie <c.maglie@bug.st>
     * SPI Master library for arduino.
     *
     * This file is free software; you can redistribute it and/or modify
     * it under the terms of either the GNU General Public License version 2
     * or the GNU Lesser General Public License version 2.1, both as
     * published by the Free Software Foundation.
     *
     * 2012-04-29 rick@kimballsoftware.com - added msp430 support.
     *
     */
    
    #ifndef _SPI_H_INCLUDED
    #define _SPI_H_INCLUDED
    
    #include <Energia.h>
    #include <inttypes.h>
    
    #if defined(__MSP430_HAS_USI__) || defined(__MSP430_HAS_USCI_B0__) || defined(__MSP430_HAS_USCI_B1__) || defined(__MSP430_HAS_USCI__) || defined(__MSP430_HAS_EUSCI_B0__)
    #include "utility/spi_430.h"
    #endif
    
    #define SPI_MODE0 0
    #define SPI_MODE1 1
    #define SPI_MODE2 2
    #define SPI_MODE3 4
    
    class SPIClass {
    public:
      inline static uint8_t transfer(uint8_t _data);
    
      // SPI Configuration methods
    
      static void begin(); // Default
      static void end();
    
      static void setBitOrder(uint8_t);
      static void setDataMode(uint8_t);
      static void setClockDivider(uint8_t);
    
      inline static void attachInterrupt();
      inline static void detachInterrupt();
    };
    
    extern SPIClass SPI;
    
    uint8_t SPIClass::transfer(uint8_t _data) {
        return spi_send(_data);
    }
    
    void SPIClass::attachInterrupt() {
        /* undocumented in Arduino 1.0 */
    }
    
    void SPIClass::detachInterrupt() {
        /* undocumented in Arduino 1.0 */
    }
    
    #endif
    
    
    
    
    
    
    
    
    /************************Spi.ccp File***********************/
    
    
    /*
     * Copyright (c) 2010 by Cristian Maglie <c.maglie@bug.st>
     * SPI Master library for arduino.
     *
     * This file is free software; you can redistribute it and/or modify
     * it under the terms of either the GNU General Public License version 2
     * or the GNU Lesser General Public License version 2.1, both as
     * published by the Free Software Foundation.
     *
     * 2012-04-29 rick@kimballsoftware.com - added msp430 support.
     *
     */
    
    #include <Energia.h>
    
    #include "SPI.h"
    
    SPIClass SPI;
    
    void SPIClass::begin()
    {
        spi_initialize();
    }
    
    void SPIClass::end()
    {
        spi_disable();
    }
    
    void SPIClass::setBitOrder(uint8_t bitOrder)
    {
        spi_set_bitorder(bitOrder);
    }
    
    void SPIClass::setDataMode(uint8_t mode)
    {
        spi_set_datamode(mode);
    }
    
    void SPIClass::setClockDivider(uint8_t rate)
    {
        spi_set_divisor(rate);
    }
    
    Hello natallia,

    I have attached the .txt file of my code. I am think that spi.h file is the problem i am checking with the spi clock pin output.

  • Hi,

    Can you read the device ID? If yes, SPI works.

    Best regards,

    Natallia

  • No i cant able to read any register default value. that's why i have doubt about spi.h file
  • Hello,

    Then it is most likely SPI. The firmware we released on ti.com doesnt have issues. Are you configuring the device when the device is in sleep mode?

    Best Regards,
    Natallia
  • Hello,

    Sleep mode means what your specifying PWR_MODE register of LDC1000 or some other register in MSP430. 

  • Hello Satheesh,

    Yes it is.

    Best Regards,

    Natallia Holubeva

  • I am having trouble finding the complete Arduino code that you mentioned. Is that code still available? Thank you.
  • Hallo Pelonomi,

    Thanks for sharing. But where can ik find the attached code and pdf documentation? (i am new here ;-)

    Best regards,

    Hami
  • Unfortunately, we do not have internally developed Arduino code and documentation. We do have MSP430 code for use with the LDC1000 which can work with the LDC1000EVM and MSP430 launchpads.

    Regards,

    ChrisO
  • Chris,

    Is there sample code for the LDC1000 for Energia?? I haven't found a single meaningful hit in google for this.
  • Hello Gabriel,
    unfortunately, Energia code for the LDC1000 is currently not available.
  • I have set up a repo, everything is there:

    Regards

  • I cannot find the uploaded pdf. I cannot find the "My Files" link/button on your profile.
  • As I have said in previous posts, TI forum architecture has since changed and you can find everything in the github repo. Link to which I have posted in a comment just before your comment.

    Have a look.

  • I am sorry, I missed it.

    Thank you, so much.

  • Hello Puru,
    were you able to access the files and find what you needed?
  • No problem
    Hope it helps
  • Where do I find the files mentioned here ?
  • Hi Pramod,

    which files are you looking for? Pelonomi's files are still available through the link in the post.

  • Hello Pelonomi Moiloa,

    I couldn't find the files u mentioned. Can u help me by giving regarding the pdf and code u mentioned.

    Thanks a lot
  • Hello Haris,
    I just clicked on the link that Pelonomi posted on Aug 27th 2015; the repository is still online and I was able to view the source code files.