<?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>Cannot write/read a byte from external Flash via SPI</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/57395/cannot-write-read-a-byte-from-external-flash-via-spi</link><description>I am using a BMD 349 module based on nRF52840. 
 I am interfacing with AT25SF041 flash memory. 
 I am using SDK 14.2. 
 I am writing a byte to a specific address in Flash. 
 But when I try to read the memory location, On the debug window I only see &amp;quot;00</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 13 Feb 2020 01:15:04 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/57395/cannot-write-read-a-byte-from-external-flash-via-spi" /><item><title>RE: Cannot write/read a byte from external Flash via SPI</title><link>https://devzone.nordicsemi.com/thread/234079?ContentTypeID=1</link><pubDate>Thu, 13 Feb 2020 01:15:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5084eb2d-6842-4739-9d8b-02427f103d92</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;When manually operating CS, do not set it in the SPI config.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;config.ss_pin    = NRF_DRV_SPI_PIN_NOT_USED; &lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot write/read a byte from external Flash via SPI</title><link>https://devzone.nordicsemi.com/thread/234045?ContentTypeID=1</link><pubDate>Wed, 12 Feb 2020 16:10:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c5cb0314-bd6f-4540-a124-438f615bf536</guid><dc:creator>RO</dc:creator><description>&lt;p&gt;I finally got a logic analyzer and found the the issue. The problem was with the&amp;nbsp; CS line.&lt;/p&gt;
&lt;p&gt;I am manually operating it in my code. But the nrf_xfer() function in nrf_drv_spi.c also operates on it once it detects a transfer is finished.&lt;/p&gt;
&lt;p&gt;So it used to pull the CS line high between the SPI transfer function to send the Flash opcode &amp;amp; address and the SPI transfer function for the actual byte.&lt;/p&gt;
&lt;p&gt;So I commented out the line which was pulling the CS pin high in the nrf_drv_spi.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;if (!p_cb-&amp;gt;handler)
    {
        while (!nrf_spim_event_check(p_spim, NRF_SPIM_EVENT_END)){}
        if (p_cb-&amp;gt;ss_pin != NRF_DRV_SPI_PIN_NOT_USED)
        {
            //nrf_gpio_pin_set(p_cb-&amp;gt;ss_pin);        
        }
    }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Maybe a note can be mentioned in documentation regarding the operation of CS pin.&lt;br /&gt;&lt;br /&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot write/read a byte from external Flash via SPI</title><link>https://devzone.nordicsemi.com/thread/233284?ContentTypeID=1</link><pubDate>Fri, 07 Feb 2020 12:55:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e379911c-24f1-4b7b-b68b-bf3d4b4eea5c</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;Dumb question: Which read command did you use, and did you try reading more than one byte?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot write/read a byte from external Flash via SPI</title><link>https://devzone.nordicsemi.com/thread/233263?ContentTypeID=1</link><pubDate>Fri, 07 Feb 2020 12:24:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0af10a32-7789-4fff-b8c1-87b0d6b1f590</guid><dc:creator>Edvin</dc:creator><description>[quote user="ro269"]The fact that I can read manufacturer and device ID over SPI, doesn&amp;#39;t that prove that SPI connection has been correctly established?[/quote]
&lt;p&gt;&amp;nbsp;I agree. Again, I don&amp;#39;t know what flash you are using. Did you check the datasheet to double check that you are sending the correct read commands? If you use an invalid command, it may be that the external flash doesn&amp;#39;t give any replies, which probably will look like a lot of 0&amp;#39;s on the SPI.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot write/read a byte from external Flash via SPI</title><link>https://devzone.nordicsemi.com/thread/233141?ContentTypeID=1</link><pubDate>Thu, 06 Feb 2020 18:57:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:588e4ce8-9aff-4e19-9750-dcb6a7fddb38</guid><dc:creator>RO</dc:creator><description>&lt;p&gt;I don&amp;#39;t have access to a logic analyzer yet. The fact that I can read manufacturer and device ID over SPI, doesn&amp;#39;t that prove that SPI connection has been correctly established?&lt;br /&gt;I tried with 500k frequency, and the config mode is correct too. For some reason I&amp;#39;m only reading zeros..&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot write/read a byte from external Flash via SPI</title><link>https://devzone.nordicsemi.com/thread/232986?ContentTypeID=1</link><pubDate>Thu, 06 Feb 2020 09:41:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9533512f-0244-46f9-9626-a5ae71708fa1</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;I don&amp;#39;t know what external flash you use. You should check in the data sheet for the flash. Have you tried analyzing the SPI wires to see that the data that you are sending and receiving is actually being sent correctly? Have you tried lowering the SPI frequency? Perhaps the traces/wires are too long for 1M? Perhaps you are using the wrong config.mode?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot write/read a byte from external Flash via SPI</title><link>https://devzone.nordicsemi.com/thread/232907?ContentTypeID=1</link><pubDate>Wed, 05 Feb 2020 17:02:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9925176-0b66-4943-89ed-58f78f3ff292</guid><dc:creator>RO</dc:creator><description>&lt;p&gt;I did the following:&lt;/p&gt;
&lt;p&gt;write enable -&amp;gt; chip erase -&amp;gt; read (random address)&lt;br /&gt;&lt;br /&gt;I still read 00. Shouldn&amp;#39;t I read FF after a chip erase?&lt;br /&gt;&lt;br /&gt;I added delays for each operation as per datasheet.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I can read status registers fine. Why am I not able read data in random address&amp;#39; correctly?&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot write/read a byte from external Flash via SPI</title><link>https://devzone.nordicsemi.com/thread/232797?ContentTypeID=1</link><pubDate>Wed, 05 Feb 2020 11:29:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:15d419e8-5c62-4159-a2fb-c1c417f0e82b</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/turboj"&gt;Turbo J&lt;/a&gt; is correct. An erased byte is 0xFF, so if you are reading 0x00, that means that something else has already written to that address. Try to read it before you write to it.&lt;/p&gt;
&lt;p&gt;So what you probably need to do is to find the SPI command to erase everything on the flash (or that specific flash page).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot write/read a byte from external Flash via SPI</title><link>https://devzone.nordicsemi.com/thread/232695?ContentTypeID=1</link><pubDate>Wed, 05 Feb 2020 01:02:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3b27caa6-3f76-4214-84fb-173717c2207a</guid><dc:creator>RO</dc:creator><description>&lt;p&gt;Sorry I dont understand,&lt;/p&gt;
&lt;p&gt;as wriiten in the code, I&amp;#39;m trying to write &amp;quot;0x23&amp;quot; to a specific memory location.&lt;/p&gt;
&lt;p&gt;I want to read &amp;quot;0x23&amp;quot; back, am I doing something wrong?&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cannot write/read a byte from external Flash via SPI</title><link>https://devzone.nordicsemi.com/thread/232694?ContentTypeID=1</link><pubDate>Wed, 05 Feb 2020 00:48:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c54ed3d1-0001-4ab8-ba0a-ef0af55c4b36</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;[quote userid="25505" url="~/f/nordic-q-a/57395/cannot-write-read-a-byte-from-external-flash-via-spi"][/quote]&lt;/p&gt;
&lt;p&gt;I am writing a byte to a specific address in Flash.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But when I try to read the memory location, On the debug window I only see &amp;quot;00&amp;quot;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You can only &lt;strong&gt;write&lt;/strong&gt; &amp;quot;0&amp;quot; bits to flash.&lt;/p&gt;
&lt;p&gt;Returning to &amp;quot;1&amp;quot; is the &amp;quot;erase&amp;quot; operation, which has its own command (and operates on a page or sector at a time).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>