Sunday 5 June 2016

Can I2C be used with momentary sensors?


[edit: clarifying the question] Is it possible to see events on I2C slaves, or a functional equivalent?



I'm brainstorming a new project. I'm using an ESP-12F as a main logic board to control and receive input from various connected modules (e.g. pushbutton, beam sensor, solenoid valve, shutter trigger) Each module (slave) is PIC based, and communicates with the ESP-12 (master) using I2C. Sending commands for valves and triggers over I2C is straightforward. I'm not sure how to utilize I2C for slave-triggered momentary events though.


Should I just keep sending status requests to those modules and look for changes that way? I'm also considering using XOR logic to flip the level of another line, which I can detect via interrupt to trigger the status request.


My device is timing sensitive, I'd like to get a response to a trigger down to maybe 50-100 microseconds.


I'm new to all of this so feel free to correct me on anything fundamental I'm missing.



Answer



The terms of art here are Polling, i.e. repeatedly checking the sensor for changes, vs Interrupt, being alerted on demand of a change.


No, I2C does not provide an Interrupt protocol directly. A subset of I2C, called SMBUS, does. It has the SMBALERT#, which the Host device has a single Interrupt pin which all the slave devices can attach to, and when triggered, the Host will read from the special Alert Response Address (0001 100x), and any slave that has a pending alert will write it's specific address. The Host then reads directly from it. If more than one is pending an Alert, arbitration takes place, and the Host will need to read from the ARA multiple times.


Neat trick, you can skip the interrupt pin, and poll from the ARA anyway, and then only if you get a valid address do you try to read from the slave. This can cut down the number of times you try to poll, if you have multiple slave devices.


Of course, you can implement this on I2C quite easily, if you can program the slave devices and the host device.


Alternatively, you can make all the micro controllers masters and slaves, implementing an I2C Multi-Master setup. Have the modules become masters and write to your main device. Then your main device switches to master mode, to read back.



Or just leave your main device as a slave and have the modules as masters write to it on demand as needed.


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...