<?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>SPIS Multi-Byte Read/Write (Burst-Mode)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/89461/spis-multi-byte-read-write-burst-mode</link><description>Hello, 
 I am using a nrf52840-dk and communicate via SPI with an external board (NUCLEO-L476RG from ST) during development. For the development itself I am using the nRF Connect SDK v1.9.1. The communication over SPI is actually working quiet well. </description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 29 Jun 2022 14:07:31 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/89461/spis-multi-byte-read-write-burst-mode" /><item><title>RE: SPIS Multi-Byte Read/Write (Burst-Mode)</title><link>https://devzone.nordicsemi.com/thread/374763?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2022 14:07:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:84f2baa7-c64f-4d03-8f4a-72589c73e388</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Talisca"]To my understanding, as long as the master sends the next 8 clock pulses, the slave should receive the next byte. As long as it does not take too long (hence the timeout).[/quote]
&lt;p&gt;The problem is that once the CSN is latched, your buffers are locked. You&amp;nbsp;shall not change the content of the memory at this point.&lt;/p&gt;
&lt;p&gt;CSN input is controlled by the hardware, so there&amp;#39;s not many ways around this,&amp;nbsp;other than to send and receive in two separate SPI transactions. See this chapter specifically:&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/spis.html?cp=4_0_0_5_25_2#concept_abk_lbf_wr"&gt;https://infocenter.nordicsemi.com/topic/ps_nrf52840/spis.html?cp=4_0_0_5_25_2#concept_abk_lbf_wr&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPIS Multi-Byte Read/Write (Burst-Mode)</title><link>https://devzone.nordicsemi.com/thread/374742?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2022 13:00:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d9a33c29-6a0f-4133-a784-45061757d9d1</guid><dc:creator>Talisca</dc:creator><description>&lt;p&gt;Thank you very much for the answer.&lt;/p&gt;
&lt;p&gt;That is relatively clear to me. What I want to achieve is the following:&lt;br /&gt;In the nRF52840 I manage a so-called register of n bytes. For demonstration purposes, let&amp;#39;s just define 64 bytes for this.&lt;br /&gt;I want to make this register available via SPI. So a master should be able to write and read data here arbitrarily.&lt;/p&gt;
&lt;p&gt;Classically each byte is addressed by a register address. This is usually done by the first byte sent by the master.&lt;br /&gt;The highest&amp;nbsp;bit of this byte corresponds to a read/write flag. If this bit is set (0b10000000) then the master wants to read from the specified address. Otherwise he wants to write data to the address.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;If the master now writes 0x00 as the first byte, as a slave I know: Okay, the master wants to write into the register with the address 0x00.&lt;br /&gt;So the next byte sent by the master is the data.&lt;br /&gt;The same is true for all further addresses up to 0x3F.&lt;/p&gt;
&lt;p&gt;Now I know of many devices that&amp;nbsp;implement a protocol to write or read multiple bytes in one burst. For this the device performs an internal auto-increment of the address with every further received or written byte.&lt;br /&gt;So instead of the master having to establish a new communication and send the address every time like:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;tx_buffer[0] = 0x00u; // Register-Address 0x00
tx_buffer[1] = 0xAAu; // Data for Register-Address 0x00
spi_write(spi_dev, &amp;amp;spi_cfg, &amp;amp;tx);

tx_buffer[0] = 0x01u; // Register-Address 0x01
tx_buffer[1] = 0x42u; // Data for Register-Address 0x01
spi_write(spi_dev, &amp;amp;spi_cfg, &amp;amp;tx);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Instead, I would like to do this in one go:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;tx_buffer[0] = 0x00u; // Register-Address 0x00
tx_buffer[1] = 0xAAu; // Data for Register-Address 0x00
tx_buffer[2] = 0x42u; // Data for Register-Address 0x01
spi_write(spi_dev, &amp;amp;spi_cfg, &amp;amp;tx);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So as in my slave example code in my previous post, I would expect something like this to work:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;spi_read(spi_dev, &amp;amp;spi_cfg, &amp;amp;rx); // Read one byte as start-address
current_address = rx_buffer[0];
do
{
	spi_read(spi_dev, &amp;amp;spi_cfg, &amp;amp;rx); // Read next data byte 
	my_registers[current_address++] = rx_buffer[0]; // write data into current register address and increment address itself
}while(no timeout and other conditions);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;To my understanding, as long as the master sends the next 8 clock pulses, the slave should receive the next byte. As long as it does not take too long (hence the timeout).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Another example would be this description (taken from ISM330DLC Datasheet)&lt;/p&gt;
&lt;p&gt;&lt;a href="https://imgur.com/a/8v3R1Nb" rel="noopener noreferrer" target="_blank"&gt;https://imgur.com/a/8v3R1Nb&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPIS Multi-Byte Read/Write (Burst-Mode)</title><link>https://devzone.nordicsemi.com/thread/374732?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2022 12:15:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:82eb6aa0-a1c5-4edc-865c-1a3cc2dd0cd8</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m a bit uncertain in the feature that you&amp;#39;re after here, please explain a bit more in-detail if I&amp;#39;ve misunderstood anything.&lt;/p&gt;
&lt;p&gt;Writing to the tx_buf / rx_buf structs does not automatically trigger a transaction.&amp;nbsp;The nRF52840 does not have a generic DMA channel, if that is the functionality you&amp;#39;re after.&lt;/p&gt;
&lt;p&gt;Let us define a transaction as CSN going active, x bytes clock in, and CSN goes inactive.&lt;/p&gt;
&lt;p&gt;The SPIS cannot dynamically change the content based on the first&amp;nbsp;byte within the same transaction. Each transaction must be decided upon prior to when CSN goes active.&lt;/p&gt;
&lt;p&gt;The SPIS peripheral works as described in the PS:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/spis.html?cp=4_0_0_5_25"&gt;https://infocenter.nordicsemi.com/topic/ps_nrf52840/spis.html?cp=4_0_0_5_25&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;After writing your data to the respective struct, you&amp;#39;ll have to trigger a transfer function (which sets up the easydma buffers and starts the transfer), as shown in this SPIM example:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/sigurdnev/ncs-playground/blob/master/samples/spi_test/src/main.c"&gt;https://github.com/sigurdnev/ncs-playground/blob/master/samples/spi_test/src/main.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;(there&amp;#39;s also spis samples in the above repo)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>