<?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>SPI in zephry timing problems with nrfx_spi.c</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/100501/spi-in-zephry-timing-problems-with-nrfx_spi-c</link><description>I need to change pin of SPI0. I have ws2812b on pin number 0 and pin number 1.. I wanna use only one instance ( SPI0 ) for send data to this Strip leds with 2 different pin. also I am using &amp;quot;fxcontrol&amp;quot; library for animations. I wrote that code in SES</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 04 Jul 2023 12:09:09 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/100501/spi-in-zephry-timing-problems-with-nrfx_spi-c" /><item><title>RE: SPI in zephry timing problems with nrfx_spi.c</title><link>https://devzone.nordicsemi.com/thread/434455?ContentTypeID=1</link><pubDate>Tue, 04 Jul 2023 12:09:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c99da889-e892-4c44-b2b8-dfca9dc3acda</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t see the point in&amp;nbsp;porting a nRF5-SDK based&amp;nbsp;&lt;span&gt;WS2812b driver to Zephyr, because Zephyr already&amp;nbsp;have a&amp;nbsp;WS2812b driver and a sample for this driver.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/tree/main/samples/drivers/led_ws2812"&gt;https://github.com/nrfconnect/sdk-zephyr/tree/main/samples/drivers/led_ws2812&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/main/drivers/led_strip/ws2812_spi.c"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/main/drivers/led_strip/ws2812_spi.c&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI in zephry timing problems with nrfx_spi.c</title><link>https://devzone.nordicsemi.com/thread/429632?ContentTypeID=1</link><pubDate>Tue, 06 Jun 2023 16:19:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3064eeda-4972-414e-8b8f-30ff86947be6</guid><dc:creator>smeric</dc:creator><description>&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/pastedimage1686067600353v1.png" alt=" " /&gt;&amp;nbsp;SES WS2812b data timing&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&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/pastedimage1686067676265v2.png" alt=" " /&gt;&amp;nbsp; Zephyr&amp;nbsp;&lt;span&gt;WS2812b data timing&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;in 2us there must be 1 falling.(&amp;nbsp;NRF_SPI_FREQ_8M )&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;ws2812b code was ported from&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="https://github.com/takafuminaka/nrf52832-spi_ws2812b_flashing_random/blob/master/ws2812b_driver/ws2812b_driver.c#L186"&gt;https://github.com/takafuminaka/nrf52832-spi_ws2812b_flashing_random/blob/master/ws2812b_driver/ws2812b_driver.c#L186&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI in zephry timing problems with nrfx_spi.c</title><link>https://devzone.nordicsemi.com/thread/429631?ContentTypeID=1</link><pubDate>Tue, 06 Jun 2023 16:00:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c8e7e78-fe17-49ec-b1c2-445d88e3632f</guid><dc:creator>smeric</dc:creator><description>&lt;p&gt;Yes I am porting all SES code (&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="https://www.nordicsemi.com/Products/Development-software/nrf5-sdk"&gt;nRF5-SDK&lt;/a&gt;&lt;span&gt;. )&amp;nbsp;&lt;/span&gt;to&amp;nbsp;&lt;span&gt;&amp;nbsp;Vs Code&amp;nbsp;&lt;/span&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/index.html"&gt;nRF Connect SDK&lt;/a&gt;&amp;nbsp;&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/pastedimage1686066204105v1.png" alt=" " /&gt;&amp;nbsp;SES Code&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/eg1.png" alt=" " /&gt;&amp;nbsp;Vs Code Zephyr&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;app_config.h for clock configration in SES ..&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;// &amp;lt;o&amp;gt; NRF_SDH_CLOCK_LF_SRC  - SoftDevice clock source.
  // &amp;lt;0=&amp;gt; NRF_CLOCK_LF_SRC_RC 
  // &amp;lt;1=&amp;gt; NRF_CLOCK_LF_SRC_XTAL 
  // &amp;lt;2=&amp;gt; NRF_CLOCK_LF_SRC_SYNTH 

  #ifndef NRF_SDH_CLOCK_LF_SRC
  #define NRF_SDH_CLOCK_LF_SRC 0
  #endif

  // &amp;lt;o&amp;gt; NRF_SDH_CLOCK_LF_RC_CTIV - SoftDevice calibration timer interval. 
  #ifndef NRF_SDH_CLOCK_LF_RC_CTIV
  #define NRF_SDH_CLOCK_LF_RC_CTIV 16
  #endif

  // &amp;lt;o&amp;gt; NRF_SDH_CLOCK_LF_RC_TEMP_CTIV - SoftDevice calibration timer interval under constant temperature. 
  // &amp;lt;i&amp;gt; How often (in number of calibration intervals) the RC oscillator shall be calibrated
  // &amp;lt;i&amp;gt;  if the temperature has not changed.

  #ifndef NRF_SDH_CLOCK_LF_RC_TEMP_CTIV
  #define NRF_SDH_CLOCK_LF_RC_TEMP_CTIV 2
  #endif

  // &amp;lt;o&amp;gt; NRF_SDH_CLOCK_LF_ACCURACY  - External clock accuracy used in the LL to compute timing.
 
  // &amp;lt;0=&amp;gt; NRF_CLOCK_LF_ACCURACY_250_PPM 
  // &amp;lt;1=&amp;gt; NRF_CLOCK_LF_ACCURACY_500_PPM 
  // &amp;lt;2=&amp;gt; NRF_CLOCK_LF_ACCURACY_150_PPM 
  // &amp;lt;3=&amp;gt; NRF_CLOCK_LF_ACCURACY_100_PPM 
  // &amp;lt;4=&amp;gt; NRF_CLOCK_LF_ACCURACY_75_PPM 
  // &amp;lt;5=&amp;gt; NRF_CLOCK_LF_ACCURACY_50_PPM 
  // &amp;lt;6=&amp;gt; NRF_CLOCK_LF_ACCURACY_30_PPM 
  // &amp;lt;7=&amp;gt; NRF_CLOCK_LF_ACCURACY_20_PPM 
  // &amp;lt;8=&amp;gt; NRF_CLOCK_LF_ACCURACY_10_PPM 
  // &amp;lt;9=&amp;gt; NRF_CLOCK_LF_ACCURACY_5_PPM 
  // &amp;lt;10=&amp;gt; NRF_CLOCK_LF_ACCURACY_2_PPM 
  // &amp;lt;11=&amp;gt; NRF_CLOCK_LF_ACCURACY_1_PPM 

  #ifndef NRF_SDH_CLOCK_LF_ACCURACY
  #define NRF_SDH_CLOCK_LF_ACCURACY 1
  #endif&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;prj.conf file in Vs Code&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_LOG=y

