I am creating a master/slave setup with an RPi as the master and an Arduino as the slave. For now I am only using one, but I will eventually have up to 25 on a single I2C bus.
On the Arduino side, the Wire library has a Wire.onRequest function as well as a Wire.requestFrom function, where .requestFrom is used by the Master to request a number of bytes from the slave, which uses Wire.onRequest to respond with the requested info.
I'm currently using the Node.js i2c-bus library on my Pi to handle I2C. I'm wondering if the i2c-bus.read function works similarly to the Wire.requestFrom function. Are these apples and oranges, or functionally the same?
The i2c-bus documentation mentions nothing about a specific "request" functionality. More generally, is the plain I2C read the same as the Arduino's "request" functionality?
-
I have delved the internet finding an answer to this and to be honest; nobody knows. I wanted to know the difference between requestFrom and a set of reads, but to no avail.Zimano– Zimano2017年11月23日 15:16:20 +00:00Commented Nov 23, 2017 at 15:16
-
Thank you for your effort on this. With some experimentation, it seems to 'just work' like you'd hope it to, i.e. the i2c-bus.read works perfectly well with Wire.onRequest.spiteful_moose– spiteful_moose2017年11月27日 15:03:01 +00:00Commented Nov 27, 2017 at 15:03
1 Answer 1
I've worked a bunch on this with my father and some colleagues. As far as we can tell, the i2c-bus.read functions identically to Wire.requestFrom, as we've been using .read on the Raspberry Pi and the .requestFrom interrupt on the Arduino side. The Arduino responds in the way you'd hope/expect it to.
I can only really speak to the actual functionality. I'm not sure if there are differences when you get closer to the metal, but I would expect them to be pretty close since I2C is such a simple serial bus.