<?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>nRF Connect SDK: SPI communication is not working on nRF52840 dev kit</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/67686/nrf-connect-sdk-spi-communication-is-not-working-on-nrf52840-dev-kit</link><description>Hi nRF support team, By using the nRF Connect SDK, I am trying to implement an SPI communication with the display module from my nRF52840 dev kit and nRF52840 as a master. I have tried below test code. But I m not receiving invalid data on MOSI pin and</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 22 Jan 2021 18:59:16 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/67686/nrf-connect-sdk-spi-communication-is-not-working-on-nrf52840-dev-kit" /><item><title>RE: nRF Connect SDK: SPI communication is not working on nRF52840 dev kit</title><link>https://devzone.nordicsemi.com/thread/290826?ContentTypeID=1</link><pubDate>Fri, 22 Jan 2021 18:59:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7afb2997-2758-428e-934f-d0c4ab7502b5</guid><dc:creator>rmcin</dc:creator><description>&lt;p&gt;Thanks for this example Edvin. I was in the process of trying to get an ADXL372 in spi mode going with an nRF52840 dev kit. &lt;br /&gt;&lt;br /&gt;I have not been able to get the chip select working (nrfx_spi.c if p_config-&amp;gt;ss_pin set to 0xFF NRFX_SPI_PIN_NOT_USED).&amp;nbsp; So it appears the work around in the sample you showed of using gpio_pin_set() at the main.c level was the only way I good send valid mosi data. The only change would be that I did not OR the SPI_MODE_CP0L bit so the clock goes back low.&lt;br /&gt;&lt;br /&gt;I am using nrf connect sdk and building with SES 1.4.99 dev1. I am running the adxl372 sample using this in the overlay. I can get your sample working with the same overlay and prj.config, but when I run the adxl372 example I get no activity on the logic analyzer.&lt;br /&gt;&lt;br /&gt;My question is would a sensor driver need to call gpio_pin_set() for the ss pin to function?&lt;/p&gt;
&lt;p&gt;&amp;amp;spi1 {&lt;br /&gt; cs-gpios = &amp;lt;&amp;amp;gpio0 16 GPIO_ACTIVE_LOW&amp;gt;;&lt;br /&gt; sck-pin = &amp;lt;31&amp;gt;;&lt;br /&gt; mosi-pin = &amp;lt;30&amp;gt;;&lt;br /&gt; miso-pin = &amp;lt;40&amp;gt;;&lt;br /&gt; adxl372@0 {&lt;br /&gt; compatible = &amp;quot;adi,adxl372&amp;quot;;&lt;br /&gt; reg = &amp;lt;0&amp;gt;;&lt;br /&gt; spi-max-frequency = &amp;lt;1000000&amp;gt;;&lt;br /&gt; //spi-max-frequency = &amp;lt;8000000&amp;gt;;&lt;br /&gt; label = &amp;quot;ADXL372&amp;quot;;&lt;br /&gt; int1-gpios = &amp;lt;&amp;amp;gpio1 14 GPIO_ACTIVE_HIGH&amp;gt;;&lt;br /&gt; }; &lt;br /&gt;};&lt;br /&gt;&amp;amp;spi2 {&lt;br /&gt; status = &amp;quot;disabled&amp;quot;;&lt;br /&gt;};&lt;/p&gt;
&lt;p&gt;&amp;amp;gpiote {&lt;br /&gt; status = &amp;quot;okay&amp;quot;;&lt;br /&gt;};&lt;/p&gt;
&lt;p&gt;&amp;amp;gpio0 {&lt;br /&gt; status = &amp;quot;okay&amp;quot;;&lt;br /&gt;};&lt;/p&gt;
&lt;p&gt;&amp;amp;gpio1 {&lt;br /&gt; status = &amp;quot;okay&amp;quot;;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;prj.conf&lt;/p&gt;
&lt;p&gt;CONFIG_STDOUT_CONSOLE=y&lt;br /&gt;CONFIG_LOG=y&lt;/p&gt;
&lt;p&gt;CONFIG_GPIO=y&lt;br /&gt;CONFIG_SPI=y&lt;br /&gt;CONFIG_SPI_1=y&lt;br /&gt;CONFIG_SPI_2=n&lt;br /&gt;CONFIG_SPI_NRFX=y&lt;br /&gt;CONFIG_SENSOR=y&lt;br /&gt;CONFIG_ADXL372=y&lt;br /&gt;CONFIG_ADXL372_SPI=y&lt;br /&gt;CONFIG_SENSOR_LOG_LEVEL_WRN=y&lt;/p&gt;
&lt;p&gt;CONFIG_CBPRINTF_FP_SUPPORT=y&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF Connect SDK: SPI communication is not working on nRF52840 dev kit</title><link>https://devzone.nordicsemi.com/thread/277913?ContentTypeID=1</link><pubDate>Sat, 31 Oct 2020 14:18:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f93ae9b4-ad5d-488b-8fa1-23cae3ef934d</guid><dc:creator>Kalyan Agepati</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;Thanks for the quick response and changes.&lt;/p&gt;
&lt;p&gt;I have connected CS to GND and now I am receiving the valid data on MOSI.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Kalyan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF Connect SDK: SPI communication is not working on nRF52840 dev kit</title><link>https://devzone.nordicsemi.com/thread/277649?ContentTypeID=1</link><pubDate>Thu, 29 Oct 2020 14:54:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a297fd2c-3def-4b30-ba4b-3a36330b212b</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Are you sure you didn&amp;#39;t change the SPI config?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;What happens if you try the following main.c file:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
* Copyright (c) 2012-2014 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;sys/printk.h&amp;gt;
#include &amp;lt;drivers/spi.h&amp;gt;
#include &amp;lt;drivers/gpio.h&amp;gt;

#define LED_PIN 16
#define SS_PIN 31

#define TEST_STRING &amp;quot;Southic&amp;quot;

static const struct spi_config spi_cfg = {
	.operation = SPI_OP_MODE_MASTER | SPI_WORD_SET(8) | SPI_TRANSFER_MSB |
		     SPI_MODE_CPOL | SPI_MODE_CPHA,
	.frequency = 4000000,
	.slave = 0,
};

struct device * spi_dev;

static void spi_init(void)
{
	const char* const spiName = &amp;quot;SPI_1&amp;quot;;
	spi_dev = device_get_binding(spiName);

	if (spi_dev == NULL) {
		printk(&amp;quot;Could not get %s device\n&amp;quot;, spiName);
		return;
	}
}

void spi_test_send(void)
{
	int err;
	static u8_t tx_buffer[8] = TEST_STRING;
	static u8_t rx_buffer[8];

	tx_buffer[0] = 0x3f;
	
	for (int i=0; i&amp;lt;sizeof(tx_buffer);i++)
	{
		//tx_buffer[i] = 0x61 + i;
		rx_buffer[i] = 0x00;
	}

	const struct spi_buf tx_buf = {
		.buf = tx_buffer,
		.len = sizeof(tx_buffer)
	};
	const struct spi_buf_set tx = {
		.buffers = &amp;amp;tx_buf,
		.count = 1
	};

	struct spi_buf rx_buf = {
		.buf = rx_buffer,
		.len = sizeof(rx_buffer),
	};
	const struct spi_buf_set rx = {
		.buffers = &amp;amp;rx_buf,
		.count = 1
	};
	
	err = spi_transceive(spi_dev, &amp;amp;spi_cfg, &amp;amp;tx, &amp;amp;rx);
	
	if (err) {
		printk(&amp;quot;SPI error: %d\n&amp;quot;, err);
	} else {
		/* Connect MISO to MOSI for loopback */
		printk(&amp;quot;TX sent: &amp;quot;);
		for (uint8_t i=0; i&amp;lt;6; i++)
		{
			printk(&amp;quot;%x&amp;quot;, tx_buffer[i]);
		}
		printk(&amp;quot;\r\nRX recv: &amp;quot;);
		for (uint8_t i=0; i&amp;lt;6; i++)
		{
			printk(&amp;quot;%c&amp;quot;, rx_buffer[i]);
		}
		printk(&amp;quot;\r\n&amp;quot;);
		//tx_buffer[0]++;
	}	
}

void main(void)
{
	int ret;
	bool my_bool = false;

	struct device * dev = device_get_binding(&amp;quot;GPIO_0&amp;quot;);
	if (!dev) {
		printk(&amp;quot;Device not found\n&amp;quot;);
		return;
	}
	ret = gpio_pin_configure(dev, LED_PIN, GPIO_OUTPUT_ACTIVE);
	if (ret &amp;lt; 0)
	{
		printk(&amp;quot;failed %d&amp;quot;, ret);
	}
	ret = gpio_pin_configure(dev, SS_PIN, GPIO_OUTPUT_ACTIVE);
	if (ret &amp;lt;0)
	{
		printk(&amp;quot;failed %d&amp;quot;, ret);
	}
	printk(&amp;quot;SPIM Example\n&amp;quot;);
	
	spi_init();
	

	while (1) {
		gpio_pin_set(dev, LED_PIN, my_bool);
		
		my_bool = !my_bool;
		printk(&amp;quot;my_bool %d\r\n&amp;quot;, my_bool);
		gpio_pin_set(dev, SS_PIN, false);
		spi_test_send();
		gpio_pin_set(dev, SS_PIN, true);
		k_sleep(K_MSEC(1000));
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;(you can remove the LED pin output if you like. I used this for testing, and it prints &amp;quot;?outhic&amp;quot;.&lt;/p&gt;
&lt;p&gt;Does it do that for you as well? You should see it in the logic analyzer. Try to enable the following settings:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/0726.pastedimage1603983218572v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;But with your own channels for mosi, miso and clock.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF Connect SDK: SPI communication is not working on nRF52840 dev kit</title><link>https://devzone.nordicsemi.com/thread/277411?ContentTypeID=1</link><pubDate>Wed, 28 Oct 2020 13:58:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8fc49a7f-dae1-4cb8-a4f1-911744ca2b3c</guid><dc:creator>Kalyan Agepati</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;Thanks for the suggestion. Now I am able to see the proper clock coming on SCK pin but not seeing valid data received on the MOSI pin.&lt;br /&gt;&lt;br /&gt;For your information, I have tried to transmit one byte &amp;#39;?&amp;#39; (x3f) data and expected to receive MOSI data signal should be 00111111 but I have received 00101000 which is not correct. Can you please let me know if anything I have missed in the SPI configuration and test code?&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/SPI_5F00_4MHz_5F00_data_5F00_analyzation.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Thanks in advance.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Kalyan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF Connect SDK: SPI communication is not working on nRF52840 dev kit</title><link>https://devzone.nordicsemi.com/thread/277328?ContentTypeID=1</link><pubDate>Wed, 28 Oct 2020 10:05:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b8002d96-f13a-4f2f-ba3b-614ab69cd0a4</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Your screenshot says you are sampling at 500kHz, but your SPI is running at 2MHz. Can you please try to sample using a higher sample rate on the logic analyzer?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>