简体   繁体   English

主机如何确定I2C从机是否繁忙而又不中断从机上对时间敏感的代码?

[英]How can the master figure out if an I2C slave is busy without interrupting time-sensitive code on the slave?

So I have a device set as the I2C master, and the rest of the devices on the bus are set as slaves. 因此,我将一个设备设置为I2C主设备,而总线上的其余设备都设置为从设备。 The master sends a command to each slave, and the slave executes this task (running motors, etc, important time-sensitive code). 主机向每个从机发送命令,而从机执行此任务(运行电动机等,对时间敏感的重要代码)。 I would like to be able to know when the slave is finished executing its task. 我想知道从服务器何时完成其任务。 The only way I can see to do this is to constantly have the master poll the slave, but this creates an issue, because every time the master polls the slave, it triggers and i2c interrupt on the slave and quits running the motor code for a short amount of time. 我能看到的唯一方法是不断让主设备轮询从设备,但这会产生一个问题,因为每次主设备轮询从设备时,它都会触发从设备上的i2c中断,并退出电机代码运行。时间短。

Is there anyway to solve this? 反正有解决办法吗? I was thinking of setting all devices as a master, so then when each device finishes it task, it can send the data over saying that it is done, without the need for polling. 我当时正在考虑将所有设备设置为主设备,这样,当每个设备完成任务时,它就可以发送数据,说它已经完成,而无需轮询。 The issue with this is I'm worried about data collision over the bus with devices possibly trying to talk at the same time. 问题是我担心与试图同时通话的设备在总线上发生数据冲突。

What is the correct way to solve this issue? 解决此问题的正确方法是什么?

Let the slave disable its I2C interface while it's running a time-critical task, and re-enable afterwards. 让从设备在运行时间紧迫的任务时禁用其I2C接口,然后再重新启用。 Then, the master can poll as often as it wants to, it would get no ACK from the busy slave, and the slave won't get any interrupts either. 然后,主机可以根据需要进行多次轮询,繁忙的从机不会收到ACK,从机也不会收到任何中断。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM