Skip to main content
added 7 characters in body
Source Link

When I need to send multiple bytes via Wire, for example a long int, I cast it to a byte array and specify a length

long int i;
Wire.write((byte*)&i, 4);

But if I want to send bytes from more than 1 variable I need to create a buffer

byte i;
byte j;
byte message[2] = {i, j};
Wire.write(message, 2);

If I want to send them without copying the data I can put them in a struct

struct message {
  byte i;
  byte j;
};
Wire.write((byte*)&message, 2);

But this would require me to refactor existing code.

Is there any c voodoo that I can perform to send bytes of different places of my code over Wire without copying them in a buffer and without refactoring the code?

When I need to send multiple bytes via Wire, for example a long int, I cast it to a byte array and specify a length

long int i;
Wire.write((byte*)&i, 4);

But if I want to send bytes from more than 1 variable I need to create a buffer

byte i;
byte j;
byte message[2] = {i, j};
Wire.write(message, 2);

If I want to send them without copying the data I can put them in a struct

struct message {
  byte i;
  byte j;
};
Wire.write(&message, 2);

But this would require me to refactor existing code.

Is there any c voodoo that I can perform to send bytes of different places of my code over Wire without copying them in a buffer and without refactoring the code?

When I need to send multiple bytes via Wire, for example a long int, I cast it to a byte array and specify a length

long int i;
Wire.write((byte*)&i, 4);

But if I want to send bytes from more than 1 variable I need to create a buffer

byte i;
byte j;
byte message[2] = {i, j};
Wire.write(message, 2);

If I want to send them without copying the data I can put them in a struct

struct message {
  byte i;
  byte j;
};
Wire.write((byte*)&message, 2);

But this would require me to refactor existing code.

Is there any c voodoo that I can perform to send bytes of different places of my code over Wire without copying them in a buffer and without refactoring the code?

Source Link

How to send multiple bytes with Wire without copying

When I need to send multiple bytes via Wire, for example a long int, I cast it to a byte array and specify a length

long int i;
Wire.write((byte*)&i, 4);

But if I want to send bytes from more than 1 variable I need to create a buffer

byte i;
byte j;
byte message[2] = {i, j};
Wire.write(message, 2);

If I want to send them without copying the data I can put them in a struct

struct message {
  byte i;
  byte j;
};
Wire.write(&message, 2);

But this would require me to refactor existing code.

Is there any c voodoo that I can perform to send bytes of different places of my code over Wire without copying them in a buffer and without refactoring the code?