<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Slow GPIO Output Speed Issue: Inquiring About Causes and Solutions</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/125461/slow-gpio-output-speed-issue-inquiring-about-causes-and-solutions</link><description>Hello, we are currently testing the output of square waves through GPIO output pins. However, I found that a single operation to set the GPIO output pin high or low using the gpio_pin_set function takes about 3 microseconds, so the transmitted square</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 13 Nov 2025 10:07:22 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/125461/slow-gpio-output-speed-issue-inquiring-about-causes-and-solutions" /><item><title>RE: Slow GPIO Output Speed Issue: Inquiring About Causes and Solutions</title><link>https://devzone.nordicsemi.com/thread/554239?ContentTypeID=1</link><pubDate>Thu, 13 Nov 2025 10:07:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b23482a7-5b64-4f5b-9c3a-d55a1c20c1bf</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You need a bit more flexibility and control over the hardware module.&lt;/p&gt;
&lt;p&gt;I would recommend that you look into using the nrfx_spim driver directly instead of using the zephyr driver.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/zephyrproject-rtos/hal_nordic/tree/master/nrfx/samples/src/nrfx_spim"&gt;https://github.com/zephyrproject-rtos/hal_nordic/tree/master/nrfx/samples/src/nrfx_spim&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Slow GPIO Output Speed Issue: Inquiring About Causes and Solutions</title><link>https://devzone.nordicsemi.com/thread/554214?ContentTypeID=1</link><pubDate>Thu, 13 Nov 2025 07:32:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:81c494c7-becb-4f61-9851-4a3147d4c94e</guid><dc:creator>HHJ</dc:creator><description>&lt;p&gt;We are currently using the SPI of the chip hardware without any modifications, directly reading the DTS file via macros, and setting the CS_delay to 0. Our clock is set to 8M, which works well (32 clocks take 4us), but the CS line pulls high 33us after the clock line ends. This makes a single SPI operation take 46us, resulting in the SPI frequency failing to meet our time requirements&amp;mdash;since the time consumed by the CS line determines the final SPI frequency. This is quite unreasonable; why does such a strange phenomenon occur?&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1763019137549v1.png" alt=" " /&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1763019156570v2.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Slow GPIO Output Speed Issue: Inquiring About Causes and Solutions</title><link>https://devzone.nordicsemi.com/thread/553942?ContentTypeID=1</link><pubDate>Tue, 11 Nov 2025 10:19:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d511762c-069c-457f-b6e0-ec5f7b65bd18</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="HHJ"]First, let me reply to your first question. After using the nrf_gpio_pin_set / clear functions to directly write to the registers, our speed has reached 2.65 microseconds per complete clock cycle. Since we have a total of 32 clock cycles, the total time consumed is 84.8 microseconds. However, the 32 clock cycles of our hardware SPI can be completed in 4 microseconds. We don&amp;#39;t need to reach such a high speed, but our 32 clock cycles should be controlled within 10-20 microseconds at least. Do you have any other methods to increase the speed?[/quote]
&lt;p&gt;You need to change the gpio each 0.15 to 0.3 us to obtain a frequency of 3.2 to 6.4 MHz.&lt;/p&gt;
&lt;p&gt;This is not possible to do using the gpio directly. You need to use a dedicated hardware peripheral to do this.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Slow GPIO Output Speed Issue: Inquiring About Causes and Solutions</title><link>https://devzone.nordicsemi.com/thread/553932?ContentTypeID=1</link><pubDate>Tue, 11 Nov 2025 09:38:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:92b57a76-d3f1-47a0-96cd-330b625900f6</guid><dc:creator>HHJ</dc:creator><description>&lt;p&gt;First, let me reply to your first question. After using the nrf_gpio_pin_set / clear functions to directly write to the registers, our speed has reached 2.65 microseconds per complete clock cycle. Since we have a total of 32 clock cycles, the total time consumed is 84.8 microseconds. However, the 32 clock cycles of our hardware SPI can be completed in 4 microseconds. We don&amp;#39;t need to reach such a high speed, but our 32 clock cycles should be controlled within 10-20 microseconds at least. Do you have any other methods to increase the speed?&lt;br /&gt;Second, we have already reduced the interrupt frequency, but the TIMER2 still fails to start correctly. Through tests, we can confirm that the HFCLK has been bound to TIMER2. However, we suspect that TIMER2 has not been initialized successfully&amp;mdash;the timer never increments, remains at 0, and thus cannot enter the interrupt function. I have integrated the SPI-related code into a single file and hope you can help me analyze the cause.&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/2654.spi.c"&gt;devzone.nordicsemi.com/.../2654.spi.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;kevin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Slow GPIO Output Speed Issue: Inquiring About Causes and Solutions</title><link>https://devzone.nordicsemi.com/thread/553794?ContentTypeID=1</link><pubDate>Mon, 10 Nov 2025 10:03:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d16ea316-8bf0-4e82-8fb8-9605bdfcbb7c</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="HHJ"]We followed your suggestion to directly write to the registers using the nrf_gpio_pin_set / clear functions, which improved the clock speed of our simulated SPI, but it&amp;#39;s still insufficient. [/quote]
&lt;p&gt;What speed did you achieve?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="HHJ"]Therefore, I defined a timer interrupt function void TIMER2_IRQHandler(void) in an attempt to control the clock frequency myself. Although the program can run, according to the logic analyzer, this timer interrupt is not enabled. We currently have two hypotheses: first, there is no external clock source HFCLK; second, the timer2 timer is not triggering. Here are my current main file, configuration file, and device tree file. Could you please help me analyze the reason?[/quote]
&lt;p&gt;You will not be able to service a interrupt of 125 ns. The CPU will be&amp;nbsp;at 100% load and not able to do any other tasks than entering the ISR function.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Slow GPIO Output Speed Issue: Inquiring About Causes and Solutions</title><link>https://devzone.nordicsemi.com/thread/553791?ContentTypeID=1</link><pubDate>Mon, 10 Nov 2025 09:31:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c68502d5-f985-42bd-aaab-f98d890a4bc8</guid><dc:creator>HHJ</dc:creator><description>&lt;p&gt;We followed your suggestion to directly write to the registers using the nrf_gpio_pin_set / clear functions, which improved the clock speed of our simulated SPI, but it&amp;#39;s still insufficient. Therefore, I defined a timer interrupt function void TIMER2_IRQHandler(void) in an attempt to control the clock frequency myself. Although the program can run, according to the logic analyzer, this timer interrupt is not enabled. We currently have two hypotheses: first, there is no external clock source HFCLK; second, the timer2 timer is not triggering. Here are my current main file, configuration file, and device tree file. Could you please help me analyze the reason?&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/5001.main.c"&gt;devzone.nordicsemi.com/.../5001.main.c&lt;/a&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/8233.app.overlay"&gt;devzone.nordicsemi.com/.../8233.app.overlay&lt;/a&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/327556.prj.conf"&gt;devzone.nordicsemi.com/.../327556.prj.conf&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Slow GPIO Output Speed Issue: Inquiring About Causes and Solutions</title><link>https://devzone.nordicsemi.com/thread/553519?ContentTypeID=1</link><pubDate>Thu, 06 Nov 2025 08:22:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c0d05694-aadc-4622-a032-668e3d0dc699</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;1. include header hal/nrf_gpio.h and use nrf_gpio_pin_set / clear functions. These will write directly to the register.&lt;/p&gt;
&lt;p&gt;2. In addition; Try adding a barrier or a readback of an event register.&lt;/p&gt;
&lt;p&gt;Reading back for instance (void)NRF_TIMER2-&amp;gt;EVENTS_COMPARE[0]; between each gpio_pin_set function call will generate a PCLK16M wait state, thus you will ensure that the gpio is set/clr with a higher accuracy/speed.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>