garymarks
Posts: 6
Joined: Wed Apr 10, 2013 4:43 am
Location: Fremont, CA
Contact: Website

SPI Command-line Utility

Thu Apr 11, 2013 5:23 am

iP Solutions (http://ipsolutionscorp.com) has created a Serial Peripheral Interface (SPI) command-line utility for the Raspberry Pi platform. The utility, spincl, is licensed under Open Source GNU GPLv3 and is being offered by iP Solu­tions as a free down­load with source included: http://ipsolutionscorp.com/raspberry-pi-spi-utility/.

Although a C library exists for the Broadcom bcm2835 with an SPI Application Programming Interface (API) among other things, there are reasons to have a command-line utility, which can be invoked from a shell command line or from within a script. A command-line utility allows easy testing and debugging of SPI slave devices without having to develop a C executable. Additionally, it provides a simple way for bash and python scripts to access the SPI master of the BCM2835 on Raspberry Pi. Although the raspian distribution provides GPIO libraries with the included python installation it doesn't include an SPI library. spincl, on the other hand, can be invoked from a python (or bash) script.
Gary Marks
iP Solutions Corp.

xorrbit
Posts: 2
Joined: Wed May 08, 2013 4:47 pm
Location: Winnipeg, Canada
Contact: Website

Re: SPI Command-line Utility

Wed May 08, 2013 5:08 pm

This looks handy and this is something I feel is missing from the Python RPIO library.

I can see the value in testing with a console application but in order to be truly useful it would need to be able to be added to a Python app as a library. Are there any plans to contribute a SPI module to the RPIO library or provide bindings to use your implementation from Python directly somehow?

Thanks!
software craftsman | hardware hacker | open source advocate

dhal
Posts: 1
Joined: Wed May 08, 2013 9:05 pm

Re: SPI Command-line Utility

Wed May 08, 2013 11:12 pm

xorrbit wrote:This looks handy and this is something I feel is missing from the Python RPIO library.

I can see the value in testing with a console application but in order to be truly useful it would need to be able to be added to a Python app as a library. Are there any plans to contribute a SPI module to the RPIO library or provide bindings to use your implementation from Python directly somehow?

Thanks!
Here is a code snippet showing how to use the command-line program spincl directly from Python:
###
import commands

#path to the SPI command-line program, "spincl"
spinclPath = '/home/developer/csource/spincl'

#Show spincl usage
print commands.getoutput(spinclPath)

#spi begin enables RPi SPI interface
commands.getoutput(spinclPath + ' -ib')

#write 32 bit string of 1's with SPI mode = 3, clock frequency divider = 5,
#use SPI CS0, chip select active low, transmit 4 bytes full duplex
commands.getoutput(spinclPath + ' -m3 -c5 -s0 -p0 4 0xFF 0xFF 0xFF 0xFF')

#transmit 1 byte and read back 1 byte (full duplex)
res = commands.getoutput(spinclPath + ' -m3 -c5 -s0 -p0 1 0x00')
print res

#Disable SPI (may not want to do this as the SPI interface
#puts the chip select pins CS0 and CS1 into the INPUT state)
commands.getoutput(spinclPath + ' -ie')
###

garymarks
Posts: 6
Joined: Wed Apr 10, 2013 4:43 am
Location: Fremont, CA
Contact: Website

Re: SPI Command-line Utility

Thu May 09, 2013 12:40 am

Yes, it's the fact that there is no SPI API in the Python RPIO that motivated me to create the utility. My colleague, who is foremost a circuit designer, uses Python as his language of first choice. He invokes the SPI utility from within his Python scripts. For example:

commands.getoutput(spiPath + ' -m3 -c5 -s0 -p0 1 0x03')

We have established a "leap-frog" approach to hardware/software development over the years that is especially suited to embedded Linux. He may incorporate the SPI utility within Python scripts that he used to develop/debug higher-level protocol to SPI-driven peripheral chips. I may then reference the Python scripts to develop higher-level utilities/executables ... and so on.

By the way, I have asked him to also post a reply to this thread (he may have already done it).

We have not discussed creating a Python SPI module, but we may now consider it. Thank you.
Gary Marks
iP Solutions Corp.

garymarks
Posts: 6
Joined: Wed Apr 10, 2013 4:43 am
Location: Fremont, CA
Contact: Website

Re: SPI Command-line Utility

Tue May 21, 2013 10:41 pm

A new update to the SPI command utility is now available.
Check http://ipsolutionscorp.com/raspberry-pi-spi-update/
as well as the original link: http://ipsolutionscorp.com/raspberry-pi-spi-utility/ for the latest version.

The following items are included in the update:
  • - Bug Fix: A bug in the way the number of transmit bytes was calculated has been fixed. Previously, if the total byte length of the transfer was greater than the number of specified xmit bytes then an attempt to access command-line arguments beyond the number available would occur, which causes a segmentation fault.
    - suid bit is now set in the install target of Makefile.
Gary Marks
iP Solutions Corp.

garymarks
Posts: 6
Joined: Wed Apr 10, 2013 4:43 am
Location: Fremont, CA
Contact: Website

Re: SPI Command-line Utility

Wed Jul 31, 2013 10:30 pm

A new version the SPI command utility, 1.3.1, is now available.
Check http://ipsolutionscorp.com/raspberry-pi ... available/
as well as the original link: http://ipsolutionscorp.com/raspberry-pi-spi-utility/ for the latest version.

The following items are included in the update:
- This version was built with the bcm2835-1.25 library. All previous versions were built with bcm2835-17.
- This version was tested on 2013-02-09 raspian wheezy. The 2012-10-28 raspian wheezy was used for testing all previous versions.
Gary Marks
iP Solutions Corp.

Andario
Posts: 2
Joined: Wed Aug 28, 2013 7:05 pm
Location: Buchloe / Germany

Re: SPI Command-line Utility

Wed Aug 28, 2013 7:12 pm

Hi Gary,

I'd really love to try the SPI command line tool, since it sounds like exactly the kind of thing I'm looking for, however when I follow your link I only get a 404 error, or when I click the Download button on your page it says that the file does not exist.
Maybe you can check on this, since the description sounds really promising!

Kind regards,
Andario

garymarks
Posts: 6
Joined: Wed Apr 10, 2013 4:43 am
Location: Fremont, CA
Contact: Website

Re: SPI Command-line Utility

Wed Aug 28, 2013 11:45 pm

Andario,

Thank you for pointing this out. I'm not sure why, but the file is not where it should be. I'll fix it and let you know when it's ready. Sorry for the inconvenience.

Gary Marks
iP Solutions Corp.
Gary Marks
iP Solutions Corp.

garymarks
Posts: 6
Joined: Wed Apr 10, 2013 4:43 am
Location: Fremont, CA
Contact: Website

Re: SPI Command-line Utility

Wed Aug 28, 2013 11:54 pm

Andario,

It should work now. There was an error in the url that was injected a while back when was moving some directories around. I thought that I had tested that. Again, sorry for the inconvenience.
Gary Marks
iP Solutions Corp.

Andario
Posts: 2
Joined: Wed Aug 28, 2013 7:05 pm
Location: Buchloe / Germany

Re: SPI Command-line Utility

Thu Aug 29, 2013 8:27 pm

Hello Gary,
the download works now! Thanks alot, I will try it over the weekend and will write a little about my experiences here in this thread.

Kind regards and thanks again,
Andario

phil98
Posts: 1
Joined: Sun Jan 03, 2016 10:06 pm

Re: SPI Command-line Utility

Sun Jan 03, 2016 11:13 pm

I everybody
I just buy a rasperry,and I would connect a lcd 2x16 with spi interface(KS0074 chipset) . I'v used it a long time ago with basicstamp without problem
so i try to use the spincl library.
I'v made some test in command line but It doesn't really work
I think I have 2 sort of problems.
The first on is that my lcd it's 5v logic so i'm waiting to receive a level shifter i'v found here
http://shop.mchobby.be/breakout/131-con ... results=28
For my first try , i'v connected only (MOSI pin 19,CLK pin 23 ,and CE0 pin 24 ) lines like i do with basicstamp and to protect also my new raspberry
When i try to send some cmd in bash like that (01 reset, 0C display on, and 0D cursor blink), my lcd need LSB first and low CS
sudo ./spincl -ib -s0 -c12 -p0 3 0x01 0x0C 0x0D
sudo ./spincl -ib -s0 -c12 -p0 3 0x10 0xC0 0xD0
sudo ./spincl -m0 -c15 -p0 2 0x1f 0x01

I'v try several clock divider
nothing happen and command not finished, and I don't have prompt back so I'v made CtrlC to break it
So I would like to know, apart from the logic level pb, is it possible to only write data to slave without connecting MISO, Is this mode the mode 0 which is not explained in the README (only 3 exemple for mode 1,2 and 3)
is there a way to test the spincl commande without slave by connecting MISO to MOSI like i see in a lot of forum without danger for my Pi
And at last what do the -i [begin|end] options

Thanks a lot for you help

Sorry for my english :oops:

Return to “General discussion”