树莓派SpiDev库open方法参数含义及配置咨询
Understanding SpiDev's
open() Parameters on Raspberry Pi Let me break this down clearly for you — I’ve messed around with SPI on Raspberry Pi plenty, so this should make sense:
What do bus and device actually refer to?
bus: This is the SPI bus number on your Pi. Most modern Pi models have two SPI buses:SPI0andSPI1(older models might only haveSPI0). Each bus has its own set of clock, MOSI, and MISO pins.device: This maps to the chip select (CE) line for that bus. Each SPI bus supports up to two CE lines (CE0 and CE1), which let you connect multiple SPI devices to the same bus — you just activate the specific CE line for the device you want to talk to.
As you found in the SpiDev docs, open(X,Y) directly corresponds to the system device file /dev/spidev-X.Y — so X is your bus number, Y is your CE line number.
Setting up open() for your specific pins
Looking at your pinout:
- Your CE pin is PIN24 — this is the CE0 line for the
SPI0bus (the default primary SPI bus on Pi). - The other pins you’re using (SCLK: PIN23, MISO: PIN21, MOSI: PIN19) are all the default pins for
SPI0.
That means your open() call should be:
spi.open(0, 0)
This points to /dev/spidev-0.0, which is the correct device file for your setup. Just a quick reminder: don’t forget to enable SPI on your Pi first (you can do this via raspi-config under Interface Options > SPI).
内容的提问来源于stack exchange,提问作者user10900692
相关产品推荐
相关产品推荐

