您好!
我´m 通过 I2C 连接到 LSM6DS33器件、但这给了我一些问题。 我的目的是制作蓝牙信标并广播设备为我提供的值的一种解释。
问题是、当我尝试使用周期性任务读取这些值时、LSM6DS33配置值会发生差异、有时传感器值为零、有时是正确的值。
静态空 SimpleBLEBroadcaster _init (空)
{
//
//在调用 iCall_registerApp 之前可能会发生 N0栈 API 调用
//
//将当前线程注册为 iCall 调度应用程序
//以便应用程序可以发送和接收消息。
iCall_registerApp (自实体、SEM);
//I2C 驱动程序初始化
I2C_init();
I2C_PARAMS_INIT (params);
I2C_Transaction i2cTrans;
uint8_t txBuf[32]={0};//发送缓冲器
uint8_t rxBuf[32]={0};//读取缓冲区
句柄= I2C_open (Board_I2C、params);
if (!handle){
//错误
}
/////////////////////////////////////////////////////////////////// LSM6DS33///////////////////////////////////
//配置 gyro y acelerometro
//确认
//地址= 0x10 ctrl1
//// 0x80
TxBuf[0]= 0x10;
txBuf[1]= 0x80;
i2cTrans.writeCount = 2;
i2cTrans.writeBuf = txBuf;
i2cTrans.ReadCount = 0;
i2cTrans.readBuf =空;
i2cTrans.slaveAddress = 0x6B;
。
。
。
。
}
静态空 SimpleBLEPeripheral_performPeriodicTask (空)
{
#if 1.
//******* I2C 代码*******
结构选择
{
uint16_t x;
uint16_t y;
uint16_t z;
};
结构陀螺仪
{
uint16_t x;
uint16_t y;
uint16_t z;
};
I2C_Transaction i2cTrans;
uint8_t rxBuf[32]={0};//接收缓冲区
uint8_t txBuf[32]={0};//发送缓冲器
结构 A;
结构陀螺仪 g;
句柄= I2C_open (Board_I2C、params);
if (!handle){
//错误
}
/////////////////////////////////////////////////////////////////// LSM6DS33///////////////////////////////////
//读取陀螺仪
//Address = 0x22
TxBuf[0]= 0x22;
i2cTrans.writeCount = 1;
i2cTrans.writeBuf = txBuf;
i2cTrans.ReadCount = 6;
i2cTrans.readBuf = rxBuf;
i2cTrans.slaveAddress = 0x6B;
I2C_transfer (handle、&i2cTrans);
G.x=(rxBuf[1]<<8| rxBuf[0]);
G.y=(rxBuf[3]<<8| rxBuf[2]);
G.z=(rxBuf[5]<<8| rxBuf[4]);
。
。
。
我认为主要问题是 I2C_transfer 函数。 当我´m 步调试它时、它会完全阻止、但我完全不确定。