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.

MPS430G2553 and LDC1000 interfacing

Other Parts Discussed in Thread: MSP430G2553, LDC1000EVM, MSP430F5528

Hi,

I'm having issues with interfacing LDC1000 and MSP430G2553 based PCB. I'm using 16Mhz clock on the MSP and when I load the preconfigured RPMIN and RPMAX values in my init function for e.g.

retVal &= spi_writeByte(NULL,LDC1000_CMD_RPMAX,       0x18);

I get TRUE as a return value. However if I change the RPMAX value and reload the program, sometimes the old RPMAX/RPMIN remains in the LDC1000. However I always get true from the spi_writeByte call. I'm thinking that this would relate to some kind of timing error because it does not happen all the time? Now I'm using 16Mhz clock and the examples are using 12Mhz, do I need to change some timing parameter in spi_1p1,h?

  • Hello Sami,

    According to the LDC1000 D/S, the external clock limitation for LDC1000 is 8MHz:

    Best Regards,

    Natallia Holubeva

  • Ok, I will test if that will solve the issue.
  • Sami,
    You can use f divider to reduce external oscillator frequency.

    Best Regards,
    Natallia Holubeva
  • Hello Sami,
    One additional consideration is that the maximum speed of the SPI (the SCLK frequency) is 4MHz. Ensure that you are not exceeding this spec.
    Regards,ChrisO
  • Here is my current clock configuration

    	// 12 Mhz
    	if (CALBC1_12MHZ == 0xFF) {				// If calibration constant erased
    		while (1);							// do not load, trap CPU!!
    	}
    
    	DCOCTL = 0;                             // Select lowest DCOx and MODx settings
    	BCSCTL1 = CALBC1_12MHZ;          		// Set range
    	DCOCTL = CALDCO_12MHZ;                  // Set DCO step + modulation
    	BCSCTL2 |= DIVS_1;						// SMCLK = MCLK / 2
    
    	FCTL2 = FWKEY + FSSEL0 + FN4;     		// Flash Timing Generator has to be between ~ 260 kHz - 480 kHz											
    							// Thus 6Mhz/16 = 375kHz

    If I change the values in evm_init() e.g. RPMIN/RPMAX I get true as a return value. When I query them right after the call with spi_readByte I get the original values. Sometimes the values are changed, sometimes not. Unless there is something wrong in my clock definition, perhaps my SPI is configured wrongly.

  • Now this is getting weirder and weirder. I have a Launchpad (Rev 1.5)  and LDC1000EVM which I have cut right after the LDC1000 part. So essentially I have the coil and the LDC1000 chip. When I attach the LDC1000 to Launchpad as per the instructions in http://www.ti.com/lit/an/snaa213/snaa213.pdf  and run the LDC1000_G2xx3_DRDY program, it works ok. But if I go to the evm_init function and change the RPMIN and RPMAX values, they are not changed in the LDC1000. It uses the previous values 0x3D and 0x13. Is there a bug in yours truly (likely) or is there a bug in the LDC1000/MSP430 library. I think this should be easily verifiable. I'm using Code Composer 6.0.1.00040. 

    #include <msp430.h>
    #include "LDC1000_evm.h"
    #include "LDC1000_cmd.h"
    #include "spi_1p1.h"
    
    #include "printf_lib.h"
    
    static uint8_t led = 0;
    
    uint16_t proxData;						// data to print
     uint16_t freqData;						// data to print
    
     uint8_t rpmin = 0;
     uint8_t rpmax = 0;
    
    int main(void)
    {
      uint8_t data[4];							// data buffer
    
      WDTCTL = WDTPW + WDTHOLD;                 // Stop Watchdog Timer
    
      // 12Mhz
      if (CALBC1_12MHZ==0xFF)					// If calibration constant erased
      {
        while(1);                               // do not load, trap CPU!!
      }
      DCOCTL = 0;                               // Select lowest DCOx and MODx settings
      BCSCTL1 = CALBC1_12MHZ;          			// Set range
      DCOCTL = CALBC1_12MHZ;                    // Set DCO step + modulation
      BCSCTL2 |= DIVS_1;						// SMCLK = MCLK / 2
    
      // initialize LDC1000 (default threshold function on EVM_INT)
      evm_init();								// Outputs SMCLK to LDCLK, Inits LDC1000
      spi_readByte(NULL,LDC1000_CMD_RPMIN, &rpmin);
      spi_readByte(NULL,LDC1000_CMD_RPMAX, &rpmax);
    
    
    
    
      while (1) {
    	  // read data
    	  spi_readBytes(NULL, LDC1000_CMD_PROXLSB, data, sizeof(data));
    	  proxData = data[0] | (data[1] << 8);			// buffer proximity data
    	  freqData = data[2] | (data[3] << 8);			// buffer frequency counter data
      }
    }
    
    
    /** Initialization */
    uint8_t evm_init() {
    
    	uint8_t retVal = TRUE;
    
    	EVM_LDCLK_DIR |= EVM_LDCLK_BIT;   // LDC CLK for Freq counter (set to output selected clock)
    	EVM_LDCLK_SEL |= EVM_LDCLK_BIT;   // LDC CLK for freq counter (set to output selected clock)
    
    	// LEDs
    	EVM_GRN_LEDDIR |= EVM_GRN_LEDBIT;
    	EVM_RED_LEDDIR |= EVM_RED_LEDBIT;
    
    	// initialize SPI
    	retVal &= spi_cs_setup(&evm_cs_pins[0],EVM_CS_TOTAL); // setup cs pins
    	retVal &= spi_cs_setDefault(evm_cs_pins[0]); // set default CS pin
    	spi_setup();
    
    	
    	uint8_t rpval = 0;
    	retVal &= spi_writeByte(NULL,LDC1000_CMD_RPMAX,       0x18); 
    	spi_readByte(NULL,LDC1000_CMD_RPMAX, &rpval);
    	retVal &= spi_writeByte(NULL,LDC1000_CMD_RPMIN,       0x39);
    	spi_readByte(NULL,LDC1000_CMD_RPMIN, &rpval);
    	
    	
    	retVal &= spi_writeByte(NULL,LDC1000_CMD_SENSORFREQ,  0x94);
    	retVal &= spi_writeByte(NULL,LDC1000_CMD_LDCCONFIG,   0x17);
    	retVal &= spi_writeByte(NULL,LDC1000_CMD_CLKCONFIG,   0x00);
    	retVal &= spi_writeByte(NULL,LDC1000_CMD_INTCONFIG,   0x02);
    
    	retVal &= spi_writeByte(NULL,LDC1000_CMD_THRESHILSB,  0x50);
    	retVal &= spi_writeByte(NULL,LDC1000_CMD_THRESHIMSB,  0x14);
    	retVal &= spi_writeByte(NULL,LDC1000_CMD_THRESLOLSB,  0xC0);
    	retVal &= spi_writeByte(NULL,LDC1000_CMD_THRESLOMSB,  0x12);
    
    	retVal &= spi_writeByte(NULL,LDC1000_CMD_PWRCONFIG,   0x01);
    
    
    	return retVal;
    }

  • I'm getting SPI Overrun Error in each of the spi_writeByte call in evm_init().
  • Hello Sami,

    I see that you found the problem. Please note that MSP430 sample code is available on our website. No bugs were reported, so you can use it as an example.

    Best Regards,
    Natallia Holubeva
  • Well, unfortunately I did not find the problem. I'm using the sample code and it is giving me the error in the spi_writeByte call. So either there is an bug in the MSP430/LDC1000 sample code or I have an some subtle issue here. The spi_writeByte is provided in the sample code.
  • Hello Sami,
    I checked the sample code and nothing like you describe is detected. Please, try checking it again.

    Best Regards,
    Natallia Holubeva
  • Did you test it with Launchpad Rev 1.5? I'm really baffled because I'm getting the same response with this code with our own PCB as well as with the Launchpad. This is most likely error related to DCO. I tried setting the DCO to 1MHz and using without the prescaler but still I get the same. I noticed following thread where similar issues are discussed:
    http://e2e.ti.com/support/microcontrollers/msp430/f/166/t/239057#pi239031349filter=all&pi239031349scroll=false
  • David,

    We tested it with our EVM and MSP430F5528. Please, post code/microcontroller questions to the following forum: http://e2e.ti.com/support/microcontrollers/msp430/

    Please, let me know if you have any questions on LDC technology.
    Best Regards,
    Natallia Holubeva
    Analog Applications
  • Hello Sami,
    I'm sure you already know this, but the LDC1000 should be configured while in sleep (standby) mode - the Power Config (address 0x0B) should be set to 0x00, then change the RPMIN & RPMAX values.
    Regards,Chris O
  • I have just isolated the problem and quite frankly I am quite baffled. I'm using the LDC1000 interface library and its spi-commands. Again if I LDC1000 like following

    spi_writeByte(NULL,LDC1000_CMD_RPMAX, TEST_RPMAX_INIT);

    I get a OVERRUN_ERROR from the SPI. Now when I go into the LDC1000 library the code uses following spi_exec-function. If I put a breakpoint to last line in the SPI_TXRDY() function, the SPI write works and I don't get OVERRUN_ERROR. I don't understand this, does the breakpoint slow the program behaviour? Changing the SPI_TIMEOUT_IN_CYCLES does not have any effect.

    Now I don't know if this question should be in the MSP430 forum, but I'm using the code that comes with LDC1000. 

    static uint8_t spi_exec(SPI_1P1_CS_Pin * cs) {
    	cs_active = (cs == NULL) ? cs_default : cs;
    	if (cs_active == NULL) return FALSE;
    	done = FALSE;
    	(cs_active->select)();
    	SPI_TXRDY();
    	SPI_TXBUF = txaddr;
    
    	while (txlen > 0) {
    
    		SPI_TXRDY();			// PROBLEM IN HERE
    		SPI_TXBUF = * txbuf;
    		txbuf++;
    		txlen--;
    	}
    	while (rxlen > 0) {
    		SPI_TXRDY();
    		SPI_TXBUF = 0;
    		SPI_IDLE();
    		* rxbuf = SPI_RXBUF;
    		rxbuf++;
    		rxlen--;
    	}
    	SPI_IDLE();
    	(cs_active->deselect)();
    	done = TRUE;
    	return TRUE;
    }
    
    uint8_t SPI_TXRDY() {
    	do {
    		ctr = 0;
    		while (!SPI_TXBUF_EMPTY) {
    			if (ctr++ >= SPI_TIMEOUT_IN_CYCLES) {
    				(cs_active->deselect)();
    				done = TRUE;
    				return FALSE;
    			}
    		}
    	}while (0);
    	return TRUE;			// IF BREAKPOINT IN HERE EVERYTHING WORKS!!
    }
    
    /* SPI_IDLE() wait buffer is idle */
    uint8_t  SPI_IDLE() {
    	do {
    		ctr = 0;
    		while (SPI_BUSY) {
    			if (ctr++ >= SPI_TIMEOUT_IN_CYCLES) {
    				(cs_active->deselect)();
    				done = TRUE;
    				return FALSE;
    			}
    		}
    	}while (0);
    	return TRUE;
    }

  • Hi Everyone, Even I am getting same Problem with the example code. I am using MSP430G2553. I have made my coil and connected with evaluation board and identified my RP_MAX and RP_Min values for 0 and 32768. If I programmed same values in evm_init() function of sample code It didn't change.

    Any help is appreciated.

    Thanks,
    Naveen
  • Check that you remember to put the LDC1000 into a sleep mode before you start writing values into it. I also noticed that sometimes you have to write the values twice before LDC1000 is correctly initialized. You can check that the values are written correctly into LDC1000 by reading the register values before going into the main loop. 

  • Thanks Chris. I got it done.

    Cheers,
    Naveen
  • Thanks Man. I got it.

    Naveen
  • Hello Naveen,

    Did writing to the microcontroller in sleep mode solve your problem?

    Best Regards,

    Natallia Holubeva

  • Naveen,

    Thank you.

    Best Regards,
    Natallia Holubeva
  • Hallo Sami,
    Could your problem be due to a wrong connection between MSP430 MISO/MOSI and LDC1000 SDI/SDO perhaps?
    In the example code it is rather unclear which is which, i-m-o.

    in the scheme on the top of main.c :
    ...
    // | P1.6/USCIB0SOMI|<--EVM_SDO
    // | P1.7/USCIB0SIMO|-->EVM_SDI
    ...

    but in spi_1p1h these pins are defined as follows:
    /* SDO */
    #define SPI_MOSI_BIT BIT6 /**< Bit */
    ...
    /* SDI */
    #define SPI_MISO_BIT BIT7 /**< Bit */

    Could perhaps Natallia clarify this issue?
    Best regards
    Enrico
  • Hello Enrico,

    Configuring the device in sleep mode was the solution. Thank you for your help.

    Best Regards,
    Natallia Holubeva