I can't figure out what the input/output of the SPIDev xfer command is supposed to be. I know it accepts an array of integers but what does it mean? I initially thought it meant the byte array of an integer like so:

Integer = 2
Byte Array = [0x0, 0x2]

But the SPI slave (a MSP432 microcontroller) receives two numbers: 80 and 0. Like the output of the xfer command is very random. So how do I use the spidev.xfer command?

  • Nothing to do with the Pi. If you transfer x bytes the device you are talking to receives x bytes and returns x bytes. If you send 0x0 and 0x2 it receives 0x0 and 0x2. You need to read the device datasheet and study binary numbers. – joan Nov 6 '17 at 22:16
  • Yeah, but the main problem is that my receiving device isn't receiving 0x0 and 0x2 - it's receiving random input instead and I don't know the cause. – Amelia Nov 7 '17 at 0:22
  • Could be many reasons, an obvious one is incorrect connections. You need to provide relevant information if you want help. – joan Nov 7 '17 at 5:04
  • Okay so what I know is let's say I want to send an integer (for example, 2) over SPI - do I do spidev.xfer([0x0, 0x2])? Is this the correct format or is it spidev.xfer([2])? Do I have to use a longer byte array? – Amelia Nov 7 '17 at 16:42

Your Answer

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

Browse other questions tagged or ask your own question.