Hi,目前使用TI开发板的蓝牙芯片调试硬件I2C没有信号输出,一直没找到原因。
– 使用LAUNCHXL-CC2640R2开发板通过I2C和一个从设备通信;
– 使用STM32通过I2C和从设备读写正常,说明从设备本身没有问题;
– 使用i2ctmp007中的例程和从设备进行I2C通信正常;
问题出在将i2ctmp007中的代码迁移至SDK中的simple_peripheral例程后,始终看不到
I2C信号输出,可能是simple_peripheral例程中少添加或修改了部分代码,但我不知道少了什么。
我的步骤如下:
1. 向SDK中simple_peripheral例程drivers目录下添加i2c.c和i2c.h文件,并在main.c中添加
#include <ti/drivers/I2C.h>
#include "Board.h"
2. Board.h中定义
#define Board_I2C0 CC2640R2_LAUNCHXL_I2C0
#define Board_I2C_TMP Board_I2C0
3. CC2640R2_LAUNCHXL.h中定义管脚
#define CC2640R2_LAUNCHXL_I2C0_SCL0IOID_5 #define CC2640R2_LAUNCHXL_I2C0_SDA0IOID_15
typedef enum CC2640R2_LAUNCHXL_I2CName {CC2640R2_LAUNCHXL_I2C0 = 0,CC2640R2_LAUNCHXL_I2CCOUNT } CC2640R2_LAUNCHXL_I2CName;
4. CC2640R2_LAUNCHXL.C中添加有关I2C的部分
/* * =============================== I2C =============================== */ #include <ti/drivers/I2C.h> #include <ti/drivers/i2c/I2CCC26XX.h> I2CCC26XX_Object i2cCC26xxObjects[CC2640R2_LAUNCHXL_I2CCOUNT]; const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[CC2640R2_LAUNCHXL_I2CCOUNT] = {{.baseAddr= I2C0_BASE,.powerMngrId = PowerCC26XX_PERIPH_I2C0,.intNum= INT_I2C_IRQ,.intPriority = ~0,.swiPriority = 0,.sdaPin= CC2640R2_LAUNCHXL_I2C0_SDA0,.sclPin= CC2640R2_LAUNCHXL_I2C0_SCL0,} }; const I2C_Config I2C_config[CC2640R2_LAUNCHXL_I2CCOUNT] = {{.fxnTablePtr = &I2CCC26XX_fxnTable,.object= &i2cCC26xxObjects[CC2640R2_LAUNCHXL_I2C0],.hwAttrs= &i2cCC26xxHWAttrs[CC2640R2_LAUNCHXL_I2C0]}, }; const uint_least8_t I2C_count = CC2640R2_LAUNCHXL_I2CCOUNT;
5. main.c中添加定义
#define TASKSTACKSIZE640 #define TEST_ADDR0x1A #define MODULE_TEST_TEMP10x0001 /* Die Temp Result Register */ #define MODULE_TEST_TEMP20x0003 /* Object Temp Result Register */ #ifndef Board_TEST_ADDR #define Board_TEST_ADDRTEST_ADDR #endif
main.c中主函数中
/* Register Application callback to trap asserts raised in the Stack */RegisterAssertCback(AssertHandler);PIN_init(BoardGpioInitTable);uint8_ttxBuffer[1]={0x66};uint8_trxBuffer[10];I2C_Handlei2c;I2C_Paramsi2cParams;I2C_Transaction i2cTransaction;I2C_init();/* Create I2C for usage */I2C_Params_init(&i2cParams);i2cParams.bitRate = I2C_400kHz;i2c = I2C_open(Board_I2C_TMP, &i2cParams);/* Point to the T ambient register and read its 2 bytes *///txBuffer[0] = TMP007_OBJ_TEMP;i2cTransaction.slaveAddress = (Board_TEST_ADDR>>1);i2cTransaction.writeBuf = txBuffer;i2cTransaction.writeCount = 1;i2cTransaction.readBuf = NULL;i2cTransaction.readCount = 0;while(1){I2C_transfer(i2c, &i2cTransaction);}
请问哪里有不对的地方吗?
da qin zheng sheng:
有没有打开低功耗啊?
linch kong:
回复 da qin zheng sheng:
没有
YiKai Chen:
有沒有先檢查一下I2C_open回傳的handle i2c是不是null
linch kong:
回复 YiKai Chen:
查看了下,I2C_open返回值为NULL,没有打开,正常情况下返回值不是NULL,不知道什么东西没有考虑到?
Viki Shi:
参考下这边的帖子,下面有在simple_peripheral中融合i2ctmp007例程的单步指导:
e2e.ti.com/…/2543887