Sending 4 empty bits #644
Replies: 3 comments
-
Posted at 2016-11-13 by CriscoCrusader I see that espruino supports the binary prefix, 0b, so 0b0000 should work, and appears to work, but reading the empty byte and printing it out ('0000') seems to take a lot of effort in C++ (my slave device for testing use is an arduino uno). |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-11-14 by @allObjects I2C is sending by specification always 8 bits - the 8 lower bits of the bytes (or values in an array) you provide. Easiest is a plain integer number that you mask with & 15. Bits 5 through 7 (counting from 0 and LSB) get nulled. If you need to pack four booleans into 4 bit, you can do that by addition of the mapping values of 1, 2, 4, and 8. Unpacking can be done in a similar way... and the fun part is that JavaScript looks at any number that is not 0 as true in a logical statement, so receiving To actually answer your question literally: just send 0 ( |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-11-14 by @gfwilliams As @allObjects says, it's not possible to send just 4 bits via I2C on any platform, it's just the way I2C works - you have to send a byte at a time. Your best bet is to send a whole byte and only use the bottom 4 bits - so sending
Welcome to embedded software! :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2016-11-13 by CriscoCrusader
Is there a way to directly represent 4 empty bits in JS? To send 0000 over I2C, it seems I have to use an array of 0's.
Beta Was this translation helpful? Give feedback.
All reactions