Reading specific bits

The device I am reading has specific information all packed together like this:

8 bits - Configuration
8 bits MSB
8 bits LSB

In order to get the reading, I need to read the 2nd 8 bits shifting to the left 8 bits and then read the third 8 bits shifting to the right one and then storing the information.

Can you specify which bits to read from a device?

You have to read all the bits (generally as bytes), then extract the information from the ones you’ve read.

If you’d read 3 bytes (24 bits) into a blob with:

local data = spi.readblob(3);

…then you’d extract the value like this. The 3 bytes are in data[0], data[1], and data[2].

local value = (data[1] << 8) | data[2];

@Hugo awesome, I had thought that was what the [x] meant.