主题中讨论的其他器件:OPT3001
工具/软件:Code Composer Studio
您好!
我有一个传感器 BoosterPack、我正在使用 opt3001传感器测量配体、我编写了此代码并将 OPT_INT 引脚连接到 DIO12。
我想配置下一次中断:当配体为低电平时、我想打开 LED1;当配体过高时、我想关闭 LED1。
我已经查看了"引脚中断"示例、但我不知道如何执行我之前所解释的操作。
以下是代码:
#define TMP007_ADDR 0x47; 静态 Display_Handle 显示; void gpioButtonFxn0 (uint_least8_t index) { /*清除 GPIO 中断并切换 LED */ GPIO_TOGGLE (Board_GPIO_LED1); display_printf (display、0、0、"INT."); } /* ===== mainThread ==== // void * mainThread (void * arg0) { uint16_t 样本; uint16_t LUX_RAW; uint16_t e、m; float 勒克斯; uint8_t txBuffer[3]; 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); GPIO_setConfig (Board_GPIO_LED1、GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW); GPIO_setConfig (Board_DIO12、GPIO_CFG_INPUT| GPIO_CFG_IN_INT_INT_FALLING); /*安装引脚 DIO12回调*/ GPIO_setCallback (Board_DIO12、gpioButtonFxn0); GPIO_enableInt (Board_DIO12); /*打开主机显示屏以输出*/ 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、"启动 i2ctmp 示例。"); /*创建 I2C 以供使用*/ 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); } 否则{ display_printf (display、0、0、"I2C initialized!\n"\}); } /*通用 I2C 事务设置*/ i2cTransaction.writeBuf = txBuffer; i2cTransaction.writeCount = 3; i2cTransaction.readBuf = rxBuffer; i2cTransaction.ReadCount = 2; TxBuffer[0]= 0x0001; TxBuffer[1]= 0xce; TxBuffer[2]= 0x10; i2cTransaction.slaveAddress = TMP007_ADDR; if (!I2C_transfer (i2c、&i2cTransaction)){ Display_printf (display、0、0、"错误。 未找到 TMP 传感器!"); while (1); } TxBuffer[0]= 0x0002; TxBuffer[1]= 0x02; txBuffer[2]= 0xff; i2cTransaction.slaveAddress = TMP007_ADDR; if (!I2C_transfer (i2c、&i2cTransaction)){ Display_printf (display、0、0、"错误。 未找到 TMP 传感器!"); while (1); } TxBuffer[0]= 0x0003; TxBuffer[1]= 0x8a; TxBuffer[2]= 0xAA; i2cTransaction.slaveAddress = TMP007_ADDR; if (!I2C_transfer (i2c、&i2cTransaction)){ Display_printf (display、0、0、"错误。 未找到 TMP 传感器!"); while (1); } i2cTransaction.writeBuf = txBuffer; i2cTransaction.writeCount = 1; i2cTransaction.readBuf = rxBuffer; i2cTransaction.ReadCount = 2; TxBuffer[0]= 0x0000; /*采集20个样本并将其打印到控制台*/ 对于(sample = 0;sample < 50;sample++){ if (I2C_transfer (i2c、&i2cTransaction)){ Lux_RAW =(rxBuffer[0]<< 8)|(rxBuffer[1]); M = lux_raw 和0x0FFF; E =(lux_raw & 0xF000)>> 12; Lux = m *(0.01 * pow (2、e)); Display_printf (display、0、0、"Sample %u:%f %x %x"、 SAMPLE+1、lux、rxBuffer[0]、rxBuffer[1]); } 否则{ display_printf (display、0、0、"I2C 总线故障"); } /*睡眠1秒*/ 睡眠(1); } I2C_Close (i2c); display_printf (display、0、0、"I2C closed!"); 返回(NULL); }