Pages

Monday, May 13, 2013

spidev_test compilation and execution problem


For I2C MCP23017, I used something called i2cdetect to make sure that linux finds the device.  So I thought there should be a similar thing called spidetect. 

Indeed I found the something called spidev_test.

I downloaded the program (This time I know the command to use is wget.  Last time when I played with Guzunty, I did not know how to download in lunux, so I switched to Windows and did the Windows way of download and then the Windows way to detar, ..., taking me so much time!)

But when I complied the spidev.c there was a compilation error and I did not know how to fix it.  So I download another spidev_test.c.  This time I could compile it, but I could not run it.  I used WinSCP to set the executive rights but still could not execute it.  I used other tricks like sudo su to switch to root, and use path thing like "./xxx" but still no luck.

So I got into a stupid linux newbie trap and wasted 1 hour!

Lunch time!

********************************************************************************


# cat spidev_test.sh
wget http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git\;a=blob_plain\;f=Documentation/spi/spidev_test.c -O 



$ gcc spidev_test.c -o spidev_test

$ ls

fl2070.py  fl2072d.py  fl2073.py  fl2076.py  spidev_test    spidev_test.sh
fl2071.py  fl2072.py   fl2075.py  fl2077.py  spidev_test.c



root@raspberrypi:/home/pi/python_programs/test_eeprom

# cat spidev_test.sh
wget http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git\;a=blob_plain\;f=Documentation/spi/spidev_test.c -O 
spidev_test.croot@raspberrypi:/home/pi/python_programs/test_eeprom#

n as: pi
pi@192.168.1.40's password:
Access denied
pi@192.168.1.40's password:
Linux raspberrypi 3.2.27+ #250 PREEMPT Thu Oct 18 19:03:02 BST 2012 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun May 12 07:00:48 2013 from tlfongpc01.zyxel.com
pi@raspberrypi ~ $ cd python_programs
pi@raspberrypi ~/python_programs $ cd test_eeprom
pi@raspberrypi ~/python_programs/test_eeprom $ ls
fl2070.py  fl2071.py  fl2072d.py  fl2072.py  fl2073.py  fl2075.py  fl2076.py  fl2077.py
pi@raspberrypi ~/python_programs/test_eeprom $ wget www.kernel.ord/doc/Documentation/spi/spidev_test.c
--2013-05-13 03:31:38--  http://www.kernel.ord/doc/Documentation/spi/spidev_test.c
Resolving www.kernel.ord (www.kernel.ord)... 203.198.80.62
Connecting to www.kernel.ord (www.kernel.ord)|203.198.80.62|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 168 [text/html]
Saving to: `spidev_test.c'

100%[=========================================================>] 168         --.-K/s   in 0s

2013-05-13 03:31:38 (2.36 MB/s) - `spidev_test.c' saved [168/168]

