matthieu-pi
Posts: 11
Joined: Thu Jun 25, 2015 5:44 pm

spidev vs bitbanging

Tue Jul 14, 2015 7:57 am

Hello,

I'm trying to retrive measurements of a soil sensor.
I m using a MCP3008 for that.

By checking the posts and tutorials, I ve seen that there's 2 ways of communicating with the mcp3008:
using spidev
or by bitbanging

I'm using

Code: Select all

Linux farmbeta 3.18.11+ #781 PREEMPT Tue Apr 21 18:02:18 BST 2015 armv6l GNU/Linux
Which method do you recommand ? and why ?

Thanks in advance,
Cheers
Mat

matthieu-pi
Posts: 11
Joined: Thu Jun 25, 2015 5:44 pm

Re: spidev vs bitbanging

Tue Jul 14, 2015 6:00 pm

Some good answers:
http://stackoverflow.com/questions/2079 ... plications

Should have check that before asking...

Cheers!

User avatar
joan
Posts: 14024
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: spidev vs bitbanging

Tue Jul 14, 2015 6:45 pm

matthieu-pi wrote:Some good answers:
http://stackoverflow.com/questions/2079 ... plications

Should have check that before asking...

Cheers!
Do you think so? I can't see any mention of spidev. The answers don't appear to address when you might want to use one over the other.

User avatar
sommersoft
Posts: 35
Joined: Sat Jul 11, 2015 1:43 pm
Location: Delaware, US

Re: spidev vs bitbanging

Tue Jul 14, 2015 7:53 pm

Well, that thread doesn't discuss spidev specifically, but I think it is sort of implied since the "context" covers two protocols (SPI and i2c). They seem to be discussing native MCU communication vs software communication; which as I understand would be spidev vs bit banging when discussing only SPI. I may be wrong.

I do agree however that the conversation is limited on the "when" aspect of one vs the other. For instance, if your interfacing with more than one SPI device, you either have to 1) MUX it or 2) spidev one device AND bitbang the other. This is based on RPi not having slave SPI capability. (again, I may be off on this...still learning myself)
"We mock what we don't understand." - Dr. Trowbridge

User avatar
joan
Posts: 14024
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: spidev vs bitbanging

Tue Jul 14, 2015 8:23 pm

sommersoft wrote: ...
I do agree however that the conversation is limited on the "when" aspect of one vs the other. For instance, if your interfacing with more than one SPI device, you either have to 1) MUX it or 2) spidev one device AND bitbang the other. This is based on RPi not having slave SPI capability. (again, I may be off on this...still learning myself)
The Python spidev module uses the underlying Linux SPI driver.

The Linux SPI driver on the Pi supports the main SPI peripheral which has two slave selects.

There is another SPI peripheral on recent Pis which is currently not supported by the Linux SPI driver. This auxiliary peripheral has three slave selects.

Support for both peripherals as well as arbitrary gpios used as slave selects is slowly moving through the Linux kernel review process.

So currently recent Pis support a total of 5 connected SPI devices, although only two have kernel support.

The Pi always acts as a SPI and I2C bus master (not quite true, but near enough). I.e. it does not act as a slave device, it talks to slave devices.

User avatar
sommersoft
Posts: 35
Joined: Sat Jul 11, 2015 1:43 pm
Location: Delaware, US

Re: spidev vs bitbanging

Tue Jul 14, 2015 9:08 pm

joan wrote:The Python spidev module uses the underlying Linux SPI driver.

The Linux SPI driver on the Pi supports the main SPI peripheral which has two slave selects.

There is another SPI peripheral on recent Pis which is currently not supported by the Linux SPI driver. This auxiliary peripheral has three slave selects.

Support for both peripherals as well as arbitrary gpios used as slave selects is slowly moving through the Linux kernel review process.

So currently recent Pis support a total of 5 connected SPI devices, although only two have kernel support.

The Pi always acts as a SPI and I2C bus master (not quite true, but near enough). I.e. it does not act as a slave device, it talks to slave devices.
See..this is what happens when I speak before re-reading stuff I read at 1AM. :lol:

Thank you joan. After getting back onto the SPI doc page (https://www.raspberrypi.org/documentati ... /README.md), I see how confusing master and slave support was throwing me off (remembering MOSI and MISO definitions would've helped me).

I'll have to look into this 5 SPI devices stuff. No need to paste links; I'm a Jedi at search. Remembering...that's another story.
"We mock what we don't understand." - Dr. Trowbridge

krishnaiah.vv
Posts: 19
Joined: Wed Jun 24, 2015 7:34 am

Re: spidev vs bitbanging

Tue Jul 28, 2015 3:31 pm

joan wrote:
sommersoft wrote: ...
I do agree however that the conversation is limited on the "when" aspect of one vs the other. For instance, if your interfacing with more than one SPI device, you either have to 1) MUX it or 2) spidev one device AND bitbang the other. This is based on RPi not having slave SPI capability. (again, I may be off on this...still learning myself)
The Python spidev module uses the underlying Linux SPI driver.

The Linux SPI driver on the Pi supports the main SPI peripheral which has two slave selects.

There is another SPI peripheral on recent Pis which is currently not supported by the Linux SPI driver. This auxiliary peripheral has three slave selects.

Support for both peripherals as well as arbitrary gpios used as slave selects is slowly moving through the Linux kernel review process.

So currently recent Pis support a total of 5 connected SPI devices, although only two have kernel support.

The Pi always acts as a SPI and I2C bus master (not quite true, but near enough). I.e. it does not act as a slave device, it talks to slave devices.
... Hi Sommersoft, I'm also currently looking for configuring SPI as slave in Pi. Did u already find a way to do it?
I find something here @ http://tylernichols.me/raspberry-pi-bar ... spi-slave/

Return to “Advanced users”