SPI Bit-Bang with BBIO don't work

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
terjefroysa
 
Posts: 3
Joined: Wed Aug 06, 2014 5:06 am

SPI Bit-Bang with BBIO don't work

Post by terjefroysa »

Hello Forum,
I'm up against the wall in this subject.
I have now used BBIO for verifying a new cape with a lot of GPIO, USARTs, I2C and SPI lines.
I have successfully used Adafruit BBIO to verify all GPIO lines that are by default free-to-use GPIOs.

But I fail to test the SPI lines by configuring them as GPIO (bit-bang) by Adafruit_BBIO.
The GPIO lines in question can be manually manipulated and programmed in C according to this example:
http://learnbuildshare.BANNED.com/20 ... tal-ouput/
I read from the forum that the Adafruit_BBIO uses same methods, but it won't work with the lines in question.

Please see informatioin below.

Please advice
Best regards
Terje Froysa
----------------------info--------------------------------------------
Running system: Debian GNU/Linux 7.6 (wheezy)

Latest Adafruit_BBIO:
sudo python -c "import Adafruit_BBIO.SPI as SPI; print SPI"
<module 'Adafruit_BBIO.SPI' from '/root/.python-eggs/Adafruit_BBIO-0.0.20-py2.7-linux-armv7l.egg-tmp/Adafruit_BBIO/SPI.so'>
sudo python -c "import Adafruit_BBIO.GPIO as GPIO; print GPIO"
<module 'Adafruit_BBIO.GPIO' from '/root/.python-eggs/Adafruit_BBIO-0.0.20-py2.7-linux-armv7l.egg-tmp/Adafruit_BBIO/GPIO.so'>


Disabled HDMI interface:
0: 54:PF---
1: 55:PF---
2: 56:PF---
3: 57:PF---
4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
5: ff:P-O-- Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI
6: ff:P-O-- Bone-Black-HDMIN,00A0,Texas Instrument,BB-BONELT-HDMIN

Verifying pins available as GPIO:
/sys/kernel/debug/pinctrl/44e10800.pinmux/pinmux-pins:
pin 100 (44e10990): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 101 (44e10994): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 102 (44e10998): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 103 (44e1099c): (MUX UNCLAIMED) (GPIO UNCLAIMED)
/sys/kernel/debug/pinctrl/44e10800.pinmux/pins:
pin 100 (44e10990) 00000027 pinctrl-single
pin 101 (44e10994) 00000027 pinctrl-single
pin 102 (44e10998) 00000027 pinctrl-single
pin 103 (44e1099c) 00000027 pinctrl-single

Manual GPIO check:

cd /sys/class/gpio
echo 110 > export
echo 111 > export
echo 112 > export
echo 113 > export
echo "out" > ./gpio110/direction
echo "out" > ./gpio111/direction
echo "out" > ./gpio112/direction
echo "out" > ./gpio113/direction
echo 1 > ./gpio110/value
echo 1 > ./gpio111/value
echo 1 > ./gpio112/value
echo 1 > ./gpio113/value
echo 0 > ./gpio110/value
echo 0 > ./gpio111/value
echo 0 > ./gpio112/value
echo 0 > ./gpio113/value
Measuring on I/O pins and verified that all SPI lines could be set high and low.

Writing the Python test script (see below).
Measuring the I/O lines with an oscilloscope while script was running.
Lines did not toggle.
------------------------------
#!/usr/local/bin/python

import Adafruit_BBIO.GPIO as GPIO
import time
import serial
import sys

GPIO.setup("GPIO3_14",GPIO.OUT) #SPI1 SCLK
GPIO.setup("GPIO3_17",GPIO.OUT) #SPI1 CS0
GPIO.setup("GPIO3_15",GPIO.OUT) #SPI1 D0
GPIO.setup("GPIO3_16",GPIO.OUT) #SPI1 D1
GPIO.output("GPIO3_14",GPIO.LOW)
GPIO.output("GPIO3_17",GPIO.LOW)
GPIO.output("GPIO3_15",GPIO.LOW)
GPIO.output("GPIO3_16",GPIO.LOW)
for x in range(1,10000):
time.sleep(0.2)
GPIO.output("GPIO3_14",GPIO.HIGH)
GPIO.output("GPIO3_17",GPIO.HIGH)
GPIO.output("GPIO3_15",GPIO.HIGH)
GPIO.output("GPIO3_16",GPIO.HIGH)
sys.stdout.write('H')
sys.stdout.flush()
time.sleep(0.2)
GPIO.output("GPIO3_14",GPIO.LOW)
GPIO.output("GPIO3_17",GPIO.LOW)
GPIO.output("GPIO3_15",GPIO.LOW)
GPIO.output("GPIO3_16",GPIO.LOW)
sys.stdout.write('L')
sys.stdout.flush()

GPIO.cleanup()

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: SPI Bit-Bang with BBIO don't work

Post by adafruit_support_mike »

Did you run the script using `sudo` or as root? Most versions of Linux have permissions limits on access to the GPIO pins.

User avatar
terjefroysa
 
Posts: 3
Joined: Wed Aug 06, 2014 5:06 am

Re: SPI Bit-Bang with BBIO don't work

Post by terjefroysa »

Thanks for answering!
Yes, I have tried to run the script both with 'sudo' and as root.
To be correct I have now repeated what I described with the same result.
I can manually jog the pins under /sys/class/gpio and with a C-program,
but running the script using Adafruit_BBIO gives no result.
I have used the same Adafruit_BBIO library on other pins with success.

I have one more observation:
The C-program in the referred example failed first just because it was designed to write only two siphers into the export file.
To control these pins the function that writes to the export file must write three siphers.
Only a "hand full" pins have three sipher gpio numers.
Can the Adafruit_BBIO have the same problem?

Best regards
Terje Froysa

User avatar
terjefroysa
 
Posts: 3
Joined: Wed Aug 06, 2014 5:06 am

Re: SPI Bit-Bang with BBIO don't work

Post by terjefroysa »

I have found the solution to the problem.

By studying the Adafruit_BBIO source code, I found that the gpio numer is found by "pin_t table[]" lookup in the common.c file.
The names GPIO3_14, GPIO3_15, GPIO3_16 and GPIO3_17 are not defined there and will not be recognized.
By using the defined names P9_28, P9_29, P9_30 and P9_31 instead, it all started working!

But this means that your code is missing an error message if non-defined GPIO pin names are used!

An error message would have saved me for a lot of testing and confusion.

Best regards
Terje Froysa

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: SPI Bit-Bang with BBIO don't work

Post by adafruit_support_mike »

Interesting point. I'll pass that along to the team that maintains the code.

Locked
Please be positive and constructive with your questions and comments.

Return to “Beagle Bone & Adafruit Beagle Bone products”