I2C clocks stop after slave ack the address

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

I2C clocks stop after slave ack the address

430 次查看
tommino
Contributor I

Hello community,

 

I am using the LPC824 I2C to talk with a IC slave. The goal is to have this kind of communication as reported in the slave manual

tommino_0-1744785196731.png

Precondition: I2C HW is correctly working in my board since I can talk to different I2C slaves without issues ( I mean different type of devices...i have more than one unit of the I2C slave that is giving me the problem and I tried all of them and nothing changes).

The problem is that everything is fine until the part pointed by the arrow: LPC824 sends out the slave address which is ACK by the slave, then I have the register and then the I see another ACK in the SDA line but from now on: SCL line is stopped and no clock is present, SDA line keeps staying low forever. I think that the problem comes from the fact that no clock is present ( see oscilloscope screenschot attached). 

 

The code is the following:

if((LPC_I2C0->STAT & MSTSTATE) == MSTSTATE_IDLE){ /* if idle */
LPC_I2C0->MSTDAT=(devaddr<<1); /* send addr w/ R/W bit =0 */
LPC_I2C0->MSTCTL=(1<<MSTSTART); /* send start condition */
}

while(!(LPC_I2C0->STAT & MSTPENDING)) /* wait for i2c0 idle or pending */

  // send register
      LPC_I2C0->MSTDAT=(reg_address);                                      
  LPC_I2C0->MSTCTL=(1<<MSTCONTINUE);
 
  while(!(LPC_I2C0->STAT & MSTPENDING));   /* wait for i2c0 idle or pending */
 
LPC_I2C0->MSTDAT=(devaddr<< 1)|0x1; /* send addr w/ R/W bit =1 */
LPC_I2C0->MSTCTL=(1<<MSTCONTINUE);
 
while(!(LPC_I2C0->STAT & MSTPENDING)); /* wait for i2c0 idle or pending */
value1=LPC_I2C0->MSTDAT;
LPC_I2C0->MSTCTL=(1<<MSTCONTINUE);
 
LPC_I2C0->MSTCTL=(1<<MSTSTOP)
 
Any idea where is the bug?
0 项奖励
回复
2 回复数

418 次查看
tommino
Contributor I

I forgot the scope screenshot

tommino_0-1744789081298.png

 

0 项奖励
回复

397 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @tommino 

Thank  you for your contacting us.

In an I2C read operation, when switching from "writing the register address" to "reading data", a ​​Repeated Start​​ signal needs to be sent instead of directly sending the read address.

 

The current code uses MSTCONTINUE before sending the read address. This causes the timing to not comply with the standard I2C specification. Therefore, please change LPC_I2C0->MSTCTL=(1<<MSTCONTINUE); to LPC_I2C0->MSTCTL = (1 << MSTSTART); before the read operation.

 

BR

Alice

0 项奖励
回复