Announcements

Ever wondered how you could shape the future in collaboration with others? Join us at OktoberTech Asia Pacific and get inspired. Click here to sign up FREE of charge.

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

PSoC™ 6 Forum Discussions

zhji_4006061
Level 3
First solution authored 10 questions asked 25 sign-ins
Level 3

我们的设备挂了一个i2c的传感器,psoc6当master,通过以下的示例代码来读写传感器的寄存器

{

 
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总线上有冲突?(但总线上我就挂了一个设备)谢谢!
0 Likes
1 Solution
YuZh
Moderator
Moderator 10 likes received 50 sign-ins 50 replies posted
Moderator

Hi:

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

 

zhichai

View solution in original post

6 Replies
zhji_4006061
Level 3
First solution authored 10 questions asked 25 sign-ins
Level 3

死循环一般发生在系统刚上电初始化的时候

0 Likes
YuZh
Moderator
Moderator 10 likes received 50 sign-ins 50 replies posted
Moderator

Hi:

1、你是每次上下电都会这样吗?还是只是系统复位才会这样?

2、·用的是什么平台软件,PSOC Creator?还是MTB?我们有对应的example,是否又对照过例程进行调试?

3、有抓过I2C波形吗?建议最好看下。

0 Likes
zhji_4006061
Level 3
First solution authored 10 questions asked 25 sign-ins
Level 3

谢谢回复!

1、并不是每次上下电都这样,有80%的概率会死循环

2,我们用的是psoc creator,仿照的例程是CE220818_I2C_Master_High_Level01

3,I2c波形还没抓过,我等下用示波器看下

 

 

0 Likes
YuZh
Moderator
Moderator 10 likes received 50 sign-ins 50 replies posted
Moderator

Hi:

1、你接的是什么I2C设备?

2、你现在测试是注释掉全部其他代码,单独测试I2C吗?

3、你是在自己的硬件板子上测试?

4、抓个波形看看吧,一起分析下。

 

zhichao

0 Likes
zhji_4006061
Level 3
First solution authored 10 questions asked 25 sign-ins
Level 3

1, 我们接的是GSENSOR芯片 DA217

2,测试时 其他代码都注释掉了,仅剩一些GPIO和PWM的初始化操作

3,是我们自己的硬件板子

4,波形还在抓

还有我发现在I2C初始化前,延时100ms后就不会死循环了,试了100多次都是正常的,代码如下:

/***************************I2C 配置*****************************/
Cy_SysLib_Delay(100);

I2C_0_Start();

0 Likes
YuZh
Moderator
Moderator 10 likes received 50 sign-ins 50 replies posted
Moderator

Hi:

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

 

zhichai