pi@raspberrypi ~/python_programs/test_eeprom $ ls
fl2070.py  fl2072d.py  fl2073.py  fl2076.py  spidev_test.c
fl2071.py  fl2072.py   fl2075.py  fl2077.py
pi@raspberrypi ~/python_programs/test_eeprom $ gcc spidev_test.c -o spidec_test
spidev_test.c:1:1: error: expected identifier or ‘(’ before ‘<’ token
spidev_test.c:1:14: warning: character constant too long for its type [enabled by default]
spidev_test.c:1:50: warning: character constant too long for its type [enabled by default]
pi@raspberrypi ~/python_programs/test_eeprom $ ls
fl2070.py  fl2072d.py  fl2073.py  fl2076.py  spidev_test.c
fl2071.py  fl2072.py   fl2075.py  fl2077.py
pi@raspberrypi ~/python_programs/test_eeprom $ gcc spidev_test.c -o spidev_test
spidev_test.c:1:1: error: expected identifier or ‘(’ before ‘<’ token
spidev_test.c:1:14: warning: character constant too long for its type [enabled by default]
spidev_test.c:1:50: warning: character constant too long for its type [enabled by default]
pi@raspberrypi ~/python_programs/test_eeprom $ ^C
pi@raspberrypi ~/python_programs/test_eeprom $ ls
fl2070.py  fl2072d.py  fl2073.py  fl2076.py  spidev_test.c
fl2071.py  fl2072.py   fl2075.py  fl2077.py  spidev_test.sh
pi@raspberrypi ~/python_programs/test_eeprom $ sudo spidev_test.sh
sudo: spidev_test.sh: command not found
pi@raspberrypi ~/python_programs/test_eeprom $ sudo ./spidev_test.sh
--2013-05-13 03:43:09--  http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob_plain;f=Documentation/spi/spidev_test.c
Resolving git.kernel.org (git.kernel.org)... 198.145.20.140, 149.20.4.72
Connecting to git.kernel.org (git.kernel.org)|198.145.20.140|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/plain/Documentation/spi/spidev_test.c [following]
--2013-05-13 03:43:10--  http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/plain/Documentation/spi/spidev_test.c
Reusing existing connection to git.kernel.org:80.
HTTP request sent, awaiting response... 200 OK
Length: 4410 (4.3K) [text/plain]
Saving to: `spidev_test.c'

100%[=========================================================>] 4,410       --.-K/s   in 0s

2013-05-13 03:43:10 (31.4 MB/s) - `spidev_test.c' saved [4410/4410]

pi@raspberrypi ~/python_programs/test_eeprom $ ls
fl2070.py  fl2072d.py  fl2073.py  fl2076.py  spidev_test.c
fl2071.py  fl2072.py   fl2075.py  fl2077.py  spidev_test.sh
pi@raspberrypi ~/python_programs/test_eeprom $ gcc spidec_test.c -o spidev_test
gcc: error: spidec_test.c: No such file or directory
gcc: fatal error: no input files
compilation terminated.
pi@raspberrypi ~/python_programs/test_eeprom $ gcc spidev_test.c -o spidev_test
pi@raspberrypi ~/python_programs/test_eeprom $ ls
fl2070.py  fl2072d.py  fl2073.py  fl2076.py  spidev_test    spidev_test.sh
fl2071.py  fl2072.py   fl2075.py  fl2077.py  spidev_test.c
pi@raspberrypi ~/python_programs/test_eeprom $ spidev_test
-bash: spidev_test: command not found
pi@raspberrypi ~/python_programs/test_eeprom $ sudo spidev_test
sudo: spidev_test: command not found
pi@raspberrypi ~/python_programs/test_eeprom $ sudo ./spidev_test
can't open device: No such file or directory
pi@raspberrypi ~/python_programs/test_eeprom $ ls
fl2070.py  fl2072d.py  fl2073.py  fl2076.py  spidev_test    spidev_test.sh
fl2071.py  fl2072.py   fl2075.py  fl2077.py  spidev_test.c
pi@raspberrypi ~/python_programs/test_eeprom $ spidev_test
-bash: spidev_test: command not found
pi@raspberrypi ~/python_programs/test_eeprom $ spidev_test
-bash: spidev_test: command not found
pi@raspberrypi ~/python_programs/test_eeprom $ ls
fl2070.py  fl2072d.py  fl2073.py  fl2076.py  spidev_test    spidev_test.sh
fl2071.py  fl2072.py   fl2075.py  fl2077.py  spidev_test.c
pi@raspberrypi ~/python_programs/test_eeprom $ sudo spidev_test
sudo: spidev_test: command not found
pi@raspberrypi ~/python_programs/test_eeprom $ sudo ./spidev_test
can't open device: No such file or directory
pi@raspberrypi ~/python_programs/test_eeprom $ sudo ./spidev_test
can't open device: No such file or directory
pi@raspberrypi ~/python_programs/test_eeprom $ ls
fl2070.py  fl2072d.py  fl2073.py  fl2076.py  spidev_test    spidev_test.sh
fl2071.py  fl2072.py   fl2075.py  fl2077.py  spidev_test.c
pi@raspberrypi ~/python_programs/test_eeprom $ sudo su
root@raspberrypi:/home/pi/python_programs/test_eeprom# spidev_test
bash: spidev_test: command not found
root@raspberrypi:/home/pi/python_programs/test_eeprom# ./spidev_test
can't open device: No such file or directory
Aborted
root@raspberrypi:/home/pi/python_programs/test_eeprom# sudo ./spidev_test
can't open device: No such file or directory
root@raspberrypi:/home/pi/python_programs/test_eeprom# sudo ./spidev_test
can't open device: No such file or directory
root@raspberrypi:/home/pi/python_programs/test_eeprom# sudo spidev_test
sudo: spidev_test: command not found
root@raspberrypi:/home/pi/python_programs/test_eeprom# spidev_test
bash: spidev_test: command not found
root@raspberrypi:/home/pi/python_programs/test_eeprom# cat spidev_test.sh
wget http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git\;a=blob_plain\;f=Documentation/spi/spidev_test.c -O spidev_test.croot@raspberrypi:/home/pi/python_programs/test_eeprom#

+osted on February 20, 2013

In my previous post, I described how to get SPI working on my Raspberry Pi. Now I wanted to check if it actually works.

I found a useful description on the web, but used only the second part about “testing”: http://www.brianhensley.net/2012/07/getting-spi-working-on-raspberry-pi.html

Given that the linux kernel module dealing with SPI is loaded, there is a small test application written in C that you need to download:

pi@raspberrypi ~ $ wget http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git\;a=blob_plain\;f=Documentation/spi/spidev_test.c -O spidev_test.c

In spidev_test.c, change the following line

static const char *device = "/dev/spidev1.1";
to
static const char *device = "/dev/spidev0.0";
Now compile the C source code using gcc:
gcc spidev_test.c -o spidev_test
Run the test application:
pi@raspberrypi ~ $ sudo ./spidev_test
spi mode: 0 
bits per word: 8
max speed: 500000 Hz (500 KHz) 
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00
Now connect the MISO and MOSI pins and execute this test application again:
pi@raspberrypi ~ $ sudo ./spidev_test
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)
FF FF FF FF FF FF 
40 00 00 00 00 95 
FF FF FF FF FF FF 
FF FF FF FF FF FF 
FF FF FF FF FF FF 
DE AD BE EF BA AD 
F0 0D
Looks good! This is what we expect.



) Test SPI
Download the spidev_test.c source and compile it:

