<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to 184: Unable to set up edge detection on SPI0 CS0 and CS1 as of 5.4.51 Kernel</title><link>https://sourceforge.net/p/raspberry-gpio-python/tickets/184/</link><description>Recent changes to 184: Unable to set up edge detection on SPI0 CS0 and CS1 as of 5.4.51 Kernel</description><atom:link href="https://sourceforge.net/p/raspberry-gpio-python/tickets/184/feed.rss" rel="self"/><language>en</language><lastBuildDate>Tue, 03 Nov 2020 18:50:36 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/raspberry-gpio-python/tickets/184/feed.rss" rel="self" type="application/rss+xml"/><item><title>#184 Unable to set up edge detection on SPI0 CS0 and CS1 as of 5.4.51 Kernel</title><link>https://sourceforge.net/p/raspberry-gpio-python/tickets/184/?limit=25#4281</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;Hi Phil,&lt;/p&gt;
&lt;p&gt;I'd just like to say a massive thank you for your detailed explanation, and solution!&lt;/p&gt;
&lt;p&gt;I've just come across this myself (CE1, 7 for me) and had a look here to see if anyone else had come across it.&lt;br/&gt;
Hardware is made so it's not easy to change.&lt;br/&gt;
Added the overlay (for CE1) and all is well again (for my application - not the world..)&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Stefan</dc:creator><pubDate>Tue, 03 Nov 2020 18:50:36 -0000</pubDate><guid>https://sourceforge.netc107e623d264a59a8a4eb8b3035e7069416a2330</guid></item><item><title>Unable to set up edge detection on SPI0 CS0 and CS1 as of 5.4.51 Kernel</title><link>https://sourceforge.net/p/raspberry-gpio-python/tickets/184/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;As of the recently Kernel 5.4.51 it's no longer possible to &lt;code&gt;add_event_detect&lt;/code&gt; on an SPI Chip-Select pin while the SPI interface is enabled.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Yes&lt;/em&gt; in retrospect using a channel "reserved" by the SPI device in this way was probably never a wise thing to do. But what's done is done.&lt;/p&gt;
&lt;p&gt;To replicate use the following code snippet on a 5.4.51 Pi vs the previous kernel:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;RPi.GPIO&lt;/span&gt; &lt;span class="kn"&gt;as&lt;/span&gt; &lt;span class="nn"&gt;GPIO&lt;/span&gt;

&lt;span class="n"&gt;GPIO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;setmode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;GPIO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;BCM&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;GPIO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;GPIO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;IN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pin&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;pass&lt;/span&gt;

&lt;span class="n"&gt;GPIO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_event_detect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;edge&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;GPIO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;RISING&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;callback&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;It attempts to set up edge detection on SPI's default CE0 pin.&lt;/p&gt;
&lt;p&gt;Run this without SPI enabled and it will work fine.&lt;/p&gt;
&lt;p&gt;Run it &lt;em&gt;with&lt;/em&gt; SPI enabled, and it will fail with "RuntimeError: Failed to add edge detection".&lt;/p&gt;
&lt;p&gt;This has changed from previous behaviour and is no doubt the fault of changes as of the 5.x Linux kernel (the new mutually exclusive gpiochip instead of sysfs) and is, furthermore, no doubt fully intended behaviour depite the fact it breaks some potential back-compatibility cases (I've encountered this on a new ready to ship product and am dispairing with the world right now). &lt;/p&gt;
&lt;p&gt;I am raising it here in case there is some workaround that can be added to RPi.GPIO itself (I fear not) and to make this issue (and the below solution) known to other users who might have also been drawn into the trap of thinking they could own the SPI chip-select pins.&lt;/p&gt;
&lt;p&gt;The fix is simple, though a minor hassle for end-users. You must re-allocate the offending chip select channel to a different pin. There's a dtoverlay for this:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;dtoverlay&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;spi0&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;cs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;cs0_pin&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;14&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This example (add it to &lt;code&gt;/boot/config.txt&lt;/code&gt;) allocates CS0 to BCM14 (UART transmit) so that the above code will work in both cases.&lt;/p&gt;
&lt;p&gt;This dtoverlay also supports- you guessed it- an &lt;code&gt;cs1_pin&lt;/code&gt; argument that can be used to re-allocate the other channel.&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Phil</dc:creator><pubDate>Mon, 27 Jul 2020 09:27:07 -0000</pubDate><guid>https://sourceforge.net51543ec96a453f212cd2a39cc5205a604d46fd70</guid></item></channel></rss>