Jump to content

SPI kernel driver


aliceander

Recommended Posts

Is the SPI kernel driver enabled by default in 5.16?  If not, how can I enable it in armbian (what are the magic steps raspi-config makes to enable it in raspbian - I'd like to make the changes manually in armbian)

 

By default I can see

 

dmesg | grep spi
[    0.454454] sunxi_spi_chan_cfg()1376 - [spi-0] has no spi_regulator.
[    0.454468] sunxi_spi_chan_cfg()1376 - [spi-1] has no spi_regulator.
[    0.455034] spi spi0: master is unqueued, this is deprecated

 

ls -al /dev/spi*
crw------- 1 root root 153, 0 Jul 13 06:54 /dev/spidev0.0

 

And when I attach a multisegment MAX7219 I get the same results, as if it's not really enabled and seeing the hardware.

Link to comment
Share on other sites

SPI is working with legacy kernel starting with 5.04 (see post #268) and Martin Ayotte provided patches for mainline kernel also at around the same time. You might have to rely on external forum search (eg. asking google for 'spi h3 site:armbian.com') since our forum search is somewhat limited and prevents searching for very short terms.

Link to comment
Share on other sites

Copying the work from other threads I got something working. It's nowhere near complete, but I thought I'd share what I've found so far.

 

I have a SainSmart MAX7219 Dot Matrix Module 4-in-one attached to my Orange Pi ONE. This unit contains FOUR 8x8 LED modules cascaded together into one long unit with 5 wires coming out of the unit.

 

Hardware connections (Orange Pi One header is turned 180 degrees from the RPi orientation)

VCC connected to Pin 2 (VCC)

GND connected to Pin 4 (GND)

DIN connected to Pin 19 (GPIO 10)

CS connected to Pin 24 (GPIO 8)

CLK connected to Pin 23 (GPIO 11)

 

Start with fresh  5.14 jessie server image. Bring it up to 5.16

apt-get update

apt-get upgrade

 

git clone https://github.com/rm-hull/max7219.git

cd max7219

apt-get install python-dev python-pip

pip install spidev

python setup.py install

cd ..

 

git clone https://github.com/duxingkei33/orangepi_PC_gpio_pyH3

cd orangepi_PC_gpio_pyH3

python setup.py install

cd ..

 

git clone https://github.com/lthiery/SPI-Py.git

cd SPI-Py

python setup.py install

cd ..

 

git clone https://github.com/rasplay/MFRC522-python

 

edit MFRC522.py and comment lines 108.109.110 and 356(as shown below)

#GPIO.setmode(GPIO.BOARD)

#GPIO.setup(22, GPIO.OUT)

#GPIO.output(self.NRSTPD, 1)

 

#GPIO.output(self.NRSTPD, 1)

 

Also, in MFRC522.py comment RPi.GPIO and add pyA20.gpio as below

#import RPi.GPIO as GPIO

import pyA20.gpio as GPIO

 

Then run the read.py program.

python read.py

 

The read.py program never did anything for me as far as I could tell (no return, and I had to abort the program), but it seems to initialize "something". After I run read.py I can execute other programs on the module. I need to look closer at this program soon to figure out what it does to enable my other program to work.

 

Here's my incredible simple first program; it will scroll "Hello World!"

 

#!/usr/bin/env python

 

import max7219.led as led

 

device = led.matrix(cascaded=3)

device.orientation(90)

device.brightness(2)

device.show_message("Hello World!")

Link to comment
Share on other sites

 

edit MFRC522.py and comment lines 108.109.110 and 356(as shown below)

#GPIO.setmode(GPIO.BOARD)

#GPIO.setup(22, GPIO.OUT)

#GPIO.output(self.NRSTPD, 1)

 

#GPIO.output(self.NRSTPD, 1)

 

Also, in MFRC522.py comment RPi.GPIO and add pyA20.gpio as below

#import RPi.GPIO as GPIO

import pyA20.gpio as GPIO

 

 

 

You have to change MFRC522.py like this.
 
BEFORE
 
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
import time
 
COUNT = 3
PIN = 4
#GPIO.setmode(GPIO.BOARD)
GPIO.setmode(GPIO.BCM)
GPIO.setup(PIN,GPIO.OUT)
 
for _ in xrange(COUNT):
    GPIO.output(PIN,True)
    time.sleep(1.0)
    GPIO.output(PIN,False)
    time.sleep(1.0)
 
GPIO.cleanup()
 
 
AFTER
 
# -*- coding: utf-8 -*-
from pyA20.gpio import gpio
from pyA20.gpio import port
import time
 
COUNT = 3
PIN = port.PA6
gpio.init()
gpio.setcfg(PIN, gpio.OUTPUT)
 
for _ in xrange(COUNT):
    gpio.output(PIN,True)
    time.sleep(1.0)
    gpio.output(PIN,False)
    time.sleep(1.0)
 
#gpio.cleanup()
 
 
EDIT
This isn't the part of MFRC522.py.
This is the sample which ports python-rpi-gpio library to orangepi_PC_gpio_pyH3 library.
 
Link to comment
Share on other sites

I'm certain I'll want to bury my head in the sand from embarrassment after asking, but I can't see where to make some of the changes suggested.  I see the import, setup, and setmode changes, but I'm lost with the loop.  Is that something that needs to be added rather than updated?  I can't find the for _in xrange(COUNT) loop in the code I got from git clone for MFRC522-python.

Link to comment
Share on other sites

I'm certain I'll want to bury my head in the sand from embarrassment after asking, but I can't see where to make some of the changes suggested.  I see the import, setup, and setmode changes, but I'm lost with the loop.  Is that something that needs to be added rather than updated?  I can't find the for _in xrange(COUNT) loop in the code I got from git clone for MFRC522-python.

 

 

NRSTPD = 22 -> NRSTPD = port.PA2
GPIO.setup(22, GPIO.OUT) -> gpio.setcfg(NRSTPD, gpio.OUTPUT)
GPIO.output(self.NRSTPD, 1) -> gpio.output(self.NRSTPD, 1)
GPIO.cleanup() -> Comment Out
Link to comment
Share on other sites

In summary to my original question, nothing has to be done to make SPI available in armbian. It's ready and waiting out of the box.  I've got a set of four MAX7219 8x8 matrices working nicely now.   

 

This is different than raspbian, where it's my understanding that raspi-config needs to be run to enable SPI.

Link to comment
Share on other sites

AFAIK, nobody said that Armbian is Raspbian alike. If you want to change GPIO configuration, you must edit script.bin. I think that there was agreement that one of the each type of the bus is enabled by default. So you should have at least one I2C, one SPI and one 1-wire interface working on 40 pins header without any configuration.

Link to comment
Share on other sites

You're right.  But I think my comment might be misunderstood; The only reason I mentioned raspbian is that some of us are new to armbian and have historical references in the old world. I can see where it might be seen as a slight, but that is not my intention!  I've become rather fond of armbian in the last few weeks and plan on continue to use it in the foreseeable future and sometimes I bring the old way of doing things to the new environment, even when, in this case, it's was unnecessary.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines