<?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>Nrf9160 + AD74413R spi problem with write/read</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/64215/nrf9160-ad74413r-spi-problem-with-write-read</link><description>We have AD74413R and we try send 32-bits frame size using spi interface and try read results, but it return always zero or 0xff bit. Maybe spi interface nrf9160 cannot work with 32-bits frame? Link - https://www.analog.com/media/en/technical-documentation</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 29 Jul 2020 09:16:41 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/64215/nrf9160-ad74413r-spi-problem-with-write-read" /><item><title>RE: Nrf9160 + AD74413R spi problem with write/read</title><link>https://devzone.nordicsemi.com/thread/262145?ContentTypeID=1</link><pubDate>Wed, 29 Jul 2020 09:16:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:78e8c138-9c4f-49e7-8c62-1d9b267238ee</guid><dc:creator>Martin Lesund</dc:creator><description>&lt;p&gt;Hi Mikhail,&lt;br /&gt;Without a Logic analyzer it is difficult to verify correct behavior of the SPI interface.&lt;br /&gt;I strongly recommend getting a hold of such equipment.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Nrf9160 + AD74413R spi problem with write/read</title><link>https://devzone.nordicsemi.com/thread/262122?ContentTypeID=1</link><pubDate>Wed, 29 Jul 2020 08:07:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:48c505bc-b794-4205-8c75-61ae36ce26f6</guid><dc:creator>mikhail.maryankou</dc:creator><description>&lt;p&gt;We don&amp;#39;t have logic analyzor :) It&amp;#39;s hardcore develop, but between transactions =&amp;gt; amperage from 0.04 to 0.05A&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
#include &amp;lt;logging/log.h&amp;gt;
LOG_MODULE_REGISTER(main);
#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;sys/printk.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;drivers/gpio.h&amp;gt;
#include &amp;lt;drivers/spi.h&amp;gt;

#define STACK_SIZE 512
u8_t buffer_tx[] = {0x41, 0x01, 0x46, 0xFF};//{0x46, 0x00, 0x00, 0xFF};
#define BUF_SIZE sizeof(buffer_tx)
u8_t buffer_rx[BUF_SIZE] = {};

u8_t buffer2_tx[] = {0x00, 0x00, 0x00, 0xFF};
#define BUF2_SIZE  sizeof(buffer2_tx)
u8_t buffer2_rx[BUF2_SIZE] = {};

#define PIN_3_3_ON 25
#define PIN_3_3_PER_ON 24
#define PIN_BAT_ON 22

#define SPI_CS NULL
#define CS_CTRL_GPIO_DRV_NAME &amp;quot;&amp;quot;

#define SPI_DRV_NAME	&amp;quot;SPI_3&amp;quot;
#define SPI_SLAVE	0
#define SLOW_FREQ	500000
#define FAST_FREQ	16000000

#define CS_CTRL_GPIO_PIN 28
static struct device *gpio;
static struct device *spi;

struct spi_config spi_cfg = {
	.frequency = SLOW_FREQ,
#if CONFIG_SPI_LOOPBACK_MODE_LOOP
	.operation = SPI_OP_MODE_MASTER | SPI_MODE_CPOL | SPI_MODE_LOOP |
#else
	.operation = SPI_OP_MODE_MASTER | SPI_MODE_CPOL |
#endif
	SPI_MODE_CPHA | SPI_WORD_SET(8) | SPI_LINES_SINGLE,
	.slave = SPI_SLAVE,
	.cs = SPI_CS,
};

struct spi_buf tx_buf = {
  .buf = buffer_tx,
  .len = sizeof(buffer_tx),
};
const struct spi_buf_set tx = {
  .buffers = &amp;amp;tx_buf,
  .count = 1
};

struct spi_buf rx_buf = {
  .buf = buffer_rx,
  .len = sizeof(buffer_rx),
};
const struct spi_buf_set rx = {
  .buffers = &amp;amp;rx_buf,
  .count = 1
};

int main()
{
  int err;

  gpio = device_get_binding(&amp;quot;GPIO_0&amp;quot;);
  spi = device_get_binding(SPI_DRV_NAME);

  err = gpio_pin_configure(gpio, PIN_3_3_ON, GPIO_DIR_OUT);
  if (err == 0) 
  {
    err = gpio_pin_write(gpio, PIN_3_3_ON, 1);
    LOG_INF(&amp;quot;err %d&amp;quot;, err);
  }
  err = gpio_pin_configure(gpio, PIN_3_3_PER_ON, GPIO_DIR_OUT);
  if (err == 0) 
  {
    err = gpio_pin_write(gpio, PIN_3_3_PER_ON, 1);
    LOG_INF(&amp;quot;err %d&amp;quot;, err);
  }

  err = gpio_pin_configure(gpio, PIN_BAT_ON, GPIO_DIR_OUT);
  if (err == 0) 
  {
      err = gpio_pin_write(gpio, PIN_BAT_ON, 1);
      LOG_INF(&amp;quot;err %d&amp;quot;, err);
  }

  err = gpio_pin_configure(gpio, CS_CTRL_GPIO_PIN, GPIO_DIR_OUT);
  if (err == 0) 
  {
      gpio_pin_write(gpio, CS_CTRL_GPIO_PIN, 1); //PULL CS HIGH
  }


  //1
  buffer_tx[3] = crc8_ccitt(0, buffer_tx, 3);
  buffer2_tx[3] = crc8_ccitt(0, buffer2_tx, 3);

  int ret;
  
  LOG_INF(&amp;quot;Start complete multiple&amp;quot;);
  ret = gpio_pin_write(gpio, CS_CTRL_GPIO_PIN, 0); //PULL CS LOW
  ret = spi_transceive(spi, &amp;amp;spi_cfg, &amp;amp;tx, NULL);
  if (ret) 
  {
      LOG_ERR(&amp;quot;Code %d&amp;quot;, ret);
      return ret;
  }
  ret = gpio_pin_write(gpio, CS_CTRL_GPIO_PIN, 1); //PULL CS HIGH


  //2
  tx_buf.buf = buffer2_tx;
  tx_buf.len = sizeof(buffer2_tx);
  
  ret = gpio_pin_write(gpio, CS_CTRL_GPIO_PIN, 0); //PULL CS LOW
  ret = spi_transceive(spi, &amp;amp;spi_cfg, &amp;amp;tx, &amp;amp;rx);
  if (ret) 
  {
      LOG_ERR(&amp;quot;Code %d&amp;quot;, ret);
      return ret;
  }
  ret = gpio_pin_write(gpio, CS_CTRL_GPIO_PIN, 1); //PULL CS HIGH

  rx_buf.buf = buffer2_rx;
  rx_buf.len = sizeof(buffer2_rx);

  ret = gpio_pin_write(gpio, CS_CTRL_GPIO_PIN, 0); //PULL CS LOW
  ret = spi_transceive(spi, &amp;amp;spi_cfg, &amp;amp;tx, &amp;amp;rx);
  if (ret) 
  {
      LOG_ERR(&amp;quot;Code %d&amp;quot;, ret);
      return ret;
  }
  ret = gpio_pin_write(gpio, CS_CTRL_GPIO_PIN, 1); //PULL CS HIGH

  if (memcmp(buffer_tx, buffer_rx, BUF_SIZE)) 
  {
      return -1;
  }

  if (memcmp(buffer2_tx, buffer2_rx, BUF2_SIZE)) 
  {
      return -1;
  }
  
  LOG_INF(&amp;quot;Passed&amp;quot;);
  return 0;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Nrf9160 + AD74413R spi problem with write/read</title><link>https://devzone.nordicsemi.com/thread/262041?ContentTypeID=1</link><pubDate>Tue, 28 Jul 2020 15:04:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4161ee1b-c5d5-4253-8e47-213389c439fb</guid><dc:creator>Martin Lesund</dc:creator><description>&lt;p&gt;Hi Mikhail,&lt;/p&gt;
&lt;p&gt;Please check out the SPI peripheral documentation for the nRF9160:&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fps_nrf9160%2Fspim.html&amp;amp;cp=2_0_0_5_12"&gt;https://infocenter.nordicsemi.com/index.jsp?topic=%2Fps_nrf9160%2Fspim.html&amp;amp;cp=2_0_0_5_12&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I do see why that should not work. I would like to know more about your implementation instead.&amp;nbsp;&lt;br /&gt;Have you checked with a logic analyzor that it is actually behaving correctly?&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>