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.

[参考译文] CCS/LAUNCHXL-CC1352R1:从传感器 BoosterPack 读取 OPT3001数据

Guru**** 2551110 points
Other Parts Discussed in Thread: CC1352R

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/832101/ccs-launchxl-cc1352r1-read-opt3001-data-from-sensors-boosterpack

器件型号:LAUNCHXL-CC1352R1
主题中讨论的其他器件:CC1352R

工具/软件:Code Composer Studio

您好!

我有这个代码、我想知道如何读取数据并将其转换为可读的数据。 代码来自 i2ctmp 示例、但我已更改传感器地址。

我使用的是带传感器 BoosterPack 的 CC1352R 板。

#define TASKSTACKSIZE 640

/*
===== tmp 寄存器======
*/

#define OPT_ADDR 0x47;

#ifndef Board_TMP_ADDR
#define Board_TMP_ADDR TMP007_ADDR
#endif

static Display_Handle 显示;

/*
=== mainThread ====
//
void * mainThread (void * arg0)
{
uint16_t 样本;
uint16_t 勒克斯;
uint8_t txBuffer[1];
uint8_t rxBuffer[2];
I2C_Handle I2C;
I2C_Params i2cParams;
I2C_Transaction i2cTransaction;

/*调用驱动程序初始化函数*/
display_init();
GPIO_init();
I2C_init();

/*配置 LED 以及 TMP116_EN 引脚(如果适用)*/
GPIO_setConfig (Board_GPIO_LED0、GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);


/*打开主机显示屏以输出*/
Display = Display_open (Display_Type_UART、NULL);
if (display =NULL){
while (1);
}

/*打开用户 LED */
GPIO_WRITE (Board_GPIO_LED0、Board_GPIO_LED_ON);
display_printf (display、0、0、"启动 opt 示例。");

/*创建 I2C 以供使用*/
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);
}
否则{
display_printf (display、0、0、"I2C initialized!\n"\});
}

/*通用 I2C 事务设置*/
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.ReadCount = 2;

TxBuffer[0]= 0x0003;
i2cTransaction.slaveAddress = opt_ADDR;
if (!I2C_transfer (i2c、&i2cTransaction)){
Display_printf (display、0、0、"错误。 未找到 OPT 传感器!");
while (1);
}

/*采集20个样本并将其打印到控制台*/
对于(sample = 0;sample < 20;sample++){
if (I2C_transfer (i2c、&i2cTransaction)){

/*
*从接收到的数据中提取 lux;
*
*

Display_printf (display、0、0、"Sample %u:%d (C)"、
sample + 1、lux);
}
否则{
display_printf (display、0、0、"I2C 总线故障");
}

/*睡眠1秒*/
睡眠(1);
}

I2C_Close (i2c);
display_printf (display、0、0、"I2C closed!");

返回(NULL);
}