<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://test-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>Zephyr nrf5340 cpu app SPI1 burst read missing byte</title><link>https://test-devzone.nordicsemi.com/f/nordic-q-a/87791/zephyr-nrf5340-cpu-app-spi1-burst-read-missing-byte</link><description>Hi, 
 I am trying to burst read FIFO of ADXL362 with zephyr adxl362 sample. 1 byte tx (read fifo command) and n byte rx ( reading the fifo data); 
 Zephyr is the last version 3.0 , ncs is 1.9.1 , mcu is nrf5340 app s 
 i write this function to set a spi</description><dc:language>en-US</dc:language><generator>Telligent Community 13 Non-Production</generator><lastBuildDate>Thu, 12 May 2022 11:31:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://test-devzone.nordicsemi.com/f/nordic-q-a/87791/zephyr-nrf5340-cpu-app-spi1-burst-read-missing-byte" /><item><title>RE: Zephyr nrf5340 cpu app SPI1 burst read missing byte</title><link>https://test-devzone.nordicsemi.com/thread/367581?ContentTypeID=1</link><pubDate>Thu, 12 May 2022 11:31:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e9c298e0-8794-4fdb-aaba-90dbf6525bd1</guid><dc:creator>user2111</dc:creator><description>&lt;p&gt;I think you understand what is occuring now, so I don&amp;#39;t think there is anything I can add, but just to clarify a bit on how it works:&lt;/p&gt;
