Page 1 of 1

SPI read and write

Posted: Sun Aug 06, 2017 12:23 am
by Jinlu8591
We used spi on a banana pi to interface with a sensor module. I used spidev there, and needed to load spi-sun7i.ko module. Everything worked there. See spidev examples for banana pi.

I want to switch to nanopi neo air and port the application that interfaces with spi. I had difficulties. First, I did not find spi-sun7i.ko in the kernel, although I can see /dev/spidev0.0 . I installed WiringNP on my nanopi neo air board, and looked at some examples there. One example requires you run "gpio load spi", and that returns "can't find spi-sun7i.." . I compiled some simple spi test code following the examples and run without spi-sun7i, and failed to get correct result.

Please help and let me know how I can communicate with nanopi spi. Greatly appreciated.

Re: SPI read and write

Posted: Mon Aug 07, 2017 3:28 pm
by Jinlu8591
Some additional information.

I am using Ubuntu core 3.4.xx coming with the nanapi neo air unit. It has /dev/spidev0.0. That means spi driver is in the kernel.

I wonder if the driver works properly? Has anyone verified it?

Here is my finding:

I have a simple spi test program I used to communicate with a spi slave. The slave is using mode 0, so I set the master mode to 0 and and speed to 1mbps. The test program works when running it on a banana pi unit communicating with the slave. But on the nanapi neo air, the data master reads from the slave has one bit off, meaning, 0x3 become 0x6, 0x1 becomes 0x2, etc. Digital scope shows the 4 lines are in expected format. It appeared the phase handling, that is sampling of data on which edge could be wrong. Can someone shed light to the issue? Thanks a lot.

Re: SPI read and write

Posted: Thu Sep 28, 2017 1:10 am
by elecdashtron
Yep i can confirm it works. I have tested it on
    Nano Pi Neo Air
    Nano Pi Duo
    Nano Pi Neo Plus 2
Have a look at my Neopixel library Look inside the "Nano Pi Neo Air" directory for a C++ example of how to use SPIDEV
I have tested it to 20mhz, it probably goes faster But i have never needed it.

Re: SPI read and write

Posted: Sat Oct 07, 2017 5:49 pm
by Jinlu8591
Thx. Yes. Spi on nanopi works. Somehow the spi slave I was using had a little problem.

Re: SPI read and write

Posted: Thu Nov 30, 2017 7:45 pm
by sashok1337
Does anybody tried to change SPI mode (exactly SPI_CPOL (Clock polarity) and SPI_CPHA (Clock phase) ) ? All my attemps were unsuccessfull :(
I tried both WiringNP (mode 0, 3) and native spidev_test.c (written by Anton Vorontsov) (with flags -HO and without them) - I've got same results on my logic analizator.

Device - NanoPi NEO2, Ubuntu 16.04.3 LTS xenial