完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我们的设备挂了一个i2c的传感器,psoc6当master,通过以下的示例代码来读写传感器的寄存器
{ cy_stc_scb_i2c_master_xfer_config_t transfer; uint8_t readBuffer [5UL]; uint8_t writeBuffer[2UL] = {0U, 5U}; /* Configure write transaction */ transfer.slaveAddress = 0x08U; transfer.buffer = writeBuffer; transfer.bufferSize = sizeof(writeBuffer); transfer.xferPending = true; /* Do not generate Stop condition at the end of transaction */ /* Initiate write transaction. * The Start condition is generated to begin this transaction. */ (void) Cy_SCB_I2C_MasterWrite(SCB3, transfer, i2cContext); /* Wait for transaction completion */ while (0UL != (CY_SCB_I2C_MASTER_BUSY Cy_SCB_I2C_MasterGetStatus(SCB3, i2cContext))) { } /* Configure read transaction */ transfer.buffer = readBuffer; transfer.bufferSize = sizeof(readBuffer); transfer.xferPending = false; /* Generate Stop condition the end of transaction */ /* Initiate read transaction. * The ReStart condition is generated to begin this transaction because * previous transaction was completed without Stop. */ (void) Cy_SCB_I2C_MasterRead(SCB3, transfer, i2cContext); /* Wait for transaction completion */ while (0UL != (CY_SCB_I2C_MASTER_BUSY Cy_SCB_I2C_MasterGetStatus(SCB3, i2cContext))) { } } 但调试中发现有很大概率在下面的代码中死循环,while (0UL != (CY_SCB_I2C_MASTER_BUSY Cy_SCB_I2C_MasterGetStatus(SCB3, i2cContext))) { } 请问这是啥原因呢?是i2c初始化没做好?还是i2c总线上有冲突?(但总线上我就挂了一个设备)谢谢! |
|
相关推荐
1个回答
|
|
根据你说的这个现象,会不会跟你连接的GSENSOR有关系,你可以仔细按下他的技术手册,对于初始化是不是需要一个上电的稳定时间之类的。
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
飞凌嵌入式ElfBoard EL 1板卡-i2c与从设备通讯编程示例之i2c-tools工具使用
976 浏览 0 评论
stc15f2k60s2利用串口传输字模存储到eeprom并进行点阵显示
1093 浏览 1 评论
1356 浏览 0 评论
607 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-串口通讯编程示例之串口编写程序
1236 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11600 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-4 03:59 , Processed in 0.526404 second(s), Total 74, Slave 56 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号