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.
工具/软件:Code Composer Studio
你(们)好。
我尝试将mpu6050与cc2640 launchpad配合使用。
我使用tidriver示例i2ctmp007启动了i2c,并尝试稍微编辑该示例。
这是代码的一部分
/*打开用户LED */
GPIO写入(Board_GPIO _LED0,Board_GPIO _LED_ON);
printf ("正在启动i2ctmp007示例\n");
/*创建I2C以供使用*/
I2C_Params_init (&i2cParams);
i2cParams.bitrate = I2C_400kHz;
I2C = I2C_OPEN (Board_I2C_TMP,&i2cParams);
如果(i2c ==空){
printf ("Error Initializing I2c\n");
同时(1);
}
否则{
printf ("I2C已初始化!\n");
printf ("开始吧!");
}
我用printf来检查哪里发生了错误,而且发生了奇怪的事情。
控制台打印"I2C initialized!" 但不要"让我们开始吧!"。
我不知道问题是什么。
有人知道吗?
谢谢!
I2C_TRANSFORT() 函数可能尚未返回。现在它打印"我在循环中!",但它既不打印"什么?" 也不是"I2C总线故障"。
i2cTransaction变量是否在第一次调用 I2C_TRANSFORT(i2c,&i2cTransaction)之前初始化?
现在它打印"我在循环中!",但它既不打印"什么?" 也不是"I2C总线故障"。[/QUOT]
您是否可以在这些printf语句上执行单步操作,而看不到C I/O输出?
实际上,这是第一次使用CCS (甚至使用ARM),所以我不熟悉调试器。
您是否有链接,我可以获取相关信息?
如果它能提供帮助,下面是完整的代码。
mpu6050的地址是0x68,我正在尝试使用0注册0x6B。
打印
"正在启动i2ctmp007示例"
"I2C已初始化!"
"让我们开始吧!"
"乐高"
衷心感谢您的关注。
/* ========= i2ctmp007.c ========= */ #include <stdint.h> #include <stddef.h> #include <stdio.h> #include <ti/drivers/GPIC.h> #include <ti/drivers/I2c.h>/* example/Board Header files */ #include "Board.h" #define TASKSTACKSIZE 640 /* ========= mainThread ========= */ void *mainThread (void *arg0) { 无符号int I; UINT16_t 温度; UINT8_t txBuffer[1]; UINT8_t rxBuffer[2]; I2C_HANDLE I2C; I2C_Params i2c参数; I2C_Transaction i2cTransaction; /*调用驱动程序初始化函数*/ GPIO初始化(); I2C_INIT(); /*打开用户LED */ GPIO写入(Board_GPIO _LED0,Board_GPIO _LED_ON); printf ("正在启动i2ctmp007示例\n"); /*创建I2C以供使用*/ I2C_Params_init (&i2cParams); i2cParams.bitrate = I2C_400kHz; I2C = I2C_OPEN (Board_I2C_TMP,&i2cParams); 如果(i2c ==空){ printf ("Error Initializing I2c\n"); 同时(1);} 否则{ printf ("I2C已初始化!\n"); printf("Let's go!\n"); } printf ("leggo"); // setup mpu6050 UINT8_t SetupBuffer[2]; SetupBuffer[0]= 0x6b; SetupBuffer[1]=0; i2cTransaction.slaveAddress = 0x68; i2cTransaction.writeBuf = setupBuffer; i2cTransaction.writeCount = 2; i2cTransaction.readBuf = NULL; i2cTransaction.ReadCount = 0; I2C_TRANSFER (i2c,&i2cTransaction); printf ("设置完成!\n"); /*采集20个样本并将其打印到控制台上*/ 对于(i = 0;i < 20;I++){ printf ("我在循环中!\n"); txBuffer[0]= 0x3B; i2cTransaction.slaveAddress = 0x68; i2cTransaction.writeBuf = txBuffer; i2cTransaction.writeCount = 1; i2cTransaction.readBuf = rxBuffer; i2cTransaction.ReadCount = 2; IF (I2C_TRANSFER (i2c,&i2cTransaction)){ 温度=(rxBuffer[0]<< 8)|(rxBuffer[1]); 温度/= 1000; printf (“样本%u:%d (C)\n",i,温度); } 否则{ printf("I2C总线故障\n");} /*睡眠1秒*/ 睡眠(1);} /*已取消初始化I2C */ I2C_CLOSE (i2c); printf ("I2C已关闭!\n"); 返回(NULL); }
//设置mpu6050
UINT8_t设置缓冲器[2];
SetupBuffer[0]= 0x6b;
SetupBuffer[1]=0;
i2cTransaction.slaveAddress = 0x68;
i2cTransaction.writeBuf = setupBuffer;
i2cTransaction.writeCount = 2;
i2cTransaction.readBuf = NULL;
i2cTransaction.ReadCount = 0;
I2C_TRANSFER (i2c,&i2cTransaction);
printf ("设置完成!\n");
/*采集20个样本并将其打印到控制台上*/
对于(i = 0;i < 20;I++){
printf ("我在循环中!\n");
txBuffer[0]= 0x3B;
i2cTransaction.slaveAddress = 0x68;
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.ReadCount = 2;
IF (I2C_TRANSFER (i2c,&i2cTransaction)){
温度=(rxBuffer[0]<< 8)|(rxBuffer[1]);
温度/= 1000;
printf ("样本%u:%d (C)\n",i,温度);
}
否则{
printf ("I2C总线故障\n");
}
/*睡眠1秒*/
睡眠(1);
}
/*已取消初始化I2C */
I2C_CLOSE (i2c);
printf ("I2C已关闭!\n");
返回(NULL);
}
[引用user="Changmin Lee)]实际上,这是第一次使用CCS (甚至使用ARM),所以我不熟悉调试器。
您是否有我可以获取相关信息的链接?[/QUOT]
我将从以下链接开始:
此外,建议使用以下链接:
http://processors.wiki.ti.com/index.php/GSG:Debugging_projects_v5#Launching_the_debugger
请注意上面链接中的图6。 它是调试工具栏的图形。 黄色箭头是源步进按钮。
希望这有所帮助
KI
哦,现在我明白了。 谢谢
在我走了一步之后它就停止了
I2C_TRANSFER (i2c,&i2cTransaction);
,打印“设置完成!”之前。