Home › Forums › EasyTransfer Library Support Forum › Easy Transfer Byte Limit?
Tagged: I2C
- This topic has 4 replies, 4 voices, and was last updated 7 years, 8 months ago by Anonymous.
-
AuthorPosts
-
July 5, 2015 at 12:28 pm #3323AnonymousInactive
Hello Bill.
Firstly, great work on the transfer libraries they work great for most of my applications
I’m using I2C method and I have an application that needs to transfer 24 ints from one arduino to another but it appears that there is a limit of 12 integers with the transfer. Once I put in the 13th integer communication fails. I was just wondering if this is a know bug/limit and if there is any way of getting round this?
Many thanks and Best Regards,
Lee
August 2, 2015 at 12:31 pm #3327AnonymousInactiveoutrage, just seen your post. Possibly the problem is that there is a limit of 32 bytes, I believe, when using the wire library. So 24 ints would exceed this since 16 ints = 32 bytes.
Hope this helps
August 26, 2015 at 8:47 am #3330AnonymousInactiveI Just ran into the same issue – there is a fairly easy work around – use one int as an ID and send the other int´s in multiple packages – you could do one packet per loop – I managed to send multiple packages within the same loop. Bill hope you don´t mind me pasting code here?
RX CODE———————————————
#include <Wire.h>
#include <EasyTransferI2C.h>
//create object
EasyTransferI2C ET;
struct RECEIVE_DATA_STRUCTURE{
//put your variable definitions here for the data you want to receive
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
int DATA_ID;
int DATA1;
int DATA2;
int DATA3;
};
//give a name to the group of data
RECEIVE_DATA_STRUCTURE mydata;
//define slave i2c address
#define I2C_SLAVE_ADDRESS 9
void setup(){
Serial.begin(9600);
Wire.begin(I2C_SLAVE_ADDRESS);
//start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
ET.begin(details(mydata), &Wire);
//define handler function on receiving data
Wire.onReceive(receive);
}
void loop() {
//check and see if a data packet has come in.
if(ET.receiveData()){
if (mydata.DATA_ID == 1){
Serial.print(“DATA1”);
Serial.println(mydata.DATA1);
Serial.print(“DATA2”);
Serial.println(mydata.DATA2);
Serial.print(“DATA3”);
Serial.println(mydata.DATA3);
// delay(100);
}
if (mydata.DATA_ID == 2){
Serial.print(“DATA4”);
Serial.println(mydata.DATA1);
Serial.print(“DATA5”);
Serial.println(mydata.DATA2);
Serial.print(“DATA6”);
Serial.println(mydata.DATA3);
// delay(100);
}
}
}
void receive(int numBytes) {}
—————————————————————————
TX CODE—————————————————————-
#include <Wire.h>
#include <EasyTransferI2C.h>
//create object
EasyTransferI2C ET;
struct SEND_DATA_STRUCTURE{
//put your variable definitions here for the data you want to send
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
int DATA_ID;
int DATA1;
int DATA2;
int DATA3;
};
int SPEED_RAW =0;
int RPM_RAW = 0;
int countup =1;
int testsignal =0;
//give a name to the group of data
SEND_DATA_STRUCTURE mydata;
//define slave i2c address
#define I2C_SLAVE_ADDRESS 9
void setup(){
Wire.begin();
Serial.begin(9600);
Serial.println(“2 wire comms starting…..”);
//start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
ET.begin(details(mydata), &Wire);
Serial.println(“2 wire comms started OK”);
}
void loop(){
Serial.println(“loop started”);
//this is how you access the variables. [name of the group].[variable name]
mydata.DATA_ID = 1;
mydata.DATA1 = 1;
mydata.DATA2 = 2;
mydata.DATA3 = 3;
//send the data
Serial.println(“Sending Data 2 “);
ET.sendData(I2C_SLAVE_ADDRESS);
Serial.println(“DATA1 SENT”);
delay (5);
//this is how you access the variables. [name of the group].[variable name]
mydata.DATA_ID = 2;
mydata.DATA1 = 4;
mydata.DATA2 = 5;
mydata.DATA3 = 6;
//send the data
Serial.println(“Sending Data 2 “);
ET.sendData(I2C_SLAVE_ADDRESS);
Serial.println(“DATA2 SENT”);
delay (5);
}
August 26, 2015 at 1:38 pm #3333AnonymousInactiveHi John,
Thanks for posting your workaround thats very helpful! I’ll give that a go when I have time.
Many thanks,
All the best.
Lee
January 4, 2017 at 2:03 am #3608AnonymousInactivey dis serial print is not working.. :/
#include <Wire.h>
#include <EasyTransferI2C.h>
const int num = 12;
int print_buffer[num];//create object
EasyTransferI2C ET;
struct RECEIVE_DATA_STRUCTURE{
//put your variable definitions here for the data you want to receive
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
int DATA_ID;
int DATA1;
int DATA2;
int DATA3;
int DATA4;
int DATA5;
int DATA6;
int DATA7;
int DATA8;
int DATA9;
int DATA10;
int DATA11;
int DATA12;
int DATA13;};
//give a name to the group of data
RECEIVE_DATA_STRUCTURE sensor_data;
//define slave i2c address
#define I2C_SLAVE_ADDRESS 9
void setup(){
Serial.begin(9600);
Wire.begin(I2C_SLAVE_ADDRESS);
//start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
ET.begin(details(sensor_data), &Wire);
//define handler function on receiving data
Wire.onReceive(receive);
}
void loop()
{//check and see if a data packet has come in.
if(ET.receiveData())
{
if (sensor_data.DATA_ID == 1)
{
print_buffer[0] = sensor_data.DATA1;
print_buffer[1] = sensor_data.DATA2;
print_buffer[2] = sensor_data.DATA3;
print_buffer[3] = sensor_data.DATA4;
print_buffer[4] = sensor_data.DATA5;
print_buffer[5] = sensor_data.DATA6;
print_buffer[6] = sensor_data.DATA7;
print_buffer[7] = sensor_data.DATA8;
print_buffer[8] = sensor_data.DATA9;
print_buffer[9] = sensor_data.DATA10;
print_buffer[10] = sensor_data.DATA11;
print_buffer[11] = sensor_data.DATA12;
print_buffer[12] = sensor_data.DATA13;
/*Serial.print(“DATA1”);Serial.println(sensor_data.DATA1);
Serial.print(“DATA2”);
Serial.println(sensor_data.DATA2);
Serial.print(“DATA3”);
Serial.println(sensor_data.DATA3);
Serial.print(“DATA4”);
Serial.println(sensor_data.DATA4);
Serial.print(“DATA5”);
Serial.println(sensor_data.DATA5);
Serial.print(“DATA6”);
Serial.println(sensor_data.DATA6);
Serial.print(“DATA7”);
Serial.println(sensor_data.DATA7);
Serial.print(“DATA8”);
Serial.println(sensor_data.DATA8);
Serial.print(“DATA9”);
Serial.println(sensor_data.DATA9);
Serial.print(“DATA10”);
Serial.println(sensor_data.DATA10);
Serial.print(“DATA11”);
Serial.println(sensor_data.DATA11);
Serial.print(“DATA12”);
Serial.println(sensor_data.DATA12);
Serial.print(“DATA13”);
Serial.println(sensor_data.DATA13);
// delay(100);*/
for(int i=0;i<=num;i++)
{
if(i == num)
Serial.println(print_buffer[i]);
else
{
Serial.print(print_buffer[i]);
Serial.print(‘\t’);
}
}
}}
}
void receive(int numBytes) {}
-
AuthorPosts
- You must be logged in to reply to this topic.