#CONFIG_LED_STRIP=y
#CONFIG_LED_STRIP_LOG_LEVEL_DBG=y
#CONFIG_WS2812_STRIP=y
CONFIG_NEWLIB_LIBC=y
#clock config
CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y
CONFIG_CLOCK_CONTROL_NRF_K32SRC_500PPM=y
CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC_CALIBRATION=y
CONFIG_CLOCK_CONTROL_NRF_CALIBRATION_LF_ALWAYS_ON=y

CONFIG_SPI_NRFX=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;uninit and init code in vs&amp;nbsp;code &lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/index.html"&gt;nRF Connect SDK&lt;/a&gt;&lt;span&gt;,&amp;nbsp;&lt;/span&gt;with zephyr.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;  nrfx_spi_evt_handler_t handler;
  
  nrfx_spi_uninit(&amp;amp;(spi-&amp;gt;spi));
  
  nrfx_spi_config_t spi_config =
      {
          .ss_pin = NRFX_SPI_PIN_NOT_USED,
          .irq_priority = 2,//APP_IRQ_PRIORITY_HIGH,
        #ifdef DRIVE_MODE_8M
          .frequency = NRF_SPI_FREQ_8M,
        #endif
        #ifdef DRIVE_MODE_4M
          .frequency = NRF_SPI_FREQ_4M,
        #endif

          .mode = NRF_SPI_MODE_1,
          .bit_order = NRF_SPI_BIT_ORDER_MSB_FIRST,
          .miso_pin = NRFX_SPI_PIN_NOT_USED,
       //   .sck_pin = NRFX_SPIM_PIN_NOT_USED,
      };
        if (spi_pin_number == 0) {
          spi_config.sck_pin = SPI0_SCK_PIN;
         // spi_config.sck_pin = NRFX_SPI_PIN_NOT_USED;
          spi_config.mosi_pin = SPI0_MOSI_PIN;
          
        } else if (spi_pin_number == 1) {
          spi_config.sck_pin = SPI1_SCK_PIN;
         // spi_config.sck_pin =NRFX_SPI_PIN_NOT_USED;
          spi_config.mosi_pin = SPI1_MOSI_PIN;
        } else {
          spi_config.sck_pin = SPI2_SCK_PIN;
          //spi_config.sck_pin = NRFX_SPI_PIN_NOT_USED;
          spi_config.mosi_pin = SPI2_MOSI_PIN;
        };
        spi_config.skip_gpio_cfg=true;
        spi_config.skip_psel_cfg = false;

        //spi_config.skip_psel_cfg
        handler = spi0_event_handler;
  nrf_gpio_cfg(
    spi_config.mosi_pin,
    NRF_GPIO_PIN_DIR_OUTPUT,
    NRF_GPIO_PIN_INPUT_DISCONNECT,
    NRF_GPIO_PIN_NOPULL,
    NRF_GPIO_PIN_H0H1,
    NRF_GPIO_PIN_NOSENSE);

  nrf_gpio_cfg(
    spi_config.sck_pin,
    NRF_GPIO_PIN_DIR_OUTPUT,
    NRF_GPIO_PIN_INPUT_DISCONNECT,
    NRF_GPIO_PIN_NOPULL,
    NRF_GPIO_PIN_H0H1,
    NRF_GPIO_PIN_NOSENSE);

  spi-&amp;gt;transfer_completed = &amp;amp;spi_transfer_completed[id];
  ws2812b_driver_spi[id] = spi;
  nrfx_spi_init(&amp;amp;(spi-&amp;gt;spi), &amp;amp;spi_config, handler, NULL);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;ps : &lt;span&gt;pin changing is working I can see all logic changing, but&amp;nbsp;all changing is with wrong timing&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI in zephry timing problems with nrfx_spi.c</title><link>https://devzone.nordicsemi.com/thread/429622?ContentTypeID=1</link><pubDate>Tue, 06 Jun 2023 15:26:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:43ead10c-91f0-442b-8044-35ce7d1145c1</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""] I wrote that code in SES but I dont know how can I do it in zephyr and use nrfx_spi.c file. is ses I did like that[/quote]
&lt;p&gt;You wrote some code&amp;nbsp;using nrfx and with the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="https://www.nordicsemi.com/Products/Development-software/nrf5-sdk"&gt;nRF5-SDK&lt;/a&gt;. And you are now porting&amp;nbsp;this code&lt;span&gt;&amp;nbsp;&lt;/span&gt;over to&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/index.html"&gt;nRF Connect SDK&lt;/a&gt;, and the Zephyr RTOS ? Correct?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>