用的是硬件I2C读取9250数据 并用DMP输出欧拉角 IIC连续读的函数绝对正确 但连续写就不一定了 先放个连续写的函数
uint8_t MPU_Write_Len(uint8_t addr,uint8_t reg,uint8_t len,uint8_t *buf)
{
I2CMasterSlaveAddrSet(I2C1_BASE,addr,false);
I2CMasterDataPut(I2C1_BASE,reg);
I2CMasterControl(I2C1_BASE,I2C_MASTER_CMD_BURST_SEND_START);
while(I2CMasterBusy(I2C1_BASE));
{
I2CMasterSlaveAddrSet(I2C1_BASE,addr,false);
I2CMasterDataPut(I2C1_BASE,reg);
I2CMasterControl(I2C1_BASE,I2C_MASTER_CMD_BURST_SEND_START);
while(I2CMasterBusy(I2C1_BASE));
if(len==1)
{
I2CMasterDataPut(I2C1_BASE,*buf);
I2CMasterControl(I2C1_BASE,I2C_MASTER_CMD_BURST_SEND_CONT);
while(I2CMasterBusy(I2C1_BASE));
I2CMasterControl(I2C1_BASE,I2C_MASTER_CMD_BURST_SEND_FINISH);
}
else
{
while(len)
{
I2CMasterDataPut(I2C1_BASE,*buf);
I2CMasterControl(I2C1_BASE,I2C_MASTER_CMD_BURST_SEND_CONT);
while(I2CMasterBusy(I2C1_BASE));
len–;
buf++;
}
I2CMasterControl(I2C1_BASE,I2C_MASTER_CMD_BURST_SEND_FINISH);
while(I2CMasterBusy(I2C1_BASE));
}
return 0;
}
{
I2CMasterDataPut(I2C1_BASE,*buf);
I2CMasterControl(I2C1_BASE,I2C_MASTER_CMD_BURST_SEND_CONT);
while(I2CMasterBusy(I2C1_BASE));
I2CMasterControl(I2C1_BASE,I2C_MASTER_CMD_BURST_SEND_FINISH);
}
else
{
while(len)
{
I2CMasterDataPut(I2C1_BASE,*buf);
I2CMasterControl(I2C1_BASE,I2C_MASTER_CMD_BURST_SEND_CONT);
while(I2CMasterBusy(I2C1_BASE));
len–;
buf++;
}
I2CMasterControl(I2C1_BASE,I2C_MASTER_CMD_BURST_SEND_FINISH);
while(I2CMasterBusy(I2C1_BASE));
}
return 0;
}
然后是DMP初始化里面加载DMP固件失败
for (ii = 0; ii < length; ii += this_write) {
this_write = min(LOAD_CHUNK, length – ii);
if (mpu_write_mem(ii, this_write, (unsigned char*)&firmware[ii]))
return -1;
if (mpu_read_mem(ii, this_write, cur))
return -1;
if (memcmp(firmware+ii, cur, this_write))
return -2;
this_write = min(LOAD_CHUNK, length – ii);
if (mpu_write_mem(ii, this_write, (unsigned char*)&firmware[ii]))
return -1;
if (mpu_read_mem(ii, this_write, cur))
return -1;
if (memcmp(firmware+ii, cur, this_write))
return -2;
总是返回-2 不知道是不是连续写的问题
或者恳请大佬留下你们用DMP的例成 被这个东西折腾两个星期了 就是得不到欧拉角
之前试过用角速度和加速度解算姿态角 可解算出来的角总是在鬼畜 资料看了无数遍 代码移植了无数条 就是搞不出来啊
xyz549040622:
9250没有用过,可以参考下这个帖子里面的驱动,他的MPU9250的写程序应该是好的
e2echina.ti.com/…/162371
user5813287:
回复 xyz549040622:
这就是我写
xyz549040622:
回复 user5813287:
晕,居然没有看作者,这么长时间了,写都没有搞定吗?