|
Basic SPI Configuration
Enabling SPI module-loading on reboot:
sudo nano /etc/modprobe.d/rasppi-blacklist.conf
给这一行前面加上 # 号注释掉:blacklist spi-bcm2708
Load SPI module now, if it wasn't loaded on boot:
sudo modprobe spi_bcm2708
也可以重新启动 sudo reboot
To make SPI accessible to default user:
sudo chown 1000.1000 /dev/spidev0.*
我没有这么做, 而是以 root 身份运行 python
Python spidev setup
sudo apt-get update
sudo apt-get install python-dev
sudo apt-get install git
cd ~
mkdir py-spidev
cd py-spidev
wget https://raw.github.com/doceme/py-spidev/master/setup.py
wget https://raw.github.com/doceme/py-spidev/master/spidev_module.c
sudo python setup.py install
两个 wget 也可以被一行指令替代
git clone git://github.com/doceme/py-spidev
测试程序
>>> import spidev
>>> spi = spidev.SpiDev()
>>> spi.open(0,0)
>>> # send a single byte, value 0xa0, and store the response. I have SPI looped back (mosi -> miso).
>>> resp = spi.xfer2([0xa0, 0x55])
>>> print resp
[160, 85]
说明
xfer2 keeps the CS active during the whole transfer, while xfer releases / re-activates CS between blocks.
can set speed with >>> spi.max_speed_hz = 16000000 #i.e. 16 Mbps
|
|