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.

cc2650 interfacing with I2C accelerometer (LIS2DH from ST)

Other Parts Discussed in Thread: CC2650, CC2650STK

Hi,

I am having CC2650 5XD package and a smartRF06 EVB.  I am trying to interface LIS2DH,accelerometer from ST Micro with CC2650.  I wrote code with sensortag code as reference, doxygen for I2C in tirtos folder, bsp_i2c.c and bsp_i2c.h. 

I have skimmed through technical reference manual for cc26xx, SW developers User guide, from which I found the PRCM module should have clock for I2C.

I am trying to configure DIO_2 as  I2C0_SDA and DIO_3 as I2C0_SCL.  the interface being used is CC2650_I2C0. I tried changing the mux value using 

/* Set IO muxing for the UART pins */
PINCC26XX_setMux(hPin, Board_I2C0_SDA0, IOC_PORT_MCU_I2C_MSSDA);
PINCC26XX_setMux(hPin, Board_I2C0_SCL0, IOC_PORT_MCU_I2C_MSSCL);

All the registers in I2C0   is null even after using I2c_open(), bsp_i2c_select() and i2cCC26XX_open() etc. and the code goes to some random location. 

  • If  I2c_Handle is null, will the code never come back to the next line of execution? I believe that handle is not getting opened, as all regsiters are still null. 
  • Is it ok to initialize SDA and SCL pins in the boardgpioinittable() and initialize it using PIN_init()?
  • Is there any sample code available?

  • Hello,

    Since you are using 5x5, did you switch (and confirm) that you are using the 5XD board file in your project? Did you grep the code to see if there are any other calls to setMux?

    Best wishes
  • Hi,

    When I select  a GPIO pin and give go to definition of the pin, it goes to the board.h of 5XD which means the mapping is proper right??

    For switching to 5XD, i changed in the compiler->preprocessor-> C:\ti\tirtos_simplelink_2_13_00_06\packages\ti\boards\SRF06EB\CC2650EM_7ID

    to

    C:\ti\tirtos_simplelink_2_13_00_06\packages\ti\boards\SRF06EB\CC2650EM_5XD

    the setMux calls are there in library files i2c.c and i2ccc26xx.c

  • You can initialize the pins with PIN_init to set them up to a default value.
    If I2C_open returns NULL then you have typically run PIN_open on the I2C pins somewhere first and that pin handle will then "own" the pins so that the PIN_open call in the I2C driver fails.

    Regards,
    Svend
  • I am not invoking PIN_open() anywhere in the code? Any other change needed for switching the package from 7ID to 5XD??
  • Hi,

    I could open the i2c handle and the slave address is also getting set properly.  The only change when compared with the previous project version is

    • Reinstalled BLE stack 2.1 along with TI RTOS
    • The I2c.h, I2CCC26XX.h and .c files are not added to the project
    • Shouldn't the I2c .c and .h files be added? I have read that if we are not adding the library files, it will use the  existing compiled library files.
    • Now the issue is, I  am invoking i2c_transfer() in a while(1) in main(). While debugging, it hits i2c_transfer() and the control gets transferred to some location in disassembly  and never comes back. is there any other alternative to i2c_transfer() ? The code is in blocking mode as I am not changing the mode of operation in i2c_params.

    /* Point to the T ambient register and read its 2 bytes */
        txBuffer[0] = 0x0F;
        i2cTransaction.slaveAddress = Board_LIS2DH_ADDR;
        i2cTransaction.writeBuf = txBuffer;
        i2cTransaction.writeCount = 1;
        i2cTransaction.readBuf = rxBuffer;
        i2cTransaction.readCount = 2;

        while(1)
        {
         if(I2C_transfer(i2c, &i2cTransaction))
         {
            System_printf("I2C Bus read\n");
         }
         else
         {
            System_printf("I2C Bus fault\n");
              I2C_close(i2c);
         }
              
        }

  • The drivers often linked in using a prebuilt library (see linker settings). The prebuilt drivers are the same as in the corresponding TI RTOS release so you can add in the driver source manually if you would like to do that.

    You are calling a TI RTOS driver -before- TI RTOS have started it seems. If you look into the driver source you will see there are a lot of TI RTOS contructs in the driver which will not be avaiable until after BIOS_start() has been executed.

    :svend
  • Thanks svendbt.. Got I2C working...
  • Hi, 

    Can you explain me how did you manage to work I2C for accelerometer? I use CC2650STK (Sensor Tag), and it has 2 different I2C buses, one for accelerometer , gyro and magnet and the other for the rest of sensors. And i cannot set SDA1 and SCL1 on.

    On User_guide they it is written what is the order and how to set it, but i cannot make it with TI-RTOS. Any suggestions?

    Nat