Other Parts Discussed in Thread: CC1310
Hi TI,
I am currently working on cc1310 launchpad for vl53l1x sensor i tried to interface vl53l1x c files but i can't
can you give me any idea to interface api files to our hardware.
Regards,
hari.
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.
Hi TI,
I am currently working on cc1310 launchpad for vl53l1x sensor i tried to interface vl53l1x c files but i can't
can you give me any idea to interface api files to our hardware.
Regards,
hari.
Hi Hari,
I see that the vl53l1x uses the i2c interface.
You can use the i2ctmp example as a reference, where we use a TI temperature sensor and the i2c driver to setup and communicate with the sensor.
You would have to read ST's documentation and tutorials on what the sensor expects and supply the appropriate commands over the i2c interface.
Regards,
Sid
/*
* Copyright (c) 2018-2019, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ======== i2ctmp116.c ========
*/
#include <stdint.h>
#include <stddef.h>
#include <unistd.h>
/* Driver Header files */
#include "Board.h"
#include <ti/drivers/I2C.h>
#include <ti/display/Display.h>
/* Example/Board Header files */
#include <ti/drivers/GPIO.h>
#define TASKSTACKSIZE 640
/*
* ======== TMP Registers ========
*/
#define TMP006_REG 0x0001 /* Die Temp Result Register for TMP006 */
#define TMP116_REG 0x0000 /* Die Temp Result Register for TMP116 */
#define TMP006_ADDR 0x52;
#define TMP116_BP_ADDR 0x48;
#define TMP116_LP_ADDR 0x29;
static Display_Handle display;
/*
* ======== mainThread ========
*/
void gpioButtonFxn0(uint_least8_t index)
{
/* Clear the GPIO interrupt and toggle an LED */
//GPIO_toggle(Board_GPIO_LED0);
}
void *mainThread(void *arg0)
{
//uint16_t sample;
uint16_t distance;
uint8_t txBuffer[1];
uint8_t rxBuffer[1];
I2C_Handle i2c;
I2C_Params i2cParams;
I2C_Transaction i2cTransaction;
/* Call driver init functions */
Display_init();
GPIO_init();
I2C_init();
/* Configure the LED and if applicable, the TMP116_EN pin */
GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
//#ifdef Board_GPIO_TMP116_EN
// GPIO_setConfig(Board_GPIO_TMP116_EN, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH);
/* 1.5 ms reset time for the TMP116 */
// sleep(1);
//#endif
GPIO_setCallback(Board_GPIO_BUTTON0, gpioButtonFxn0);
/* 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 i2ctmp example.");
/* Create I2C for usage */
// GPIO_enableInt(Board_GPIO_BUTTON0);
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_100kHz;
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");
}
/* Common I2C transaction setup */
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 1;
/*
* Determine which I2C sensor is present.
* We will prefer sensors in this order: TMP116 (on BoosterPacks),
* TMP116 (on-board CC32XX LaunchPads), and last TMP006
* (on older CC32XX LaunchPads).
*/
/* Try TMP116 values */
txBuffer[0] = TMP116_REG;
i2cTransaction.slaveAddress = TMP116_BP_ADDR;
if (!I2C_transfer(i2c, &i2cTransaction)) {
/* Not BP TMP116, try LP TMP116 */
i2cTransaction.slaveAddress = TMP116_LP_ADDR;
if (!I2C_transfer(i2c, &i2cTransaction)) {
/* Not a TMP116 try TMP006*/
txBuffer[0] = TMP006_REG;
i2cTransaction.slaveAddress = TMP006_ADDR;
if (!I2C_transfer(i2c, &i2cTransaction)) {
/* Could not resolve a sensor, error */
Display_printf(display, 0, 0, "Error. No TMP sensor found!");
while(1);
}
}
}
/* Print which TMP is in use */
if (TMP116_REG == txBuffer[0]) {
Display_printf(display, 0, 0, "Detected TMP116 sensor.");
}
else {
Display_printf(display, 0, 0, "Detected TMP006 sensor.");
}
/* Take 20 samples and print them out onto the console */
while(1) {
if (I2C_transfer(i2c, &i2cTransaction)) {
// I2C_init();
/*
* Extract degrees C from the received data;
* see TMP116/006 datasheet
*/
distance =rxBuffer[0];
// temperature *= 0.0078125;
/*
* If the MSB is set '1', then we have a 2's complement
* negative value which needs to be sign extended
*/
// if (rxBuffer[0] & 0x80) {
// temperature |= 0xF000;
// }
Display_printf(display, 0, 0, "DISTACE "
": %d (mm)",
distance);
}
else {
Display_printf(display, 0, 0, "I2C Bus fault.");
}
GPIO_disableInt(Board_GPIO_BUTTON1);
/* Sleep for 1 second */
// sleep(1);
sleep(1
);
}
I2C_close(i2c);
Display_printf(display, 0, 0, "I2C closed!");
// sleep(.1);
// }
return (NULL);
}
I attached my code i2c is working , tested through CRO but its reading correct data.
How to clear is error.
Hi Hari,
We can provide you some direction.
You need to look at the source code of these APIs, and rewrite it yourself for our platform.
You would have to at least replace the i2c calls in these functions with the TI's i2c driver calls.
We could help you if you have specific issues with the TI's i2c driver itself, but we cannot support you with implementing these APIs.
Regards,
Sid