Topi39
Posts: 1
Joined: Wed Dec 03, 2014 10:04 am

using spi with wiringpi or spidev

Wed Dec 03, 2014 10:23 am

I have two devices connected to my Pi; a CAN Controller (CE0) and ADC (CE1) both are connected to RPI with a level shift, so it won't harm the RPI.
I tried to send/receive any data to the SPI devices trying with spidev module and the other time with the wiringpi2 module but I wasn't able to get/send any data. I also miss some good documentation on both modules explaining how to use this libraries. Does anybody know how to setup this right?

Code I used with spidev (only ADC)

Code: Select all

import time
import spidev
import struct

#ADC konfigurieren
spi.open(0,1)                   #Open SPI for ADC
spi.max_speed_hz = 8000000      #set max Bus-Speed
spi.bits_per_word = 8           #set number of bits
spi.mode = 0b00                 #set clock polarity and phase
spi.close()

 #ADC
spi.open(0,1)                   #Open SPI for ADC
       
spi.xfer2([0x84])               #sent Bytes to ADC for CH1
s = spi.readbytes(2)
print (s)
spi.close()
And the Code I use with wiringpi2(only ADC):

Code: Select all

import wiringpi2 as wiringpi

wiringpi.wiringPiSetupPhys()

wiringpi.wiringPiSPISetup(1, 2000000)
CH1 = wiringpi.wiringPiSPIDataRW(1, 0x84, 8)

print (CH1)

RetiredProgrammer
Posts: 14
Joined: Sat Jan 10, 2015 10:42 pm

Re: using spi with wiringpi or spidev

Wed Jan 14, 2015 3:12 am

I have used the SPI interface with the MCP3208 ADC. What ADC are you using? An 8MHz clock sounds like you have very high performance ADC. What is your test circuit (what are you trying to read)? Best to start with some know voltages so you can verify everything else is working.

Return to “Python”