New answers tagged

1

There are two alternative methods, and they can both be easily used "in reverse" as well: Unions union byte_extract { uint32_t ival; struct { uint8_t byte_0; // least significant byte uint8_t byte_1; uint8_t byte_2; uint8_t byte_3; // most significant byte } bval; }; ... later ... union byte_extract x; x.ival =...


1

The header Arduino.h defines the macro word(high_byte, low_byte). The resulting value is an uint16_t.


5

Any more sophisticated byte exchange can be done with binary operators. Extracting information You'll need some constants like MASK SHIFT 0xFF000000 24 (first byte, most significant) 0x00FF0000 16 (second byte) 0x0000FF00 8 (third byte) 0x000000FF 0 (last byte, least significant)...


1

Strings (aka byte arrays of arbitrary length) are perfect for asynchronous and full duplex protocols like UART, essentially because those are no master-slave protocols. Here, both master and slave can transmit a byte stream independent of each other at any time and with any length. But using strings on I2C is quite uncommon. As I2C is a master-slave bus ...


2

I2C works with fixed size byte arrays. Single bytes for commands should be sufficient. For positions you might need int16_t or even bigger numbers. Unsigned positions relative to (above) zero might make things easier, eventually (?) As you have the same architecture on both sides, mapping of byte arrays to bigger numbers via union will work well.


0

There is no builtin data type that can store 78 bits. However, it depends a bit what you want to store. Like the following cases: If the 78 bits are one 'entity' (e.g. one really big value), you can store it as an array of bytes (10 bytes of 8 bits = 80 bits, leaving 2 bits unused) If the 78 bits can be split up in smaller parts, you can: Create a ...


Top 50 recent answers are included