$ gcc spidev_test.c -o spidev_test
$ sudo ./spidev_test -D /dev/spidev0.0
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)

00 00 00 00 00 00 
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00


Linux/drivers/spi/spidev.cwget

http://lxr.free-electrons.com/source/drivers/spi/spidev.c

https://www.kernel.org/doc/Documentation/spi/spidev_test.c


pi@raspberrypi ~/python_programs/test_eeprom $ wget www.kernel.ord/doc/Documentation/spi/spidev_test.c
--2013-05-13 03:31:38--  http://www.kernel.ord/doc/Documentation/spi/spidev_test.c
Resolving www.kernel.ord (www.kernel.ord)... 203.198.80.62
Connecting to www.kernel.ord (www.kernel.ord)|203.198.80.62|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 168 [text/html]
Saving to: `spidev_test.c'

100%[=========================================================>] 168         --.-K/s   in 0s

2013-05-13 03:31:38 (2.36 MB/s) - `spidev_test.c' saved [168/168]

pi@raspberrypi ~/python_programs/test_eeprom $ ls
fl2070.py  fl2072d.py  fl2073.py  fl2076.py  spidev_test.c
fl2071.py  fl2072.py   fl2075.py  fl2077.py
pi@raspberrypi ~/python_programs/test_eeprom $ gcc spidev_test.c -o spidec_test
spidev_test.c:1:1: error: expected identifier or ‘(’ before ‘<’ token
spidev_test.c:1:14: warning: character constant too long for its type [enabled by default]
spidev_test.c:1:50: warning: character constant too long for its type [enabled by default]
pi@raspberrypi ~/python_programs/test_eeprom $ ls
fl2070.py  fl2072d.py  fl2073.py  fl2076.py  spidev_test.c
fl2071.py  fl2072.py   fl2075.py  fl2077.py
pi@raspberrypi ~/python_programs/test_eeprom $ gcc spidev_test.c -o spidev_test
spidev_test.c:1:1: error: expected identifier or ‘(’ before ‘<’ token
spidev_test.c:1:14: warning: character constant too long for its type [enabled by default]
spidev_test.c:1:50: warning: character constant too long for its type [enabled by default]
pi@raspberrypi ~/python_programs/test_eeprom $


7) Test SPI
Download the spidev_test.c source and compile it:
1
2
3
4
5
6
7
8
9
10
11
12
13
$ gcc spidev_test.c -o spidev_test
$ sudo ./spidev_test -D /dev/spidev0.0
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)

00 00 00 00 00 00 
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00 00 00 00 00 
00 00

.END

No comments:

Post a Comment