<?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>Understanding Write then Read SPI Transfers (External Flash)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/81704/understanding-write-then-read-spi-transfers-external-flash</link><description>Hi all, 
 I&amp;#39;m currently trying to interface an nRF52832 with an external Flash chip via SPI 
 I have tried with both NAND and NOR types, specifically the MT29F2G01 from Micron and the S25FS064S from Cypress. Both of these chips implement a pretty simple</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 16 Nov 2021 05:23:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/81704/understanding-write-then-read-spi-transfers-external-flash" /><item><title>RE: Understanding Write then Read SPI Transfers (External Flash)</title><link>https://devzone.nordicsemi.com/thread/339119?ContentTypeID=1</link><pubDate>Tue, 16 Nov 2021 05:23:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:07f239b1-7d25-445d-9fd1-de7971cfbd35</guid><dc:creator>eekwils</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;Thank you for your reply. I think I might not have made it clear in my question but I am not working with the Internal Flash of the nRF52832. This question is more about what I thought was odd behaviour from the SPI driver when reading data&amp;nbsp;from external chips.&lt;/p&gt;
&lt;p&gt;However after doing some more reading about SPI I think it&amp;#39;s actually my misunderstanding about the duplex nature of SPI. I expected all of the writing to happen first and then the reading to happen after, however because there are dedicated input and output lines what I now realise is that a byte is written and a byte is read&amp;nbsp;&lt;em&gt;&lt;strong&gt;at the same time.&lt;/strong&gt;&lt;/em&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The solution for me will be to run two seperate SPI transfers, the first one writing the required data and ignoring any data that comes over the MISO line and then another transfer reading the correct amount data off the MISO line and outputting 0 on the MOSI line for each byte read.&lt;/p&gt;
&lt;p&gt;I will also need to manage the CS pin myself now as it looks like the SPI driver automatically sets it high after a transfer but I need to keep it low so that I can perform the second read.&lt;/p&gt;
&lt;p&gt;After realising this it seems very obvious now but this was my first real exposure to SPI. I was used to the back and forth nature of I2C and expected SPI to work in a similar way.&lt;/p&gt;
&lt;p&gt;Hopefully this can serve as a record in case someone else is making the same silly mistake I have.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;-Elliott&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Understanding Write then Read SPI Transfers (External Flash)</title><link>https://devzone.nordicsemi.com/thread/339051?ContentTypeID=1</link><pubDate>Mon, 15 Nov 2021 14:37:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e444884e-e97a-4ce0-bf54-47b11a72f786</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Chapter&amp;nbsp;11 of the nRF52832 is very specific on how to do writing to flash.&lt;/p&gt;
&lt;p&gt;&amp;quot;When write is enabled, full 32-bit words can be written to word-aligned addresses in flash memory. As illustrated in Memory on page 20, the flash is divided into multiple pages. The same 32-bit word in flash memory can only be written n WRITE number of times before a page erase must be performed.&lt;/p&gt;
&lt;p&gt;The NVMC is only able to write 0 to bits in flash memory that are erased (set to 1). It cannot rewrite a bit back to 1. Only full 32-bit words can be written to flash memory using the NVMC interface. To write less than 32 bits, write the data as a full 32-bit word and set all the bits that should remain unchanged in the word to 1. The restriction on the number of writes (nWRITE) still applies in this case.&lt;/p&gt;
&lt;p&gt;Only word-aligned writes are allowed. Byte or half-word-aligned writes will result in a hard fault.&amp;quot;&lt;/p&gt;
&lt;p&gt;This means that you have to write in 1 full word (or 4 bytes at a time) I&amp;#39;m afraid.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>