Python driver Raspberry Pi SPI interface purpose Raspberry Pi SPI interface Python driver troubleshooting reference tutorial

Python driver Raspberry Pi SPI interface purpose Raspberry Pi SPI interface Python driver troubleshooting reference tutorial

purpose

For IC testing, you need to use SPI to input data and collect data. Consider using Raspberry Pi to directly combine data collection and data processing into one, avoiding the error-prone data collection part (implemented by single-chip or FPGA)

Raspberry Pi SPI interface

Physical interface

Raspberry Pi hardware interface

As can be seen from the above figure, the 19, 21, and 23 of the Raspberry Pi constitute an SPI interface. The chip select signal is controlled by GPIO. This time, the automatic chip select signal is not used. In terms of speed, the interface of Raspberry Pi has the following speeds to choose from

speed

value

125.0 MHz

125000000

62.5 MHz

62500000

31.2 MHz

31200000

15.6 MHz

15600000

7.8 MHz

7800000

3.9 MHz

3900000

1953 kHz

1953000

976 kHz

976000

488 kHz

488000

244 kHz

244000

122 kHz

122000

61 kHz

61000

30.5 kHz

30500

15.2 kHz

15200

7629 Hz

7629

Turn on the SPI interface

Use the sudo raspi-configcommand to enter the configuration option and select the SPI interface, open it and restart it

Python driver

Python usagespidev libraries to drive SPI

Start and configure the SPI interface

spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 15600000

send data

def write_pot(input):
    msb = input >> 8
    lsb = input & 0xFF
    spi.xfer([msb, lsb])

troubleshooting

MOSI is not working properly

Problem description: Use a logic analyzer to test the output, and found that there are SCK signals and CS signals, and the MOSI signal is always high. Solution: Use to raspi-configturn off SPI and restart, then turn on SPI, restart, and troubleshoot (restart debug Dafa)

Reference tutorial

python-spidev website Controlling an SPI device with the Raspberry Pi

Reference: https://cloud.tencent.com/developer/article/1110603 Python driver Raspberry Pi SPI interface purpose Raspberry Pi SPI interface Python driver troubleshooting reference tutorial-Cloud + Community-Tencent Cloud