kgb Posted March 10, 2017 Posted March 10, 2017 I have an ADC and DAC board built for Raspberry Pi which has 2 slaves on the SPI bus, requiring ce0 and ce1. This works fine on the Raspberry pi 3, which installs devices /dev/spidev0.0 and also /dev/spidev/0.1, to access each slave. On the OPi PC I can access slave 0, but not slave 1. In /dev on the Opi there is only a single spidev device: /dev/spidev0.0 and no spidev0.1 device. I have modified the script.bin (I am using Armbian legacy OS - Armbian_5.14_Orangepipc_Debian_jessie_3.4.112_desktop) by editing the .fex (and making a new script.bin) to add a spi_cs1 = port:PC07<3><default><default><default> line. But adding this prevents any spidev device from loading, even spidev0.0 is now missing. I have tried many variations to add a spi_cs1 connection in the fex file, but nothing works. the OPi pinout description includes SPI-CE1 (header pin 26) but how can i make this active? How can I make the spi system on the OPi PC work with 2 slave devices on the bus as the rasberry pi does easily? Is this an issue with the armbian OS, the fex file configuration, or a hardware issue with the OPi PC. I read that there is an issue with SPI on the OPi One - but does this problem with NAND access also affect the OPi PC?
kgb Posted March 18, 2017 Author Posted March 18, 2017 I have solved my problem above by manually selecting each of the 2 slave devices by using 2 spare gpio pins as outputs and using digitalWrite(...) to select the desired slave device before then accessing either device through the single spi driver - /dev/spidev0.0 Its a bit of a kludge, but works. I suspect the problem is that the kernel module fails to allow for multiple slaves on a single spi bus.
Oskar Blecha Posted April 2, 2017 Posted April 2, 2017 Sorry for stealing topic, but my question is the same. Is it possible to use two slave devices on one SPI in mainline kernel? If i have modified armbianenv.txt and i can use only spi0.1 or spi.0.0 but not both together. overlays=spi-spidev spi-add-cs1 param_spidev_spi_bus=0 param_spidev_spi_cs=1 makes /dev/spidev0.1 Is it possible doing this only with dtb or do I need modify spi driver? Sorry for newbie post.... mira
zador.blood.stained Posted April 2, 2017 Posted April 2, 2017 1 minute ago, Oskar Blecha said: Is it possible doing this only with dtb or do I need modify spi driver? It's possible but you need to write your own overlay. Provided overlays can activate only one device of each type.
kgb Posted April 11, 2017 Author Posted April 11, 2017 Checkout the code solution from nopnop2002 at orange pi forum here http://www.orangepi.org/orangepibbsen/forum.php?mod=viewthread&tid=2549&extra=
Oskar Blecha Posted April 15, 2017 Posted April 15, 2017 thank you for responses. i've found sun8i-h3-spi-double-spidev.dts and used is as template. + sun8i-h3-spi-add-cs1.dts + ads7846-overlay.dts (from pi, modified for armbian) and waveshare 3.2 + touch is working
ldiaz Posted April 15, 2017 Posted April 15, 2017 Very interesting Oskar. I've been playing about with spi tfts too on orange Pi Zero though. Could you share your dts files? thnx
zador.blood.stained Posted April 15, 2017 Posted April 15, 2017 3 hours ago, Oskar Blecha said: and waveshare 3.2 + touch is working Please post or attach your modified overlay, I'll add it to the repository as an example.
ldiaz Posted April 24, 2017 Posted April 24, 2017 (edited) Dear, I've trying to replicate Oskar archivements in an OrangpiZero with a 2.4" touch screen with an ili9341 for screen and XPT2046 (ADS7846 compatible as I have read). I'm runing a Mainline armbian dev version as next is not available for this board, I made sure that the ADS7846.ko is complided and included in the build. The display works fine with fbtft driver once configured the DC/LED/RESET gpios and selecting the bus=1. The device is connected to SPI1 (spi0 is connected to a flash in this board). I have included in the sun8i-h3-spi-add-cs1.dts to armbiamEnv.txt to a new pin "PA10" is usable as CS1 for SPI1. This in principle will enable to use 2 chip-select in the same SPI1 master. I have validated this assumption using the sample overlay in the repository: https://github.com/armbian/sunxi-DT-overlays-armbian/blob/master/examples/sun8i-h3-spi-double-spidev.dts if I load this overlay changing spi0 by spi1 i can see that two dev files are present in /dev directroy with spi1.0 and spi1.1 as expected. Following Oskar's approach I tried to adpapt the RPI overlay for my OPIZero. This is the file as source: /* * Generic Device Tree overlay for the ADS7846 touch controller * */ /dts-v1/; /plugin/; / { compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709"; fragment@0 { target = <&spi0>; __overlay__ { status = "okay"; }; }; fragment@1 { target = <&spidev0>; __overlay__ { status = "disabled"; }; }; fragment@2 { target = <&spidev1>; __overlay__ { status = "disabled"; }; }; fragment@3 { target = <&gpio>; __overlay__ { ads7846_pins: ads7846_pins { brcm,pins = <255>; /* illegal default value */ brcm,function = <0>; /* in */ brcm,pull = <0>; /* none */ }; }; }; fragment@4 { target = <&spi0>; __overlay__ { /* needed to avoid dtc warning */ #address-cells = <1>; #size-cells = <0>; ads7846: ads7846@1 { compatible = "ti,ads7846"; reg = <1>; pinctrl-names = "default"; pinctrl-0 = <&ads7846_pins>; spi-max-frequency = <2000000>; interrupts = <255 2>; /* high-to-low edge triggered */ interrupt-parent = <&gpio>; pendown-gpio = <&gpio 255 0>; /* driver defaults */ ti,x-min = /bits/ 16 <0>; ti,y-min = /bits/ 16 <0>; ti,x-max = /bits/ 16 <0x0FFF>; ti,y-max = /bits/ 16 <0x0FFF>; ti,pressure-min = /bits/ 16 <0>; ti,pressure-max = /bits/ 16 <0xFFFF>; ti,x-plate-ohms = /bits/ 16 <400>; }; }; }; __overrides__ { cs = <&ads7846>,"reg:0"; speed = <&ads7846>,"spi-max-frequency:0"; penirq = <&ads7846_pins>,"brcm,pins:0", /* REQUIRED */ <&ads7846>,"interrupts:0", <&ads7846>,"pendown-gpio:4"; penirq_pull = <&ads7846_pins>,"brcm,pull:0"; swapxy = <&ads7846>,"ti,swap-xy?"; xmin = <&ads7846>,"ti,x-min;0"; ymin = <&ads7846>,"ti,y-min;0"; xmax = <&ads7846>,"ti,x-max;0"; ymax = <&ads7846>,"ti,y-max;0"; pmin = <&ads7846>,"ti,pressure-min;0"; pmax = <&ads7846>,"ti,pressure-max;0"; xohms = <&ads7846>,"ti,x-plate-ohms;0"; }; }; Using the double-port template y created the following file. touch.dts: /dts-v1/ /plugin/; / { compatible = "allwinner,sun8i-h3"; fragment@0 { target-path = "/aliases"; __overlay__ { spi1 = "/soc/spi@01c69000"; /* Change spi0 -> spi1 */ }; }; fragment@1 { target = <&pio>; /* Change &gpio -> &pio */ __overlay__ { ads7846_pins: ads7846_pins { pins= "PA7"; /* TIRQ of the screen is connected to PA07" */ function = "gpio_in"; /*input. - should be irq?*/ pull = <0>; /* none. - should be bias-pull-up? */ }; }; }; fragment@2 { target = <&spi1>; __overlay__ { #address-cells = <1>; #size-cells = <0>; status = "okay"; /* Leave the first CS as in template */ spidev@0 { reg = <0>; /* Chip Select 0 */ compatible = "spidev"; spi-max-frequency = <1000000>; status = "okay"; }; /* Addapt ads definition */ ads7846: ads7846@1 { compatible = "ti,ads7846"; reg = <1>; pinctrl-names = "default"; pinctrl-0 = <&ads7846_pins>; spi-max-frequency = <2000000>; interrupts = <7 2>; /* high-to-low edge triggered change to PA7*/ interrupt-parent = <&pio>; /* Change gpio -> pio */ pendown-gpio = <&pio 0 7 0>; /* change to bank=0(A) port 7 -> PA7*/ /* driver defaults */ ti,x-min = /bits/ 16 <0>; ti,y-min = /bits/ 16 <0>; ti,x-max = /bits/ 16 <0x0FFF>; ti,y-max = /bits/ 16 <0x0FFF>; ti,pressure-min = /bits/ 16 <0>; ti,pressure-max = /bits/ 16 <0xFFFF>; ti,x-plate-ohms = /bits/ 16 <400>; }; }; }; }; I have removed all section about __overides__ as I don't know how to manage parameters. I load compule the dts using fresh verion of DTC compliler to accept parameter -@. I load the dtbo with the following command dynamicaly with a cat command to sysfs. The kernel detects correctly the DT and try to load the ads7846 driver but it fails with a non informative message: error -22. It seems that the driver do not initalize due to irq for the spi device is 0. Do you have any idea on how to solve this? Regards, Edited April 24, 2017 by zador.blood.stained Added code tags
zador.blood.stained Posted April 24, 2017 Posted April 24, 2017 8 minutes ago, ldiaz said: interrupts = <7 2>; /* high-to-low edge triggered change to PA7*/ You need to use 3 cells for the interrupt (pio has #interrupt-cells=<3>): <bank pin flags>, so value for PA7 IRQ_TYPE_EDGE_FALLING would be <0 7 2> 11 minutes ago, ldiaz said: pull = <0>; /* none. - should be bias-pull-up? */ Depends on whether your touch screen has a pull-up resistor for this line
zador.blood.stained Posted April 24, 2017 Posted April 24, 2017 15 minutes ago, ldiaz said: function = "gpio_in"; /*input. - should be irq?*/ Most likely it should be "irq", I'm not sure if initializing IRQ changes the pinmux settings in current kernel version.
ldiaz Posted April 24, 2017 Posted April 24, 2017 Thanks I give a try later with your sugestions. If it works I will Post a tutorial with the solution. This tfts are very low cost but could be very nice for certain applications. < $15 package including TF, board and touch screen.
ldiaz Posted April 25, 2017 Posted April 25, 2017 It's working now! The key point was the missing bank in interrupts parameter. interrupts = <0 7 2>; /* high-to-low edge triggered change to PA7*/ The display I use has a pull up resistor for IRQ to vref , however it works if the the pin sections is "gpio_in" or "irq" , also it works bias-pull-up is activated or not. I tested the four possibilities (gpio_in+no bias, irq+no_bias, irq+bias-up, gpio_in+bias-up) and works in all cases. thank you Zador for you help . As promised I will create a post with a tutorial for setting up a touch screen for this boards. In principle it should valid for all h3 based boards with a commented DTS as example. Regards,
Kishor Bagal Posted February 3, 2018 Posted February 3, 2018 Ldiaz hiii bro....can you give me details of how you do that 2.8 or 3.5 tft touch on spi0.0 using fbtft buffer...plzz share me ASAP.
Recommended Posts