Good day all,

I am new to RPI and have been learning as I go. A few questions when interfacing with an SPI device using c++.

The data sheet https://media.digikey.com/pdf/Data%20Sheets/Murata%20PDFs/SCA61T.pdf

1) I believe this is SPI mode 0 correct?

2) How do I read out an 11 bit read for the RDAX value after sending my command through the MOSI?

I do not understand how I would work with the MISO data when it is not byte aligned. It sends 11 bits, but I can only receive it into a 2 byte array(16 bits). I guess I am confused on the overall process. I have used http://www.raspberry-projects.com/pi/programming-in-c/spi/using-the-spi-interface as a starting point.

Thank you for your time!


The 11 bit response is part of an 19 bit sequence (8 bit command + 11 bit data).

The simplest thing to do is transfer 3 bytes (24 bits) and ignore the last 5 received bits.

If you send three bytes you receive 3 bytes.

      Byte 1            Byte 2            Byte 3
| C C C C C C C C | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 | sent
| - - - - - - - - | D D D D D D D D | D D D - - - - - | received

value = (byte 2 << 3) + (byte 3 >> 5)

  • That appears to have done the trick, but I don't understand why shifting the bits to the left 3 times gives me my answer? Wont you lose information doing that if the MSB -> 3 has information in it? – Lanet Rino May 17 '17 at 0:37
  • @LanetRino The bit shift doesn't restrict the answer to a byte. If you prefer think of it as multiply by eight (and divide by 32 for the >> 5). Use multiply and divide if you prefer, it's just personal taste. – joan May 17 '17 at 8:18
  • No no, I get bit shifting. I mean, if I have a byte 0110 0010(98) and shift << 3, the resulting number is 0001 0000(16). Why does this give me the information i need? Why am I shifting(multiplying or dividing), to interpret the received information? Please bear with me, I am new to EE – Lanet Rino May 17 '17 at 19:26
  • I don't understand the question. 11 bits are returned. It's convenient to convert the 11 binary bits to a single decimal value. – joan May 17 '17 at 19:44
  • Why does this convert it to a decimal value? What does the untouched data represent, and why does this turn it into a decimal value? I plugged in the returned RDAX value into the formula and am getting the correct angle, but I don't understand why I first need to shift bits around. – Lanet Rino May 18 '17 at 4:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.