完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
现在正在学习mpu9250,使用STM32F4+MPU9250, 通过SPI接口方式通讯,现在已经可以正常读取加速度和陀螺仪数据,但是磁力计无法读取,根据网上资料更改的程序:http://www.amobbs.com/thread-5579616-1-1.html, 求大侠指点!!!
附上程序: UNS8 AkWriteReg(UNS8 const regAddr, UNS8 const value) { OS_ERR err; UNS8 sta = TRUE, tmp; UNS16 retrytime = SPI_WAIT_I2C_TIME; SpiMpuWriteReg(I2C_SLV4_ADDR, AK8963_I2C_ADDR); OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &err); SpiMpuWriteReg(I2C_SLV4_REG, regAddr); OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &err); SpiMpuWriteReg(I2C_SLV4_DO, value); OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &err); SpiMpuWriteReg(I2C_SLV4_CTRL, I2C_SLV4_EN_VAL); OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &err); do { SpiMpuReadReg(I2C_MSTR_STA, &tmp); OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &err); }while( (--retryTime) && (0==(tmp&I2C_SLV4_DONE_VAL)) ); if (0 == retryTime) { sta = FALSE; } return sta; } UNS8 AkReadReg(UNS8 const regAddr, UNS8 *const pData) { OS_ERR err; UNS8 sta = TRUE, tmp; UNS16 retryTime = SPI_WAIT_I2C_TIME; if (NULL == pData) { return FALSE; } SpiMpuWriteReg(I2C_SLV4_ADDR, AK8963_I2C_ADDR | SPI_MPU_READ_CMD); OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &err); SpiMpuWriteReg(I2C_SLV4_REG, regAddr); OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &err); SpiMpuWriteReg(I2C_SLV4_CTRL, I2C_SLV4_EN_VAL); OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &err); do { SpiMpuReadReg(I2C_MSTR_STA, &tmp); OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &err); }while( (--retryTime) && (0==(tmp&I2C_SLV4_DONE_VAL)) ); if (0 != retryTime) { SpiMpuReadReg(I2C_SLV4_DI, pData); } else { sta = FALSE; } return sta; } void Ak8963Init( void ) { OS_ERR err; UNS8 tmp; AkReadReg(AK8963_WIA, &tmp);//// ref smartImu if (AK8963_WIA_VAL != tmp) { tmp ++; } AkWriteReg(0x0B, 0x01); OSTimeDlyHMSM(0, 0, 0, 100, OS_OPT_TIME_HMSM_STRICT, &err); AkWriteReg(0x0A, 0x10); OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &err); AkWriteReg(0x0A, 0x1F); OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &err); //// for test AkReadReg(0x00, &sAk8963AdjData.XMagnAdj); OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &err); AkReadReg(0x10, &sAk8963AdjData.XMagnAdj); OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &err); AkReadReg(0x11, &sAk8963AdjData.YMagnAdj); OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &err); AkReadReg(0x12, &sAk8963AdjData.ZMagnAdj); OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &err); AkWriteReg(0x0A, 0x10); OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &err); SpiMpuWriteReg(0x24, 0x5D); OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &err); SpiMpuWriteReg(0x25, SPI_MPU_READ_CMD | AK8963_I2C_ADDR); OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &err); SpiMpuWriteReg(0x26, 0x02); OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &err); SpiMpuWriteReg(0x27, 0x80 | 0x08); OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &err); AkWriteReg(0x0A, 0x16); OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &err); SpiMpuWriteReg(I2C_SLV4_CTRL, 0x01); OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &err); SpiMpuWriteReg(0x67, 0x81); OSTimeDlyHMSM(0, 0, 0, 100, OS_OPT_TIME_HMSM_STRICT, &err); } |
|
相关推荐
14个回答
|
|
|
|
|
|
自己先顶起来,希望大家多多交流...
|
|
|
|
默默的等待英雄出现......
|
|
|
|
恐怕只能靠自己了...
|
|
|
|
心急但静静的等待...
|
|
|
|
你好,我想了解一下,你这块解决了吗?我也一直卡在这,要哭了
|
|
|
|
解决了,把里面涉及到IIC读写延时的时间加长一点即可...
|
|
|
|
|
|
|
|
就是spi要延时久一些等master iic读完吗
|
|
|
|
|
|
|
|
好的谢谢,请问你有没有移植 motion driver 6.12啊
|
|
|
|
没有,我的应用不需要那么复杂...
|
|
|
|
|
|
你好请问你解决了吗?我也一样,可否指点一二
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1187 浏览 0 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
1122 浏览 2 评论
2223 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
1311 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
1735 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-27 18:43 , Processed in 0.966310 second(s), Total 98, Slave 81 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号