Home › Forums › EasyTransfer Library Support Forum › EasyTransfer-I2C two-way communication
- This topic has 6 replies, 2 voices, and was last updated 11 years, 3 months ago by Anonymous.
-
AuthorPosts
-
June 11, 2013 at 1:36 pm #2640AnonymousInactive
Hi! I’m trying to use the EasyTransfer-I2C library to communicate between two arduino nanos. Subsequently, I also have an adafruit RGB LCD shield on the same I2C bus.
I’m not sure I understand the intricacies of I2C communication (which is funny because my senior project was on I2C communication but that was about a million years ago).
The Arduino Nano (NANO1) that is setup to be the “Master” (Wire.begin()) can communicate with the RGB LCD shield and can send data to my “Slave” (Wire.begin(I2C_SLAVE_ADDRESS) Arduino Nano (NANO2). This was easy to accomplish just by following the supplied examples.
So…okay… my attempt to establish a two-way communication was not so successful. What I tried was:
* on both NANO1 and NANO2 I made two EasyTransferI2C objects, ET1 and ET2.
* on both NANO1 and NANO2 I made two separate SEND_ and RECEIVE_ data structures* to handle the communication I tried passing around the “Master” handle (using Wire.begin()) between the two so that only the “Master” can talk. This really messed things up with the LCD.
I will post my code if required. I want to probably take the LCD out of the mix and get the two way communication working between NANO1 and NANO2 as a first step. I’m hopeful that my mistake is simple, and there is a good example to follow for this.
Thanks!June 11, 2013 at 5:48 pm #2641AnonymousInactiveIt looks like the Master needs to send an ACK in order for a Slave to know it is OK to send data. I’ve removed the swapping of master and slave because it was throwing my LCD off.
EasyTransferI2C::sendData() needs some address to send data to but I’m unsure what the Master address would be. The obvious “0” didn’t do it.
June 11, 2013 at 8:55 pm #2642AnonymousInactiveAfter studying the code a bit more and reading more about the Wire library, I don’t think that the EasyTransfer-I2C can support Slave -> Master writing.
That being said, I think that the code could be easily modified to support this. I’m going to try it.
June 11, 2013 at 8:56 pm #2643AnonymousInactiveWhat leads me to believe this is that this function:
//Sends out struct in binary, with header, length info and checksum
void EasyTransferI2C::sendData(uint8_t i2c_address){
uint8_t CS = size;
_serial->beginTransmission(i2c_address);
#if ARDUINO >= 100
_serial->write(0x06);
_serial->write(0x85);
_serial->write(size);
has “beginTransmission()” call which is only done by the Master I think…
June 12, 2013 at 1:15 pm #2644AnonymousInactiveI’ve written some new I2C code, but still having issues. I’ve posted in the Arduino forums requesting help.http://forum.arduino.cc/index.php?topic=171682.0
Please continue the discussion there.
June 23, 2013 at 11:14 am #2708BillMemberNickerbocker,
I’ve you’ve found and fixed a bug, submit it as a pull request on Github so the changes can be added to the code.
June 25, 2013 at 10:03 am #2717AnonymousInactiveI’ll have to learn about using Github, but for now here is what I have.
https://www.dropbox.com/s/w1aj0g0ef3r2juv/EasyTransferI2C_NL%206-19-2013.zip
These changes allow for sending and receiving data to a I2C Slave. I can get it to work on data structures 28 bytes and smaller. That’s the current outstanding bug. If I make a data structure >28 bytes, the communication fails. My understanding is that you can transfer as much as 256 bytes of data at a time over I2C, so with the 3 “check bytes” it seems like the real limitation would be 253 bytes of user data. I have some projects that need >28 bytes, so if I work this bug out I’ll repost some code.
In general the usage is as straight forward and simple as EasyTransfer. The only difference between the MASTER and SLAVE communication is that the MASTER addresses the SLAVE devices and the SLAVE just responds to the MASTER’s requests. So the MASTER’s function calls look like: ET.sendData(I2C_SLAVE_ADDRESS) and ET.receiveData(I2C_SLAVE_ADDRESS) and a SLAVE’s function calls look like: ET.sendData() and ET.receiveData(). In the ISR for a SLAVE when it receives a request from the MASTER, the ET.flagSlaveSend() function can be called so that a flag is set and ET.sendData() can then be called in the main program loop (if desired).
The included example is similar to the example for EasyTransfer. The MASTER rolls on a “blinks” and “pauses” value and outputs them to the SLAVE. The SLAVE does its blinking and sends the “blinks” and “pauses” values back to the MASTER. When the MASTER receives them it executes the same “blinks” and “pauses” routine. So you can see that the data is being communicated back and forth in circles.
-Nic
-
AuthorPosts
- You must be logged in to reply to this topic.