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.

RTOS/LAUNCHXL-CC2640R2: Read data from sensor LIS3DH

Part Number: LAUNCHXL-CC2640R2

Tool/software: TI-RTOS

Hello,

I have seen several responses to people using the 'i2ctmp007' project as a base. I am currently struggling to get a ST-Micro LIS3DH accelerometer to connect to my LaunchXL-CC2640R2 board. Before I post my code I have a few basic questions:

1 - I haven't seen anywhere how to configure the device registers, i.e., even for the original 'i2ctmp007' project/code, for the TMP007 sensor I didn't see any code to set-up the device. Is it just assumed that the defaults will suffice, or, are these, i.e., registers being set somewhere else ? Even if the registers are being set somewhere else, what is the correct method ? For transmit, I send, of course, the board address as part of the ' i2cTransaction.slaveAddress'. Then, I put the device register I'm trying to set-up in one buffer location, and the value to write to the register in a second buffer location. For 'reads', I just send the 'slaveAddress', then the register to be read from in a buffer location. For transmit, I have tried to implement two 'empty' loops to send these values to the registers. I am getting the 'I2C Initialized' message. I also get the "I2C closed!\n" message (not shown in the code below). However, none of the code related to the accel/registers seems to be doing anything.

Need help, please.

Thanks,

J.

My modifications to the 'i2ctmp007' code follows (not including the various new 'defines', ....)

   uint8_t         txBuffer[10];

   uint8_t         rxBuffer[10];

    uint8_t         Accel_X;

 

   I2C_Handle     i2c;

   I2C_Params     i2cParams;

   I2C_Transaction i2cTransaction;

 

   /* Call driver init functions */

   Display_init();

   GPIO_init();

   I2C_init();

 

   /* Open the HOST display for output */

   display = Display_open(Display_Type_UART, NULL);

   if (display == NULL) {

       while (1);

   }

 

   /* Turn on user LED */

   GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);

   Display_printf(display, 0, 0, "Starting the i2ctmp007 example\n");

 

   /* Create I2C for usage */

   I2C_Params_init(&i2cParams);

   i2cParams.bitRate = I2C_400kHz;

   i2c = I2C_open(Board_I2C_TMP, &i2cParams);

   if (i2c == NULL) {

       Display_printf(display, 0, 0, "Error Initializing I2C\n");

       while (1);

   }

   else {

       Display_printf(display, 0, 0, "I2C Initialized!\n");

   }

//------------------ ALL OF THE ABOVE WORKS !!!!! -----------------------

 

//=======================================================================

//----- Init the LIS3DH Accel

 

   // Init CNTRL_REG0....

   txBuffer[0] = CTRL_REG0;/* CTRL_REG0 Address 0x1E */

   txBuffer[1] = 0x10; /* Value to write to 'CNTRL_REG0', i.e., Enable the LIS3DH */

   txBuffer[2] = 0x00; /* Do not auto-increment register address */

 

   i2cTransaction.slaveAddress = Board_TMP_ADDR; // 0x18

   i2cTransaction.writeBuf = txBuffer;

   i2cTransaction.writeCount = 3;

   i2cTransaction.readBuf = rxBuffer;

   i2cTransaction.readCount = 0;

 

   if (I2C_transfer(i2c, &i2cTransaction)) {

        }

 

   // Init CNTRL_REG1....

     txBuffer[0] = CTRL_REG1;

     txBuffer[1] = 0x27;

     txBuffer[2] = 0x00; /* Do not auto-increment register address */

 

     i2cTransaction.slaveAddress = Board_TMP_ADDR; //0x18

     i2cTransaction.writeBuf = txBuffer;

     i2cTransaction.writeCount = 3;

     i2cTransaction.readBuf = rxBuffer;

     i2cTransaction.readCount = 0;

 

     if (I2C_transfer(i2c, &i2cTransaction)) {

          }

 

/* NOTE: May have to initialize other CTRL registers */

 

   //====================================================================

       // Set-up ADC read

       txBuffer[0] = OUT_X_L;   // Output register for the X-axis lower byte, JUST TO TRY

       i2cTransaction.slaveAddress = Board_TMP_ADDR; //0x18

       i2cTransaction.writeBuf = txBuffer;

       i2cTransaction.writeCount = 1;

       i2cTransaction.readBuf = rxBuffer;

       i2cTransaction.readCount = 1;

 

       i = 1; // just to temporarily make the next lines happy (have removed loop)

 

         if (I2C_transfer(i2c, &i2cTransaction)) {

          

             Accel_X = rxBuffer[0];

 

             Display_printf(display, 0, 0, "Getting Accel Data !\n");

             Display_printf(display, 0, 0, "Sample %u: %d (C)\n", i, Accel_X);

          }

 //==================================================================================

  • Maybe you can try to refer to MPU9250 I2C implementation in SensorTag example of BLE Stack 2.2.2.
  • Hi James,

    See, my reply from your other post.


    -kel

  • Hey,YiKai Chen,
    I appreciate your response, and the responses from several other members of the community, i.e., 'Kel. I stared at 'my' code, i.e., the modified code based on the i2ctmp007 example. I just couldn't see anything incorrect - except for maybe that LSB bit-shift issue. i.e, 0x18 vs. 0x30 (turned out to be 0x18 for me. I noticed that 'Kel used 0x19 - depends on how you wire up the LIS3DH). I looked at several of the examples that were referenced. Most of them did *not* use the RTOS I2C API, but they all had a similar theme for writing to registers of the slave device, i.e., send the slave address, then the desired register address, then the contents to read/write. In some cases, also send the number of bytes to be read/written. Basically, my modified program had all of those elements, though I will be investigating the seemingly 'empty' loop that I use to select and configure registers using the I2CTransfer { } command. So with that said, I confess that in the end it was too many late nights, red eyes, and poor eye-sight. I had inadvertently connected the lead from the accel GND to the 5VDC pin which is adjacent to GND. Again, I thank you all, as after I finally came to the conclusion that there should be no reason why the code shouldn't run, based on all of your input, I went looking for the only other culprit I could think of - the hardware/wiring.
    Regards,
    J.

    Results from the initial working test trial:

    Starting the i2ctmp007 example
    I2C Initialized!
    Getting Accel Data !
    Sample 1: 0 (G's)
    I2C closed!