&lt;p&gt;In SPI there is a clock signal that synchronously output/input the MOSI (from tx_buf)/MISO(to rx_buf) signals, this is done in parallel by hardware. It should always have been this, though it might have been small changes whether the entire transaction was handled in one transfer and/or on byte level depending on the software/hardware implementation. Depending on the driver/library it might have been that the above described low level buffering&amp;nbsp;was masked out on higher abstraction layers&amp;nbsp;(e.g. that you didn&amp;#39;t observe that the low level hardware buffer was +1 byte).&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr nrf5340 cpu app SPI1 burst read missing byte</title><link>https://test-devzone.nordicsemi.com/thread/367510?ContentTypeID=1</link><pubDate>Thu, 12 May 2022 05:43:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b2d70362-b1e6-4cdd-8dc5-f5d2bcc7ab1f</guid><dc:creator>user83150</dc:creator><description>&lt;p&gt;I found the driver code&amp;nbsp; and i can say they put extra buffer switch things into spi driver , so zephyr driver is not just&amp;nbsp; like&amp;nbsp;nrfx_spim_xfer( , actually it still uses&amp;nbsp;nrfx_spim_xfer but there is much more such as ;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;it looks like &amp;quot;transaction manager&amp;quot; stye driver.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static inline void *spi_context_get_next_buf(const struct spi_buf **current,
					     size_t *count,
					     size_t *buf_len,
					     uint8_t dfs)
{
	/* This loop skips zero-length buffers in the set, if any. */
	while (*count) {
		if (((*current)-&amp;gt;len / dfs) != 0) {
			*buf_len = (*current)-&amp;gt;len / dfs;
			return (*current)-&amp;gt;buf;
		}
		++(*current);
		--(*count);
	}

	*buf_len = 0;
	return NULL;
}&lt;/pre&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;		++(*current);
		--(*count);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void event_handler(const nrfx_spim_evt_t *p_event, void *p_context)
{
	struct spi_nrfx_data *dev_data = p_context;

	if (p_event-&amp;gt;type == NRFX_SPIM_EVENT_DONE) {
#ifdef CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58
		anomaly_58_workaround_clear(dev_data);
#endif
		spi_context_update_tx(&amp;amp;dev_data-&amp;gt;ctx, 1, dev_data-&amp;gt;chunk_len);
		spi_context_update_rx(&amp;amp;dev_data-&amp;gt;ctx, 1, dev_data-&amp;gt;chunk_len);

		transfer_next_chunk(dev_data-&amp;gt;dev);
	}
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr nrf5340 cpu app SPI1 burst read missing byte</title><link>https://test-devzone.nordicsemi.com/thread/367495?ContentTypeID=1</link><pubDate>Wed, 11 May 2022 23:26:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fe962085-aa20-424d-976f-c4fb42304444</guid><dc:creator>user83150</dc:creator><description>[quote userid="2111" url="~/f/nordic-q-a/87791/zephyr-nrf5340-cpu-app-spi1-burst-read-missing-byte/367487#367487"]This because the two buffers run in paralell and not after eachother.[/quote]
&lt;p&gt;i will create small project but , i think you have already clarified it.&lt;/p&gt;
&lt;p&gt;this&amp;nbsp;&lt;pre class="ui-code" data-mode="text"&gt;spi_transceive(spec-&amp;gt;bus, &amp;amp;spec-&amp;gt;config, tx_bufs, rx_bufs);&lt;/pre&gt;&amp;nbsp; , i work with nrf52 and sdk15-17 before but it seems zephyr drivers are implemented slightly different than old ones.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Previous projects with SES, i was using this one ( not with zephyr ) and if i remember correctly , it was sending tx then getting the rx to the buffer....It was not writing to the rx buffers during the tx time.&amp;nbsp;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt; 	nrf_drv_spi_xfer (nrf_drv_spi_t const *const p_instance, nrf_drv_spi_xfer_desc_t const *p_xfer_desc, uint32_t flags)
 	
 	&lt;/pre&gt;&amp;nbsp;with&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;table class="memberdecls"&gt;
&lt;tbody&gt;
&lt;tr class="memitem:gaa882c9d38c2a3c714123cc807757d9bb"&gt;
&lt;td class="memItemLeft" align="right" colspan="1" rowspan="1" valign="top"&gt;&amp;nbsp;&lt;/td&gt;
&lt;td class="memItemRight" colspan="1" rowspan="1" valign="bottom"&gt;&lt;a class="el" href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.0.0/group__nrfx__spi.html#gaa882c9d38c2a3c714123cc807757d9bb"&gt;NRFX_SPI_XFER_TRX&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;But as you said &lt;span&gt;&amp;nbsp;zephyr driver&amp;nbsp;&lt;/span&gt;runs tx rx in parallel. (maybe even before the zephyr, those nrf spi drivers were running the buffer in parallel, i am not sure ). but i was getting only rx data in rx buffer.&lt;/p&gt;
&lt;p&gt;Now i tested zephyr driver ,yes it overwrites the 1st rx buffer when sending the tx bytes, then overwrites to 2nd&amp;nbsp; rx buffer....&lt;span&gt;and i guess if i provide only one rx buffer during the tx&amp;amp;rx transaction it recalculates rx count and filling rx maxcnt counter accordingly...&amp;nbsp;So it divides only one rx buffer for two parts automatically...As i remember previous non zephyr drivers were not behaving like this.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;If this is true, i&amp;nbsp;was wondering about&amp;nbsp; huge gap between tx and rx transactions for zephyr nrf spi driver, so it means cpu switching those buffer arrays between &amp;amp;tx and &amp;amp;rx transactions.... as i remember it was not like that before&amp;nbsp; for sdk14-15 at least . so zephyr using something like &amp;quot;transaction manager&amp;quot; style driver i guess...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr nrf5340 cpu app SPI1 burst read missing byte</title><link>https://test-devzone.nordicsemi.com/thread/367487?ContentTypeID=1</link><pubDate>Wed, 11 May 2022 19:49:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:81f21f91-a0e0-4e4e-9d00-52e192533643</guid><dc:creator>user2111</dc:creator><description>&lt;p&gt;Are you able to provide some simple project I may run on an nRF5340-DK that I can run to replicate this? I assume the adxl362 is not needed to show the problem.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Just to avoid any confusion&amp;nbsp;, I assume you understand that the amount register will be set to the length of rxbuf or txbuf, whichever is longest, and not an&amp;nbsp;addition&amp;nbsp;of the two. This because the two buffers run in paralell and not after eachother.&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr nrf5340 cpu app SPI1 burst read missing byte</title><link>https://test-devzone.nordicsemi.com/thread/367441?ContentTypeID=1</link><pubDate>Wed, 11 May 2022 13:34:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:107c0d3f-9f6f-4403-87c1-866693a7b84d</guid><dc:creator>user83150</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have compared but my issue&amp;nbsp; is not related with spi configuration or building errors.&lt;/p&gt;
&lt;p&gt;I can successfully communicate with adxl362. My issue is if I try 1 byte tx follows multi byte (n bytes) rx transaction with &amp;quot; spi_transceive_dt&amp;quot; function , Rx part clocked out&amp;nbsp; as 1 byte less, n-1.&amp;nbsp; When I debug with jlink I can see that AMOUNT and MAXCNT set as n-1&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So some how zephyr spi driver&amp;nbsp; altering my rx count setting from n to n-1. If I set rxbuf as n+1&amp;nbsp; to read n bytes , zephyr driver modifies n+1 to n so I can get n bytes. But this bugs me because I need reason why zephyr driver trims my rxbuf lenght,/count.&lt;/p&gt;
&lt;p&gt;The issue is not seen for 2 byte tx and n byte rx .&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr nrf5340 cpu app SPI1 burst read missing byte</title><link>https://test-devzone.nordicsemi.com/thread/367405?ContentTypeID=1</link><pubDate>Wed, 11 May 2022 12:35:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f2676533-88c7-4b76-985f-8f4509d2b17b</guid><dc:creator>user2111</dc:creator><description>&lt;p&gt;Can you take a look at this example for comparison?&lt;br /&gt;&lt;a href="https://test-devzone.nordicsemi.com/f/nordic-q-a/67065/how-to-configure-and-setup-an-spi-device-to-nrf5340/275002#275002"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/67065/how-to-configure-and-setup-an-spi-device-to-nrf5340/275002#275002&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>