<?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 connection with external flash LE25U40CMDTWG</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/84134/spi-connection-with-external-flash-le25u40cmdtwg</link><description>Hi, 
 I have a device based on the board nrf9160 with an external peripheral which is the flash LE25U40CMDTWG and that communicates with the controller through the next pins (configuration on the dts): 
 &amp;amp;spi3 { compatible = &amp;quot;nordic,nrf-spim&amp;quot;; status</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 28 Jan 2022 12:39:58 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/84134/spi-connection-with-external-flash-le25u40cmdtwg" /><item><title>RE: SPI connection with external flash LE25U40CMDTWG</title><link>https://devzone.nordicsemi.com/thread/350199?ContentTypeID=1</link><pubDate>Fri, 28 Jan 2022 12:39:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:430d6207-e0ed-4b61-9bd7-fa3c4d3ce072</guid><dc:creator>AngeldelaCalle</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;p&gt;thanks for the shared sample. The problem was on the chip select. I was tried to manage it manually and with a logical analyzer I saw that the pin was always high. After initializing it as follows,&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;struct spi_cs_control spi_cs = {
    .gpio_pin = LE25U40CMDTWG_SPI_CS_PIN,
    .gpio_dt_flags = GPIO_ACTIVE_LOW,
    .delay = 0,
};

void le25u40cmdtwg_init(le25u40cmdtwg_t* le25u40cmdtwg) {
  config = le25u40cmdtwg;

  spi_cs.gpio_dev = device_get_binding(GPIO0_LABEL);
  if (gpio_dev == NULL) {
    LOG_ERR(&amp;quot;Could not bind GPIO 0&amp;quot;);
    return;
  }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;the problem is solved and the Rx buffers are filled with the expected values.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI connection with external flash LE25U40CMDTWG</title><link>https://devzone.nordicsemi.com/thread/350112?ContentTypeID=1</link><pubDate>Fri, 28 Jan 2022 07:52:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e1b66c60-decf-44dd-b644-17bdba43d8c1</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]Due to the design of the board, I cannot use any external HW as a logical analyzer for testing if the frames are being correctly sent through the MISO/MOSI lines of the spi configuration.[/quote]
&lt;p&gt;You are not able to probe some signals either?&lt;/p&gt;
&lt;p&gt;I took a quick look at your code, and I did not spot anything immediately wrong. But I have a simple SPI sample&amp;nbsp;&lt;a href="https://github.com/sigurdnev/ncs-playground/blob/master/samples/spi_test/src/main.c"&gt;here&lt;/a&gt;&amp;nbsp;you can compare with.&lt;/p&gt;
&lt;p&gt;Make sure that the external flash is powered and the correct pins are configured.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI connection with external flash LE25U40CMDTWG</title><link>https://devzone.nordicsemi.com/thread/350003?ContentTypeID=1</link><pubDate>Thu, 27 Jan 2022 14:16:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3fdbae22-e52f-4492-860e-77e30a2cd0c4</guid><dc:creator>AngeldelaCalle</dc:creator><description>&lt;p&gt;I&amp;#39;ve tried a similar driver based on the nrfx_spi APIs and the behaviour is the same one.&lt;/p&gt;
&lt;p&gt;nrfx_spim_xfer(&amp;amp;spim, &amp;amp;xfer_desc, 0) returns&amp;nbsp;NRFX_SUCCESS but the Rx buffer is always empty.&lt;/p&gt;
&lt;p&gt;I attach the main part of the source code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**
 * INCLUDES
 */

#include &amp;quot;le25u40cmdtwg.h&amp;quot;
#include &amp;lt;logging/log.h&amp;gt;
#include &amp;quot;string.h&amp;quot;
#include &amp;quot;../../hw_config.h&amp;quot;

/**
 * DEFINES
 */

#define MODULE_NAME le25u40cmdtwg
LOG_MODULE_REGISTER(MODULE_NAME, LOG_LEVEL_INF);

static const le25u40cmdtwg_t* config;
const struct device* spi_dev;
static volatile bool spim_xfer_done; /**&amp;lt; Flag used to indicate that SPIM instance completed the transfer. */
static nrfx_spim_config_t spi_config = {.sck_pin = LE25U40CMDTWG_SPI_SCK_PIN,
                                        .mosi_pin = LE25U40CMDTWG_SPI_MOSI_PIN,
                                        .miso_pin = LE25U40CMDTWG_SPI_MISO_PIN,
                                        .ss_pin = LE25U40CMDTWG_SPI_CS_PIN,
                                        .ss_active_high = false,
                                        .irq_priority = NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY,
                                        .orc = 0xFF,
                                        .frequency = NRF_SPIM_FREQ_1M,
                                        .mode = NRF_SPIM_MODE_3,
                                        .bit_order = NRF_SPIM_BIT_ORDER_MSB_FIRST,
                                        NRFX_SPIM_DEFAULT_EXTENDED_CONFIG};

#define SPI_INSTANCE 3
static const nrfx_spim_t spim = NRFX_SPIM_INSTANCE(SPI_INSTANCE);

// static uint8_t m_rx_buf[sizeof(TEST_STRING) + 1];
// static const uint8_t m_length = sizeof(m_tx_buf);

/**
 * @brief SPI user event handler.
 * @param event
 */
void spim_event_handler(nrfx_spim_evt_t const* p_event, void* p_context) {
  if (p_event-&amp;gt;type == NRFX_SPIM_EVENT_DONE) {
    spim_xfer_done = true;
    printk(&amp;quot;Transfer completed.&amp;quot;);
  }
}

uint8_t le25u40cmdtwg_init(const le25u40cmdtwg_t* le25u40cmdtwg) {
  printk(&amp;quot;El init del driver de SPI ya se hace realmente en el main&amp;quot;);

  config = le25u40cmdtwg;
  uint8_t ret = 0;

  // Application specific configuration
  if (gpio_pin_configure(config-&amp;gt;gpio_dev, LE25U40CMDTWG_SPI_CS_PIN, GPIO_OUTPUT_ACTIVE)) {
    printk(&amp;quot;Error while enabling pin %u.&amp;quot;, LE25U40CMDTWG_SPI_CS_PIN);
    return -1;
  }

  ret = nrfx_spim_init(&amp;amp;spim, &amp;amp;spi_config, spim_event_handler, NULL);

  /*while (!spim_xfer_done) {
    __WFE();
  }*/

  return ret;
  return 0;
}

uint8_t le25u40cmdtwg_spiTransfer(uint8_t tx_buffer, const le25u40cmdtwg_t* le25u40cmdtwg) {
  nrfx_err_t err_code = 0;

  uint8_t tx[2] = {tx_buffer, 0};  //{0x00 | 0x80, 0};
  uint8_t rx[2] = {0};

  nrfx_spim_xfer_desc_t xfer_desc = {
      .p_tx_buffer = tx,
      .tx_length = 2,
      .p_rx_buffer = rx,
      .rx_length = 2,
  };

  nrf_gpio_pin_clear(LE25U40CMDTWG_SPI_CS_PIN);  // Manual control of the chip select pin

  err_code = nrfx_spim_xfer(&amp;amp;spim, &amp;amp;xfer_desc, 0);

  if (err_code != NRFX_SUCCESS) {
    printk(&amp;quot;SPI error: %d\n&amp;quot;, err_code);
  }

  nrf_gpio_pin_set(LE25U40CMDTWG_SPI_CS_PIN);

  return rx[1];
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>