using spi and gpio
I have had difficulty using the spi bus and/or spidev on the pine rockpro 64. It is now working and this information may help others.

I am using a MAx31865 RTD temperature sensor module which connects by SPI. I have used this on my orange pi PC (allwinner H3 - 32 bit) as a spidev device which works well. But migrating to the rockpro 64 was a big problem.

On the Rockpro 64 I used the Armbian_24.2.1_Rockpro64_jammy_current_6.6.16_xfce system. This only has Spidev1.x, but it is easy to change from using spidev0.x. However I was unable to get the spidev driver working. Oscilloscope observation showed that the CS pin (header pin) h24 is not toggled at all by the spidev driver. This can be overcome by embedding GPIO write commands around the spidev access to toggle the CS line. I could then transmit and recieve data but the data was corrupt. After many attempts I concluded that the spidev driver is faulty, but i did not want to mess with the device tree. I tried a more recent Armbian bookworm system, but it also failed. I checked other systems including free-bsd, twister, manjaro, ubunto-noble and bionic but none of them have a spidev driver. I installed the bitbang driver using armbian-config, but it does not provide a device in /dev and is not useful. (I presume you need to add a param... line in /boot/Armbianenv.txt but have seen no documentation of the required param) Eventually i resorted to writing my own bitbang subroutine. This was able to correctly access the RTD temperature device. I have given up on using spidev on the rockpro 64.

I had major issues with GPIO access from my C++ code. Wiring-pi does not work on rockpro and i found armbianio. This allows gpio control, but does not have pin-mapping for the rockpro64, however I was able to add the required pin tables easily. But note that several pages describing the pin numbering have typographical errors, in particular pin h19 is actually pad 40 (wrongly shown as pad 48 in several souces). This overcomes the "doesn't work" comments on some sources. This pin is important as it is usually MOSI of the spi bus. Although armbianio has SPI routines, these do not work - because of the suspected problem in spidev.

I cannot attatch a file  - so here is the t change information for the rockpro 64 pin mappings in armbianio.  You need to add this in armbianio.c and re-make. This must be added as the first pin table as the existing pin table indexing is corrupt. You also need to add the *iPinLists and *szBoardNames items.

// Pine RockPro 64  now added as #1 to avoid original indexing mess
  static int iRockPro64Pins[] = {-1, -1, -1, 52, -1, 53, -1, 152, 148, -1, 147,
                                    54, 120, 50, -1, 33, 36, -1, 149, 40, -1,
                                    39, 153, 41, 42, -1, 45, 43, 44, 155, -1,
                                    156, 124, 125, -1, 122, 126, 121, 123, -1, 127};
=====  fix these indexing lines also
static int *iPinLists[] = {iRockPro64Pins,  ipotatoPins, iBPIZPins, iRPIPins, iOPIZPPins, iOPIZP2ins, iOPIZPins, iOPI1Pins, iOPI1Pins,
                          iNPDPins, iNP2Pins, iNPK2Pins, iNPNPins, iNPNPins, iNPNPins, iNPM4Pins, iNPM4Pins,
                          iTinkerPins, iRadxaZeroPins, iMangoPiPins};      //total 20
static const char *szBoardNames[] = {"RockPro 64\n", "Le potato\n","Banana Pi M2 Zero\n","Raspberry Pi\n","Orange Pi Zero Plus\n",
                                    "Orange Pi Zero Plus 2\n","Orange Pi Zero\n","Orange Pi Lite\n","Orange Pi One\n",
                                    "NanoPi Duo\n", "NanoPi 2\n", "Nanopi K2\n", "NanoPi Neo\n", "NanoPi Air\n",
                                    "NanoPi Neo 2\n", "NanoPi M4\n", "NanoPi M4V2\n", "Tinkerboard\n", "Radxa Zero\n",
                                    "Mango Pi Mcore\n", NULL};  //total 20
static int iBoardType;
static int iPinCount[] = {40,40,40,40,29,29,29,43,43,32,40,40,40,40,40,40,41,41,40,41}; // number of pins in the header  rockpro64-40  total 20
// GPIO number of on-board IR receiver
static int iIR_GPIO[] = {0, 7, 0, 0, 363, 363, 363, 363, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};  //kgb  zero for pine at start, total now  21  !

===== my comment regarding tables in armbianio.c
//  this is a mess with only 17 pin-tables, but a key-list (below) of 20 boards!  Only the first few seem correct. RockPro 64 is correct if put as first

Possibly Related Threads…
Thread Author Replies Views Last Post
  GPIO on the RockPro64 - all pins high? colinmarc 2 1,853 11-18-2022, 10:20 AM
Last Post: colinmarc
  GPIO Expander HAT for ROCKPro64 and Quartz64 CounterPillow 7 5,904 07-18-2022, 10:05 PM
Last Post: zer0sig
  Using GPIO interrupts antonlyap 3 3,950 06-30-2021, 01:32 PM
Last Post: antonlyap
  GPIO performance 100x slower compared to Raspberry Pi 3 axelf 9 10,281 08-19-2020, 04:41 PM
Last Post: Gienek
  GPIO in sleep mode Mentaluproar 2 3,537 04-08-2019, 03:50 PM
Last Post: Mentaluproar

Forum Jump:

Users browsing this thread: 1 Guest(s)