danielgschl
Posts: 1
Joined: Tue Jun 27, 2017 7:36 pm

ads7846 on spi1

Tue Jun 27, 2017 7:40 pm

Is it possible to use the ads7846 on spi1 instead of spi0 ?

How to config.txt or overlays should look alike?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1819
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: ads7846 on spi1

Wed Jun 28, 2017 4:13 pm

It isn't currently possible (in a way that isn't completely awful) to parameterise overlays sufficiently to allow SPI bus selection. You will need to use a custom overlay - this ought to do (but I haven't tested it):

Code: Select all

/*
 * Generic Device Tree overlay for the ADS7846 touch controller on SPI1
 *
 */

/dts-v1/;
/plugin/;

/ {
	compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

	[email protected] {
		target = <&gpio>;
		__overlay__ {
			ads7846_pins: ads7846_pins {
				brcm,pins = <255>; /* illegal default value */
				brcm,function = <0>; /* in */
				brcm,pull = <0>; /* none */
			};
		};
	};

	[email protected] {
		target = <&spi1>;
		__overlay__ {
			/* needed to avoid dtc warning */
			#address-cells = <1>;
			#size-cells = <0>;

			ads7846: [email protected] {
				compatible = "ti,ads7846";
				reg = <0>;
				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";
	};
};
Call this ads7846-spi1-overlay.dts, and compile it with:

Code: Select all

dtc [email protected] -I dts -O dtb -o ads7846-spi1.dtbo ads7846-spi1-overlay.dts
sudo cp ads7846-spi1.dtbo /boot/overlays
Use it in the same way as the normal ads7846 overlay, except that you'll need to first load one of the spi1-[123]cs overlays:

Code: Select all

dtoverlay=spi1-1cs,cs0_spidev=off
dtoverlay=ads7846-spi,penirq=???
Note that I've changed the default CS to 0.

Robin466
Posts: 29
Joined: Tue May 08, 2018 5:55 am
Location: Fryslân, The Netherlands

Re: ads7846 on spi1

Tue May 08, 2018 8:09 am

i tried this option, but during the terminal command: dtc [email protected] -I dts -O dtb -o ads7846-spi1.dtbo ads7846-spi1-overlay.dts

i keep getting this error: ads7846-spi1.dtbo: warning (unit addres vs reg): node/[email protected] has a unit name, but no reg property.

any solution to this ?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1819
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: ads7846 on spi1

Tue May 08, 2018 8:46 am

That's a warning, not an error. The "dtc" tool isn't very aware of overlays and thinks that the fragments are nodes on a bus that should have a "reg" property. Just ignore it.

Robin466
Posts: 29
Joined: Tue May 08, 2018 5:55 am
Location: Fryslân, The Netherlands

Re: ads7846 on spi1

Tue May 08, 2018 11:38 am

PhilE wrote:
Tue May 08, 2018 8:46 am
That's a warning, not an error. The "dtc" tool isn't very aware of overlays and thinks that the fragments are nodes on a bus that should have a "reg" property. Just ignore it.
thank you for clearing that part up,

but somehow it doesn't work... i have changed the code to this for my application :

Code: Select all

dtoverlay=spi1-1cs,cs2_spidev=off
dtoverlay=ads7846-spi,penirq=5,penirq_pull=2,speed=50000,keep_vref_on=0,swapxy=0,pmax=255,xohms=150,xmin=200,xmax=3900,ymin=200,ymax=3900
i have wired the touch trough pi via the following pinout:

CS to BCM 16 (SPI1 CE2)
MOSI to BCM 20 (SPI1, MOSI)
SCLK to BCM 21 (SPI1, SCLK)
MISO to BCM 19(SPI1, MISO)
IRQ to BCM 5


Could you check together with me what i do wrong ?

thanks in advance :)

DirkS
Posts: 8850
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: ads7846 on spi1

Tue May 08, 2018 11:49 am

Robin466 wrote:
Tue May 08, 2018 11:38 am

Code: Select all

dtoverlay=spi1-1cs,cs2_spidev=off
...
i have wired the touch trough pi via the following pinout:

CS to BCM 16 (SPI1 CE2)
MOSI to BCM 20 (SPI1, MOSI)
SCLK to BCM 21 (SPI1, SCLK)
MISO to BCM 19(SPI1, MISO)
IRQ to BCM 5


Could you check together with me what i do wrong ?

thanks in advance :)
The CS pins for the SPI1 overlays are not fixed and there is only a CS0 entry available for spi1-1cs (see /boot/overlays/README).
Try

Code: Select all

dtoverlay=spi1-1cs,cs0_pin=16

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1819
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: ads7846 on spi1

Tue May 08, 2018 11:52 am

You've modified my example in order to use CE2 instead of CE0. For that to work you also need to change the overlay accordingly:

Code: Select all

...
	[email protected] {
		target = <&spi1>;
		__overlay__ {
			/* needed to avoid dtc warning */
			#address-cells = <1>;
			#size-cells = <0>;

			ads7846: [email protected] {               /* was @0 */
				compatible = "ti,ads7846";
				reg = <2>;                 /* was <0> */
				pinctrl-names = "default";
...

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1819
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: ads7846 on spi1

Tue May 08, 2018 11:54 am

The CS pins for the SPI1 overlays are not fixed and there is only a CS0 entry available for spi1-1cs (see /boot/overlays/README).
And that's the other reason it won't work. It would be best all-round if you reverted to CS0 and used cs0_pin to specify which pin to use.

Robin466
Posts: 29
Joined: Tue May 08, 2018 5:55 am
Location: Fryslân, The Netherlands

Re: ads7846 on spi1

Tue May 08, 2018 12:17 pm

DirkS wrote:
Tue May 08, 2018 11:49 am
The CS pins for the SPI1 overlays are not fixed and there is only a CS0 entry available for spi1-1cs (see /boot/overlays/README).
Try

Code: Select all

dtoverlay=spi1-1cs,cs0_pin=16
[/quote]

tried that with stock code of PhilE, doesn't work.....

Robin466
Posts: 29
Joined: Tue May 08, 2018 5:55 am
Location: Fryslân, The Netherlands

Re: ads7846 on spi1

Tue May 08, 2018 12:26 pm

PhilE wrote:
Tue May 08, 2018 11:54 am
The CS pins for the SPI1 overlays are not fixed and there is only a CS0 entry available for spi1-1cs (see /boot/overlays/README).
And that's the other reason it won't work. It would be best all-round if you reverted to CS0 and used cs0_pin to specify which pin to use.
sadly it doesn't work, don't really know why, do i do something wrong ?

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1819
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: ads7846 on spi1

Tue May 08, 2018 12:26 pm

Did you also include cs0_spidev=off?

Code: Select all

dtoverlay=spi1-1cs,cs0_pin=16,cs0_spidev=off
If this doesn't work, please look for evidence of each of the steps having executed:
1. Load the spi1-1cs overlay without the cs0_spidev=off and confirm that /dev/spidev1.0 exists and GPIO 16 is an output (raspi-gpio get 16).
2. With cs0_spidev=off reinstated, load your tweaked overlay as well and use lsmod to see if the ads7846 module is loaded.
3. Check the output of "dmesg" for errors.

Robin466
Posts: 29
Joined: Tue May 08, 2018 5:55 am
Location: Fryslân, The Netherlands

Re: ads7846 on spi1

Tue May 08, 2018 12:46 pm

PhilE wrote:
Tue May 08, 2018 12:26 pm
Did you also include cs0_spidev=off?

Code: Select all

dtoverlay=spi1-1cs,cs0_pin=16,cs0_spidev=off
If this doesn't work, please look for evidence of each of the steps having executed:
1. Load the spi1-1cs overlay without the cs0_spidev=off and confirm that /dev/spidev1.0 exists and GPIO 16 is an output (raspi-gpio get 16).
2. With cs0_spidev=off reinstated, load your tweaked overlay as well and use lsmod to see if the ads7846 module is loaded.
3. Check the output of "dmesg" for errors.
1. GPIO 16 : level0 Fsel=1 Func = Output
GPIO 5 (IRQ) level 1 Fsel=0 func= input
/dev/spidev 1.0 does exist
2. lsmod shows that ads7846 is not loaded...... the code in config.txt is this :

Code: Select all

dtoverlay=spi1-1cs,cs0_pin=16,cs0_spidev=off
dtoverlay=ads7846-spi,penirq=5,penirq_pull=2,speed=50000,keep_vref_on=0,swapxy=0,pmax=255,xohms=150,xmin=200,xmax=3900,ymin=200,ymax=3900
3. no Errors found

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1819
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: ads7846 on spi1

Tue May 08, 2018 12:49 pm

You've switched to spi1-2cs? Why? The CS usage is completely soft, and every change makes it harder to follow...

If you are determined to use CS2 then you must edit the overlay as I described above. If you have already done so then you should have said so to avoid wasting more time.

Robin466
Posts: 29
Joined: Tue May 08, 2018 5:55 am
Location: Fryslân, The Netherlands

Re: ads7846 on spi1

Tue May 08, 2018 12:51 pm

PhilE wrote:
Tue May 08, 2018 12:49 pm
You've switched to spi1-2cs? Why? The CS usage is completely soft, and every change makes it harder to follow...

If you are determined to use CS2 then you must edit the overlay as I described above. If you have already done so then you should have said so to avoid wasting more time.
no sorry i have changed my post !

i still had a old window open and copied the wrong one to the forum my bad, have changed it now !

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1819
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: ads7846 on spi1

Tue May 08, 2018 12:56 pm

It's possible the modified ads7846 overlay didn't apply. Does "sudo vcdbg log msg" show anything interesting?

Robin466
Posts: 29
Joined: Tue May 08, 2018 5:55 am
Location: Fryslân, The Netherlands

Re: ads7846 on spi1

Tue May 08, 2018 12:57 pm

where should i look for ? this is my first bigger Pi project so kind a newbie at it, my Apologies... :oops:

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1819
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: ads7846 on spi1

Tue May 08, 2018 1:01 pm

It's a command you run at a shell prompt:

Code: Select all

[email protected]:~ $ sudo vcdbg log msg
It's an odd command in that the main output goes to the error channel, so if you want to capture the output to a file you will have to run:

Code: Select all

[email protected]:~ $ sudo vcdbg log msg > log.txt 2>&1

Robin466
Posts: 29
Joined: Tue May 08, 2018 5:55 am
Location: Fryslân, The Netherlands

Re: ads7846 on spi1

Tue May 08, 2018 1:02 pm

ah easy,

002160.674: Failed to Load Overlay 'ads7846-spi'
002160.727: brfs: File read: /mfs/sd/overlays/ads7846-spi.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1819
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: ads7846 on spi1

Tue May 08, 2018 1:07 pm

Can you post the entire output after "**** Restart logging"?

Robin466
Posts: 29
Joined: Tue May 08, 2018 5:55 am
Location: Fryslân, The Netherlands

Re: ads7846 on spi1

Tue May 08, 2018 1:44 pm

PhilE wrote:
Tue May 08, 2018 1:07 pm
Can you post the entire output after "**** Restart logging"?
hmmm cannot get it trough the boot map so cannot post it here on the forum, since it is on my pi.... and i use the forum on my pc

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1819
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: ads7846 on spi1

Tue May 08, 2018 1:49 pm

1. Run "sudo cp log.txt /boot"
2. Shutdown the Pi and put the card in a card reader in your PC.
3. Upload/copy-and-paste the file.

OR (if your Pi is networked):

4. "sudo apt-get install pastebinit"
5. "sudo vcdbg log msg |& pastebinit"
6. Type the short URL it prints into your browser.

Robin466
Posts: 29
Joined: Tue May 08, 2018 5:55 am
Location: Fryslân, The Netherlands

Re: ads7846 on spi1

Tue May 08, 2018 2:01 pm

Code: Select all

001323.049: brfs: File read: /mfs/sd/config.txt

001595.949: *** Restart logging
001595.976: brfs: File read: 2026 bytes
001597.359: brfs: File read: /mfs/sd/cmdline.txt
001597.433: Read command line from file 'cmdline.txt'
dwc_otg.lpm_enable=0 console=tty1 console=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait fbcon=map:10 fbcon=font:ProFont6x11 logo.nologo
001597.704: brfs: File read: 168 bytes
001916.660: brfs: File read: /mfs/sd/kernel7.img
001916.684: Loading 'kernel7.img' to 0x8000 size 0x467730
001920.315: No kernel trailer - assuming DT-capable
001920.366: brfs: File read: 4618032 bytes
001923.940: brfs: File read: /mfs/sd/bcm2710-rpi-3-b.dtb
001923.962: Loading 'bcm2710-rpi-3-b.dtb' to 0x46f730 size 0x45c3
002030.856: brfs: File read: 17859 bytes
002033.097: brfs: File read: /mfs/sd/config.txt
002033.637: dtparam: i2c_arm=on
002042.946: dtparam: spi=on
002050.729: dtparam: audio=on
002062.858: brfs: File read: 2026 bytes
002072.553: brfs: File read: /mfs/sd/overlays/spi1-1cs.dtbo
002083.642: Loaded overlay 'spi1-1cs'
002083.660: dtparam: cs0_pin=16
002084.457: dtparam: cs0_spidev=off
002137.215: brfs: File read: 1547 bytes
002160.674: Failed to load overlay 'ads7846-spi'
002160.727: brfs: File read: /mfs/sd/overlays/ads7846-spi.dtb
003200.575: Device tree loaded to 0x2effb400 (size 0x4b76)
003202.595: gpioman: gpioman_get_pin_num: pin SDCARD_CONTROL_POWER not defined
004482.893: vchiq_core: vchiq_init_state: slot_zero = 0xfad80000, is_master = 1
004487.063: hdmi: HDMI:hdmi_get_state is deprecated, use hdmi_get_display_state instead
004492.162: TV service:host side not connected, dropping notification 0x00000002, 0x00000002, 0x00000057

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1819
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: ads7846 on spi1

Tue May 08, 2018 2:53 pm

Your overlay file should have been called "ads7486-spi.dtbo", but the firmware went on to try the ".dtb" variant and load it successfully so that error is more of a warning in this case.

I've just tried to recreate your setup here (but without the hardware) here and found a few things:
1. keep_vref_on is not a parameter understood by the overlay.
2. Your dtoverlay line is longer than 80 characters, so everthing after "swapxy=" will be ignored. You can split the line and put the remaining parameters in a "dtparam=" line (or lines, if it's really long) (*)
3. My vcdbg output includes things like "dtparam: penirq=5".
4. Even with the over-long line, the ads7846 module is still loaded.

3 & 4 make me think that your firmware may be old - what do "uname -a" and "strings /boot/start.elf | grep VC_BUILD" report?

(*)

Code: Select all

dtoverlay=foo,bar=1
can also be written

Code: Select all

dtoverlay=foo
dtparam=bar=1
so dtoverlay lines can be split at arbitrary points (between parameters, of course).

Robin466
Posts: 29
Joined: Tue May 08, 2018 5:55 am
Location: Fryslân, The Netherlands

Re: ads7846 on spi1

Fri May 11, 2018 8:16 am

Hi Phil,

Sorry had national holidays here in Holland so didn't look at this...

i am going to try the things you mentioned and will report back.

Robin466
Posts: 29
Joined: Tue May 08, 2018 5:55 am
Location: Fryslân, The Netherlands

Re: ads7846 on spi1

Fri May 11, 2018 8:26 am

Uname -a Reports

Code: Select all

Linux raspberry pi 4.9.80-v7+ #1098

strings /boot/start.elf | grep VC_BUILD reports
VC_BUILD_ID_USER: dc4
VC_BUILD_ID_TIME: 18:45:03
VC_BUILD_ID_BRANCH: Master
VC_BUILD_ID_TIME: Mar 13 2018
VC_BUILD_ID_HOSTNAME: dc4-XPS13-9333
VC_BUILD_ID_Platform: raspberrypi_linux
VC_BUILD_ID_VERSION: 6e08617e7767b09ef97b3d6cee8b75eba6d7e


its the firmware delivered with the sceen, also with the same parameters.

Return to “Device Tree”

Who is online

Users browsing this forum: No registered users and 1 guest