发 帖  
[问答]

颜色传感器和stm8s-discovery与i2c之间的通信协议实现是否正确?

1375 传感器 I2C



     // i want to read data from color sensor (0x74)

  I2C_Send7bitAddress(0x74, I2C_DIRECTION_RX);

while(!I2C_CheckEvent(I2C_EVENT_MASTER_ADDRESS_ACKED));
I2C_ClearFlag(I2C_FLAG_ADDRESSSENTMATCHED);
while (Rx_Idx < RX_BUFFERSIZE)
{
while(!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_RECEIVED));
I2C_Buffer_Rx[Rx_Idx++] = I2C_ReceiveData();
}

//nack.... in this point, master have to send a NACK to sensor in order to finish the i2c protocol.
I2C_ClearITPendingBit(I2C_ITPENDINGBIT_ACKNOWLEDGEFAILURE);

I2C_GenerateSTOP(ENABLE);




I don't Know if this is the correct method to send NACK and moreover i not sure that the implementation of protocol is right.

I need help, please!

Thank you!
0
2019-7-12 11:51:59   评论 分享淘帖 邀请回答 举报

只有小组成员才能发言,加入小组>>

860个成员聚集在这个小组

加入小组

创建小组步骤

快速回复 返回顶部 返回列表
关注微信公众号

电子发烧友网

电子发烧友论坛

社区合作
刘勇
联系电话:15994832713
邮箱地址:liuyong@huaqiu.com
社区管理
elecfans短短
微信:elecfans_666
邮箱:users@huaqiu.com
关闭

站长推荐 上一条 /7 下一条

快速回复 返回顶部 返回列表