I connected MOSI to MISO on Raspberry PI 3

Executed the below code:

import time
import sys
import spidev

spi = spidev.SpiDev()
ret = spi.xfer2([0x1, 0x2, 0x3, 0x4])
print (ret)

I am getting a different output data than what I send:

pi@raspberrypi:~/spi $ python3 spi.py 
[0, 1, 1, 2]

May I know the reason, why is the input data not same as the output?


setting the speed to 30 MHZ worked.spi.max_speed_hz = 30000

  • 1
    From provided data, the only pattern I see it that LSB is missing in data read from. It might be a coincidence. Can you make more experiments, lower the clock perhaps? Which pins are used? Pin configuration? – domen Jan 9 at 14:52
  • 1
    I suggest you set a more sensible SPI speed. I doubt more than 30 MHz works reliably (the current setting is 125 MHz). – joan Jan 9 at 15:02
  • 1
    Pins used: 19 and 21 on GPIO Header – md.jamal Jan 9 at 15:02
  • 1
    setting the speed to 30 MHZ worked.spi.max_speed_hz = 30000 – md.jamal Jan 9 at 15:04
  • @md.jamal Please add this important information to the question's body. – M. Rostami Jan 10 at 15:00

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.