Hi,
I am trying to use the spi bus from Python on my Raspberry pi 2 model B and my python script just stops when I try to do an xfer2.
Background:
I have an MCP3008 hooked up to the spi bus
When I do an ls /dev I see both spidev0.0 and spidev 0.1 so I know the bus is enabled.
I have used the C spi bus loopback test that is out on the web and it runs successfully.
I have installed the python wrapper for spidev.
I am running Python 3
To debug the problem I simplified the code to the following (it is in a file called spi_testcode.py)
import sys
import spidev
print('Starting test code')
adc_channel = 7
print('initializing the spi bus instance')
spi_bus = spidev.SpiDev()
print('opening the spi bus')
spi_bus.open(0, 0)
print('getting the adc output ')
adc_output = spi_bus.xfer2(1, 8 + adc_channel << 4, 0 )
print('adc read complete')
The following is what happens when I run the code:
pi@raspberrypi: ~ software $sudo python3 spi_testcode.py
starting test code
initializing the spi bus instance
opening the spi bus
getting the adc output
pi@raspberrypi: ~ software $
Notice that final print statement of the program is never executed. The program exits during the xfer2() call with no error message or warning. Consequently it is hard to figure out what to do to debug this.... any suggestions?




