单片机/MCU论坛
直播中

卓侨汉

7年用户 1034经验值
擅长:MEMS/传感技术
私信 关注

psoc6 i2c读写时死循环是什么原因导致的?

我们的设备挂了一个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)

张浩

2024-2-4 14:11:51
根据你说的这个现象,会不会跟你连接的GSENSOR有关系,你可以仔细按下他的技术手册,对于初始化是不是需要一个上电的稳定时间之类的。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分