Go Down

Topic: EasyTransferI2C with 3 Arduinos - trouble w/ Master Tx & Rx (Read 1 time) previous topic - next topic

pylon

The library is making things easier but you're trying to use it in a manner it is not intended for. It just tries to give an easier interface to the Wire library but it's not able to give the I2C bus capabilities it does not have.

Have you understood the I2C paradigm of master and slave? Your master is still configured as a slave (Wire.begin() call with an address parameter), this way you cannot send commands to the slaves.

liquidbuddha

Hi Pylon, thanks for your reply.

Quote
Have you understood the I2C paradigm of master and slave? Your master is still configured as a slave (Wire.begin() call with an address parameter), this way you cannot send commands to the slaves.

Hmm.. I guess not!  I thought that each I2C "node" had to have an address, in order for messages to be routed to the correct node.. thus I thought each had to be identified w/ a #define.

Looking at the Tx and Rx examples from the EasyTransferI2C library, they send from the Master to the Slave, which I will want sometimes, but I also am wanting the reverse... in order to get information from the slave.  How will I identify the Master, when receiving data from the slave?

What is also confusing me, with regard to EasyTransfer vs standard I2C, is the "number of bytes" when doing a request. How do I make a request to the slave, in the EasyTransfer data structure paradigm?

Many thanks for helping me to understand this.  You've been very helpful. :D

pylon

The most important fact in I2C communication is that a transfer is always initiated by the master. This is either a write operation (master sends to slave) or a read operation (master receives data from slave).
The master doesn't need an address on the bus because it's always initiating every communication and it's also controlling it (by providing the clock signal).
If you wanna send information from the slave to the master, you have to take care that the master is polling the slave for that information often enough. Although there is no rule how the slave organizes the I2C transfers the most often used scheme is the register based approach. That means the slave defines some registers which the master is able to read and write. Each register has it's address, sequential reads and writes are allowed (auto-incrementing register address). Most I2C devices use this way to communicate because it naturally fits the I2C specification.
In your case for slave 1 I would define two registers, on address 0 (and 1 because it's an integer) you have threshold value, on address 2 (and 3 for the second byte) you have the sensor value. If you wanna save some register addresses you can combine the two because probably the threshold value is only written while the sensor value can only be read. How you organize the byte order (little or big endian) is on you, both have advantages and disadvantages.

Quote
What is also confusing me, with regard to EasyTransfer vs standard I2C, is the "number of bytes" when doing a request. How do I make a request to the slave, in the EasyTransfer data structure paradigm?


I wouldn't use the EasyTransfer library in your case. It only makes things more complicated and I don't see the need for dynamically sized transfers on the I2C bus.

liquidbuddha

Quote
I wouldn't use the EasyTransfer library in your case. It only makes things more complicated and I don't see the need for dynamically sized transfers on the I2C bus.


Ok.. I suppose it's best I understand the I2C basic methods, especially to work with devices not-as-smart as Arduinos.  I was hoping to use EasyTransfer as I assumed I would be able to more easily change data types and sizes without having to bit-bang the changes through... perhaps I'm over thinking!

My confusion is centered around this thing you're call a "register based approach". The theory is clear, but the implementation eludes me. I feel like I'm asking to much for your to hand-hold me through this, so I wonder if you could recommend an online resource for I2C, or other resource? I suppose I need an I2C primer which is more in-depth than the Arduino references.

EasyTransfer (imho) still feels like the right, more dynamic solution for communicating to the web-server slave... do you foresee any problems using them together?

pylon

Quote
I was hoping to use EasyTransfer as I assumed I would be able to more easily change data types and sizes without having to bit-bang the changes through... perhaps I'm over thinking!


This isn't wrong, EasyTransfer makes this a little bit easier. The question is, does this approach make it easier for you in your project.

Quote
I suppose I need an I2C primer which is more in-depth than the Arduino references.


Try the introduction of Nick Gammon (a moderator on this forum), it's the only one I know which is Arduino based.
http://www.gammon.com.au/forum/?id=10896

Quote
EasyTransfer (imho) still feels like the right, more dynamic solution for communicating to the web-server slave... do you foresee any problems using them together?


No, other than it might guide you again to think about the I2C as a fast version of an UART communication. It was designed to let a processor talk to some devices (chips) and not to let two processors talk to each other. Although this is possible with I2C, it forces you to select one side to be the master while the other side is the slave. In a processor-processor communication it's not always obvious which one should be the master.

Go Up