<?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>Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/50734/interface-external-flash-to-nrf52832</link><description>I want to interface a 16MB external flash (SPI) with nrf52832 on the development board.Suggest me how should I start with and if there is an example for external flash then let me know.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 27 Aug 2019 07:29:07 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/50734/interface-external-flash-to-nrf52832" /><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/206242?ContentTypeID=1</link><pubDate>Tue, 27 Aug 2019 07:29:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7e7c9347-96d8-445e-947b-404b14477e30</guid><dc:creator>sara</dc:creator><description>&lt;p&gt;Thanku for your best wishes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/206220?ContentTypeID=1</link><pubDate>Tue, 27 Aug 2019 06:33:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:20f199f2-952b-42b4-b07d-96f00259d013</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;That&amp;#39;s great, hopefully you will have less problems going forward &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/206117?ContentTypeID=1</link><pubDate>Mon, 26 Aug 2019 12:34:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3af826be-c794-4aaf-900a-28f778c32a66</guid><dc:creator>sara</dc:creator><description>&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/206115?ContentTypeID=1</link><pubDate>Mon, 26 Aug 2019 12:30:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f2bfa965-eb2a-4775-8280-3433d7cbfd2e</guid><dc:creator>sara</dc:creator><description>&lt;p&gt;Thanks a lot, Torbjorn. I tried whole day to get make the flash write 256 bytes but was not able to do :( Thank you for your support. :). I tested it with my hardware and its working.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/206096?ContentTypeID=1</link><pubDate>Mon, 26 Aug 2019 12:03:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7bbe2b91-0c71-492c-9f1e-76704c79249b</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;It seems there are a couple of problems here. First off the UART TX buffer should be increased to allow the longer log messages to be buffered properly (I increased it from 256 to 1024 bytes), but more importantly the SPI driver is limited to 255 byte transactions, which makes it fail when you try to send 256 bytes in one go.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I made a slight change to the driver to split transactions longer than 255 bytes into multiple transactions:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-fa253dbb5a56481f9771fe3fa47ed48d/DZ233955_5F00_ble_5F00_app_5F00_uart_5F00_v2.zip"&gt;devzone.nordicsemi.com/.../DZ233955_5F00_ble_5F00_app_5F00_uart_5F00_v2.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Please note that the sensor has it&amp;#39;s own limitations. If I remember correctly you can&amp;#39;t write more than 256 bytes in one go (but I am sure you can read more).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regarding erase I think it is sufficient to specify any address within the block to erase the whole block, but specifying the start address of the block seems the most logical.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/205978?ContentTypeID=1</link><pubDate>Sat, 24 Aug 2019 14:12:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:87e75379-bac8-45f0-81f3-6a738623e6dc</guid><dc:creator>Nguyen Hoan Hoang</dc:creator><description>&lt;p&gt;This flash driver here is quite easy to use and works with almost all SPI Flash. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/IOsonata/IOsonata/blob/master/include/diskio_flash.h"&gt;https://github.com/IOsonata/IOsonata/blob/master/include/diskio_flash.h&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;usage example&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/IOsonata/IOsonata/blob/master/exemples/misc/flash_memory_demo.cpp"&gt;https://github.com/IOsonata/IOsonata/blob/master/exemples/misc/flash_memory_demo.cpp&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/205903?ContentTypeID=1</link><pubDate>Fri, 23 Aug 2019 12:59:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0f78abf1-650b-4906-8162-9df3c5f74597</guid><dc:creator>sara</dc:creator><description>&lt;p&gt;One more thing and if I want to erase :&lt;/p&gt;
&lt;p&gt;sector 0 do i have to give address as 0x000000,&lt;/p&gt;
&lt;p&gt;sector 1 as 0x008000&lt;/p&gt;
&lt;p&gt;sector 2 as 0x010000&amp;nbsp; ????&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/205896?ContentTypeID=1</link><pubDate>Fri, 23 Aug 2019 12:43:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b406a07f-7691-4c2c-a1e2-53f19fd0ff6b</guid><dc:creator>sara</dc:creator><description>&lt;p&gt;Thank you&amp;nbsp; soo much Torbjorn.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;U really made my work easier and also cleared my few doubts.&lt;/p&gt;
&lt;p&gt;I tested your code with my flash device and its working properly. But now when I want to write the full page what which is 256 bytes I am not able to do it. I tested first by sending sector erase and the if I read 256 bytes I get the following results which is wrong. ryt?? for full sector earse and fullpage write for 256 what should i add?&lt;/p&gt;
&lt;p&gt;I need this because I want to write and read full sectors.&lt;/p&gt;
&lt;p&gt;Reading address 00001000: 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-000000000000000000000000000&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/205883?ContentTypeID=1</link><pubDate>Fri, 23 Aug 2019 12:07:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:77090672-05bf-4247-8de2-2739fa17b393</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I set up my own little test based no ble_app_uart, and it seems to work fine.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have tested most of the core commands, including Sector Erase, Chip Erase, Program, Read, Write Enable and RDSR.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I set up a small state machine that runs through a read - erase - read - program - read loop every time I reset the code, and the results look OK.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-fa253dbb5a56481f9771fe3fa47ed48d/DZ233955_5F00_ble_5F00_app_5F00_uart.zip"&gt;devzone.nordicsemi.com/.../DZ233955_5F00_ble_5F00_app_5F00_uart.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;When I run this on an nRF52840 DK I get the following UART output:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;UART started.&lt;/em&gt;&lt;br /&gt;&lt;em&gt;Reading REMS. Man id: c2, Dev id: 17&lt;/em&gt;&lt;br /&gt;&lt;em&gt;Status: 0&lt;/em&gt;&lt;br /&gt;&lt;em&gt;Config: 0&lt;/em&gt;&lt;br /&gt;&lt;em&gt;Reading address 00001000: FF-FF-FF-FF-00-01-02-03-04-05-06-07-08-09-0A-0B-&lt;/em&gt;&lt;br /&gt;&lt;em&gt;Running write enable&lt;/em&gt;&lt;br /&gt;&lt;em&gt;Running sector erase at address 0x1000&lt;/em&gt;&lt;br /&gt;&lt;em&gt;Status: 0&lt;/em&gt;&lt;br /&gt;&lt;em&gt;Reading address 00001000: FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-FF-&lt;/em&gt;&lt;br /&gt;&lt;em&gt;Running write enable&lt;/em&gt;&lt;br /&gt;&lt;em&gt;Programming data at address 00001004&lt;/em&gt;&lt;br /&gt;&lt;em&gt;Status: 0&lt;/em&gt;&lt;br /&gt;&lt;em&gt;Reading address 00001000: FF-FF-FF-FF-00-01-02-03-04-05-06-07-08-09-0A-0B-&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I have updated the nRF52832 project also. It compiles and runs nicely, but doesn&amp;#39;t show any output since I don&amp;#39;t have a flash device connected.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Can you take a look at my code and see what might be different?&lt;/p&gt;
&lt;p&gt;I put all the flash functionality in the spi_flash.c/h files, and the test state machine can be found towards the bottom of main.c&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/205774?ContentTypeID=1</link><pubDate>Fri, 23 Aug 2019 07:56:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fc4467aa-3efe-47f8-b521-a120a1a78df2</guid><dc:creator>sara</dc:creator><description>&lt;p&gt;Ext_flash.h&amp;nbsp; you can remove it and instead of it add external_flash.h&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/205767?ContentTypeID=1</link><pubDate>Fri, 23 Aug 2019 07:42:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fab4cead-f147-4873-8e7c-04f30811af05</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Thanks. Adding those files I realize that ext_flash.h is also missing ;)&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f61e.svg" title="Disappointed"&gt;&amp;#x1f61e;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Either way, I will start doing some testing on my own in the mean time, and set up a quick test based on the ble_app_uart example.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Getting 3-4 of the core functions running should not be very time consuming.&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/205603?ContentTypeID=1</link><pubDate>Thu, 22 Aug 2019 12:34:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4194624d-fbf2-4030-8920-7bf1968eac71</guid><dc:creator>sara</dc:creator><description>&lt;p&gt;Opps, Sorry for the inconvience. I am sharing these two files. One more thing I have doubt is that I am not able to write more than 16 bytes and also do not know the what the &lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/external_5F00_flash.c"&gt;devzone.nordicsemi.com/.../external_5F00_flash.c&lt;/a&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/external_5F00_flash.h"&gt;devzone.nordicsemi.com/.../external_5F00_flash.h&lt;/a&gt;block , sector and page addresses will be?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/205560?ContentTypeID=1</link><pubDate>Thu, 22 Aug 2019 11:24:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:940080ea-fd5c-47b8-ae6e-f6eb87e81cad</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks for sharing your project. It mostly seems to work fine, except the external_flash.c/h files appear to be missing.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Most likely you put these in one of the SDK folders.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Are you able to share these files also?&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/205322?ContentTypeID=1</link><pubDate>Wed, 21 Aug 2019 12:42:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fbafefe0-3c4f-4285-bb50-34c240e8fffa</guid><dc:creator>sara</dc:creator><description>&lt;p&gt;&lt;strong&gt;Did you really need a 100ms delay after chip select to make it work? -&lt;/strong&gt; No but to try to get the chip erase working I added that delay . But now when I removed it it is working. But I am not sure enough that whether it will work always or not.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;strong&gt;I realized you&amp;#39;re using a similar flash device to the one used on the nRF52840DK&lt;/strong&gt;- Yes its a similar flash with difference in its storage capacity .(16 MB)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I have made removed that 100ms delay after CS and also removed the flash busy and wait status which I think is necessary but after doing that I am able to get the results sometimes. So I think it still needs some modifications for its proper functioning. I am attaching my source code for your reference.I am using SDK 15.3.0&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/ble_5F00_app_5F00_uart_5F00_pdm_5F00_extflash.rar"&gt;devzone.nordicsemi.com/.../ble_5F00_app_5F00_uart_5F00_pdm_5F00_extflash.rar&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/205302?ContentTypeID=1</link><pubDate>Wed, 21 Aug 2019 11:59:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:de60c950-c627-4234-b250-6a1feb87133a</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Did you really need a 100ms delay after chip select to make it work?&lt;/p&gt;
&lt;p&gt;Did you try to measure how long the status is busy after issuing an erase command?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;According to the specification this can take several seconds, depending on how much you are erasing.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I realized you&amp;#39;re using a similar flash device to the one used on the nRF52840DK, which allows me to do some testing myself.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Are you able to send me both your source and header files so I can try to run your code?&lt;br /&gt;The code you sent is referencing some includes and defines that I don&amp;#39;t have.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/204954?ContentTypeID=1</link><pubDate>Tue, 20 Aug 2019 08:46:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:27a868dd-419d-4c25-9ea1-8ac20b6439b5</guid><dc:creator>sara</dc:creator><description>&lt;p&gt;and the code as below &lt;pre class="ui-code" data-mode="c_cpp"&gt;///**
// ******************************************************************************
// * @file      ext_flash.c
// *            This source file provides external flash memory related functionalities.
// *
// * @author    Glide Embedded Technology &amp;lt;www.glidemtech.com&amp;gt;
// * @date       7, August, 2019
// ******************************************************************************
// */
//
///* Includes ------------------------------------------------------------------*/
///* Includes ------------------------------------------------------------------*/
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
//
#include &amp;quot;external_flash.h&amp;quot;
#include &amp;lt;hal/nrf_gpio.h&amp;gt;
#include &amp;lt;hal/nrf_spi.h&amp;gt;
#include &amp;quot;nrf_drv_spi.h&amp;quot;
#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;





uint8_t print = 1;


#define SPI_INSTANCE  0 /**&amp;lt; SPI instance index. */
static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);

#define WAIT_FOR_PERIPH() do { \
        while (!m_finished) {} \
        m_finished = false;    \
    } while (0)

static volatile bool m_finished = false;


static uint8_t m_buffer_tx[256];
static uint8_t m_buffer_rx[256];

//static uint8_t m_data_send[256];
static uint8_t m_data_receive[256];

#define TEST_STRING  &amp;quot;Z&amp;quot; //&amp;quot;Nordic&amp;quot;
static uint8_t       m_tx_buf[] = TEST_STRING;           /**&amp;lt; TX buffer. */
static uint8_t       m_rx_buf[sizeof(TEST_STRING) + 1];    /**&amp;lt; RX buffer. */
static const uint8_t m_length = sizeof(m_tx_buf); 

static uint8_t m_buffer_tx[256];
static uint8_t m_buffer_rx[256];

//static uint8_t m_data_send[256];
static uint8_t m_data_receive[256];

static uint8_t m_data_send[256] = {[0 ... 255] = 0xbb};
uint8_t StatusReg;
uint8_t ConfigReg;
uint8_t SecurityReg;

/**
 * @brief SPI user event handler.
 * @param event
 */
void spi_event_handler(nrf_drv_spi_evt_t const * p_event,
                       void *                    p_context)
{
    m_finished = true;
    uint16_t i ;
    //printf(&amp;quot;\n\rTransfer completed.&amp;quot;);
    if (m_buffer_rx[0] != 0)
    {
//        printf(&amp;quot; Received:&amp;quot;);
        for(i=0;i&amp;lt;8;i++)
        {
//          printf(&amp;quot;m_buffer_rx[%d] = %x &amp;quot;,i,m_buffer_rx[i]);
        }
        NRF_LOG_HEXDUMP_INFO(m_buffer_rx, strlen((const char *)m_buffer_rx));
    }
   // nrf_gpio_pin_set(SPI_SS_PIN);
}
void cs_low(void)
{
  nrf_gpio_pin_set(SPI_SS_PIN);
}


void cs_high(void)
{
  nrf_gpio_pin_clear(SPI_SS_PIN);
}



/*
 * Reset setting Command
 */

/*
 * Function:       CMD_RSTEN
 * Arguments:      None.
 * Description:    Enable RST command
 * Return Message: FlashOperationSuccess
 */
ReturnMsg cmd_rsten( void )
{
    // Chip select go low to start a flash command
    cs_low();

    // Write RSTEN command
   
    uint8_t instruction = FLASH_CMD_RSTEN;
    m_buffer_tx[0] = instruction;
    
   nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)m_buffer_tx,1,m_buffer_rx,1);

    // Chip select go high to end a flash command
    cs_high();

    return FlashOperationSuccess;
}

/*
 * Function:       CMD_RST
 * Arguments:      fsptr, pointer of flash status structure
 * Description:    The RST instruction is used as a system (software) reset that
 *                 puts the device in normal operating Ready mode.
 * Return Message: FlashOperationSuccess
 */
ReturnMsg cmd_rst( void )
{
    // Chip select go low to start a flash command
    cs_low();

    // Write RST command = 0x99
    
    uint8_t instruction = FLASH_CMD_RST;
    m_buffer_tx[0] = instruction;
    
   nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)m_buffer_tx,1,m_buffer_rx,1);

    // Chip select go high to end a flash command
    cs_high();

 
    return FlashOperationSuccess;
}



/*
 * Function:       CMD_WRSR
 * Arguments:      UpdateValue, 8/16 bit status register value to updata
 * Description:    The WRSR instruction is for changing the values of
 *                 Status Register Bits (and configuration register)
 * Return Message: FlashIsBusy, FlashTimeOut, FlashOperationSuccess
 */

//ReturnMsg cmd_wrsr( uint8_t UpdateValue )
//
//{
//    // Check flash is busy or not
//    if( IsFlashBusy() )    return FlashIsBusy;
//
//    // Setting Write Enable Latch bit
//    uint8_t err_code;
//   err_code = cmd_wren();
//
//    // Chip select go low to start a flash command
////    cs_low();
//
//    // Send command and update value
//
//    uint8_t instruction[9] = {0};
//    instruction[0] = FLASH_CMD_WRSR;
//    nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)instruction,1,m_buffer_rx,3); 
//    nrf_delay_ms(2);
//    printf(&amp;quot;UPDATE VALUE  = %d&amp;quot;,UpdateValue);
//    instruction[1]=UpdateValue;
////    memcpy(instruction[1],UpdateValue,8);
//    nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)instruction[1],2,m_buffer_rx,4); 
//
////#ifdef SUPPORT_WRSR_CR
////    SendByte( UpdateValue &amp;gt;&amp;gt; 8, SIO );    // write configuration register
////#endif
//
//    // Chip select go high to end a flash command
//    cs_high();
//
//
//    if( WaitFlashReady( WriteStatusRegCycleTime ) )
//        return FlashOperationSuccess;
//    else
//        return FlashTimeOut;
//
//}



ReturnMsg cmd_wrsr( uint8_t UpdateValue )

{
    // Check flash is busy or not
    if( IsFlashBusy() )    return FlashIsBusy;

    // Setting Write Enable Latch bit
    uint8_t err_code;
    uint8_t read_value;
        nrf_gpio_pin_clear(SPI_WP_PIN);
   err_code = cmd_wren();

    // Chip select go low to start a flash command
//    cs_low();

    // Send command and update value
   err_code =  cmd_rdsr(read_value);
   printf(&amp;quot;rdsr valu = %d \n&amp;quot;,read_value);
   if((read_value &amp;amp; 2)== 1)
  {
     uint8_t instruction[9] = {0};
    instruction[0] = FLASH_CMD_WRSR;
    nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)instruction,1,m_buffer_rx,3); 
    nrf_delay_ms(2);
    printf(&amp;quot;UPDATE VALUE  = %d&amp;quot;,UpdateValue);
    instruction[1]=UpdateValue;
//    memcpy(instruction[1],UpdateValue,8);
    nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)instruction[1],2,m_buffer_rx,4); 

    err_code =  cmd_rdsr(read_value);
   printf(&amp;quot;rdsr valu = %d \n&amp;quot;,read_value);
   if((read_value ^ 1)==1)
   {
      printf(&amp;quot;wep is zero \n&amp;quot;);
    
   }

  }


//    uint8_t instruction[9] = {0};
//    instruction[0] = FLASH_CMD_WRSR;
//    nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)instruction,1,m_buffer_rx,3); 
//    nrf_delay_ms(2);
//    printf(&amp;quot;UPDATE VALUE  = %d&amp;quot;,UpdateValue);
//    instruction[1]=UpdateValue;
////    memcpy(instruction[1],UpdateValue,8);
//    nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)instruction[1],2,m_buffer_rx,4); 

//#ifdef SUPPORT_WRSR_CR
//    SendByte( UpdateValue &amp;gt;&amp;gt; 8, SIO );    // write configuration register
//#endif

    // Chip select go high to end a flash command
    cs_high();


    if( WaitFlashReady( WriteStatusRegCycleTime ) )
        return FlashOperationSuccess;
    else
        return FlashTimeOut;

}


/*
 * Function:       CMD_RDSCUR
 * Arguments:      SecurityReg, 8 bit buffer to store security register value
 * Description:    The RDSCUR instruction is for reading the value of
 *                 Security Register bits.
 * Return Message: FlashOperationSuccess
 */
ReturnMsg cmd_rdscur( uint8_t *SecurityReg )
{
    uint8_t  gDataBuffer;

    // Chip select go low to start a flash command
    cs_low();

    //Send command
    
    uint8_t instruction = FLASH_CMD_RDSCUR;
    nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)instruction,1,gDataBuffer,3); 

    // Chip select go high to end a flash command
    cs_high();

    *SecurityReg = gDataBuffer;

    return FlashOperationSuccess;

}

/*
 * Function:       CMD_WRSCUR
 * Arguments:      None.
 * Description:    The WRSCUR instruction is for changing the values of
 *                 Security Register Bits.
 * Return Message: FlashIsBusy, FlashOperationSuccess, FlashWriteRegFailed,
 *                 FlashTimeOut
 */
ReturnMsg cmd_wrscur( void )
{
    uint8_t  gDataBuffer;

    // Check flash is busy or not
    if( IsFlashBusy() )    return FlashIsBusy;

    // Setting Write Enable Latch bit
    cmd_wren();

    // Chip select go low to start a flash command
    cs_low();

    // Write WRSCUR command
    uint8_t instruction = FLASH_CMD_WRSCUR;
    nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)instruction,1,gDataBuffer,3); 

    // Chip select go high to end a flash command
    cs_high();

    if( WaitFlashReady( WriteSecuRegCycleTime ) ){

        cmd_rdscur( &amp;amp;gDataBuffer );

        // Check security register LDSO bit
        if( (gDataBuffer &amp;amp; FLASH_LDSO_MASK) == FLASH_LDSO_MASK )
                return FlashOperationSuccess;
        else
                return FlashWriteRegFailed;
    }
    else
        return FlashTimeOut;

}


/*
 * Function:       CMD_RDID
 * Arguments:      Identification, 32 bit buffer to store id
 * Description:    The RDID instruction is to read the manufacturer ID
 *                 of 1-byte and followed by Device ID of 2-byte.
 * Return Message: FlashOperationSuccess
 */
ReturnMsg cmd_rdid( uint32_t *Identification )
{
    uint32_t temp;
    uint8_t  gDataBuffer[3];

    // Chip select go low to start a flash command
    cs_low();

    // Send command
//    SendByte( FLASH_CMD_RDID, SIO );
    uint8_t instruction = FLASH_CMD_RDID;
    nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)instruction,1,gDataBuffer,3); 

   
   

    // Chip select go high to end a command
    cs_high();

    // Store identification
    temp =  gDataBuffer[0];
    temp =  (temp &amp;lt;&amp;lt; 8) | gDataBuffer[1];
    *Identification =  (temp &amp;lt;&amp;lt; 8) | gDataBuffer[2];
    printf(&amp;quot;rdid = %x  %x&amp;quot;,gDataBuffer [0],gDataBuffer [1]);

    return FlashOperationSuccess;
}

/*
 * Function:       CMD_RES
 * Arguments:      ElectricIdentification, 8 bit buffer to store electric id
 * Description:    The RES instruction is to read the Device
 *                 electric identification of 1-byte.
 * Return Message: FlashOperationSuccess
 */
ReturnMsg cmd_res( uint8_t *ElectricIdentification )
{

    printf(&amp;quot;cmd_res \n&amp;quot;);
    // Chip select go low to start a flash command
    cs_low();

    // Send flash command and insert dummy cycle
     uint8_t instruction[4];
    instruction[0]= FLASH_CMD_RES;
    instruction[1]= 0;
    instruction[2]=0;
    instruction[3]=0;
    nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)instruction,4,m_buffer_rx,5); 
    // Get electric identification
    *ElectricIdentification = m_buffer_rx[4];
    printf(&amp;quot; eid = %x\n&amp;quot;,m_buffer_rx[4]);
    // Chip select go high to end a flash command
  cs_high();

    return FlashOperationSuccess;
}

/*
 * Function:       CMD_REMS
 * Arguments:      REMS_Identification, 16 bit buffer to store id
 *                 fsptr, pointer of flash status structure
 * Description:    The REMS instruction is to read the Device
 *                 manufacturer ID and electric ID of 1-byte.
 * Return Message: FlashOperationSuccess
 */
ReturnMsg cmd_rems( uint16_t *REMS_Identification, FlashStatus *fsptr )
{
    uint8_t  gDataBuffer[2];

    // Chip select go low to start a flash command
    cs_low();

    // Send flash command and insert dummy cycle ( if need )
    // ArrangeOpt = 0x00 will output the manufacturer&amp;#39;s ID first
    //            = 0x01 will output electric ID first
//    SendByte( FLASH_CMD_REMS, SIO );
//    InsertDummyCycle( 16 );
//    SendByte( fsptr-&amp;gt;ArrangeOpt, SIO );
    uint8_t instruction[4];
    instruction[0]= FLASH_CMD_REMS;
    instruction[1]= 0;
    instruction[2]=0;
     instruction[3]=0x00;
    nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)instruction,4,m_buffer_rx,6); 
    // Get ID
    gDataBuffer[0] = m_buffer_rx[2];//GetByte( SIO );
    gDataBuffer[1] = m_buffer_rx[3];//GetByte( SIO );

    // Store identification informaion
    *REMS_Identification = (gDataBuffer[0] &amp;lt;&amp;lt; 8) | gDataBuffer[1];

    // Chip select go high to end a flash command
    cs_high();

    return FlashOperationSuccess;
}

void cmd_read( uint32_t flash_address, uint8_t *target_address, uint32_t byte_length )
{
    uint32_t index;
    uint8_t  addr_4byte_mode;

    // Check flash address
    if( flash_address &amp;gt; FlashSize ) 
      return FlashAddressInvalid;
    nrf_delay_ms(5);

    // Chip select go low to start a flash command
    cs_low();

    // Write READ command and address

    uint8_t instruction;
    instruction = FLASH_CMD_READ;
    m_buffer_tx[0]= instruction;
    m_buffer_tx[1] = flash_address &amp;gt;&amp;gt; 16;
    m_buffer_tx[2] = flash_address &amp;gt;&amp;gt; 8;
    m_buffer_tx[3] = flash_address;
    nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)m_buffer_tx,FLASH_CMD_READ_LENGHT,m_data_receive,FLASH_CMD_READ_LENGHT+16); 
//    for( index=0; index &amp;lt; 4; index++ )
//    {
//      printf(&amp;quot;m_buffer_tx[%d] = %.02x \n&amp;quot;,index,m_buffer_tx[index]);
//      nrf_delay_ms(10);
//    }
   
//    for( index=0; index &amp;lt; 20; index++ )
//    {
//      printf(&amp;quot;m_data_receive[%d] = %.02x \n&amp;quot;,index,m_data_receive[index]);
//      nrf_delay_ms(10);
//    }

    // Chip select go high to end a flash command
   nrf_delay_ms(500);
   cs_high();

    return true;
}

/*
 * Function:       Wait_Flash_WarmUp
 * Arguments:      None.
 * Description:    Wait some time until flash read / write enable.
 * Return Message: None.
 */
void wait_flash_warm_up()
{
    uint32_t time_cnt = FlashFullAccessTime;
    while( time_cnt &amp;gt; 0 )
    {
        time_cnt--;
    }
}
uint8_t flash_ID_test( uint8_t id )
{

  uint8_t instruction[8] = {0};

  uint8_t id_read = id;
  switch (id_read)  
  {
            case 1:
                
                instruction[0] = FLASH_CMD_RES ;
                instruction[1]= 0x00;
                instruction[2] = 0x00;
                instruction[3]= 0x00;
                cs_low();
                nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)instruction,4,m_buffer_rx,5); 
                nrf_delay_ms(1);
                printf(&amp;quot;\rValue is 1:&amp;quot;);
                 printf(&amp;quot;%02x,%02x,%02x,%02x,%02x,%02x,%02x \n&amp;quot;,m_buffer_rx[0],m_buffer_rx[1],m_buffer_rx[2],m_buffer_rx[3],m_buffer_rx[4],m_buffer_rx[5],m_buffer_rx[6]);
                cs_high();
                break;
            case 2:
                
                instruction[0] = FLASH_CMD_REMS ;
                instruction[1]= 0x01;
                instruction[2] = 0x02;
                instruction[3]= 0x00;
                printf(&amp;quot;\rValue is 2:&amp;quot;);
                nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)instruction,4,m_buffer_rx,6); 
                nrf_delay_ms(2);
                printf(&amp;quot;%02x,%02x,%02x,%02x,%02x,%02x\n&amp;quot;,m_buffer_rx[0],m_buffer_rx[1],m_buffer_rx[2],m_buffer_rx[3],m_buffer_rx[4],m_buffer_rx[5]);
                break;
            case 3:               
                m_buffer_tx[0] = FLASH_CMD_RDID;
                cs_low();
//                nrf_gpio_pin_clear(SPI_SS_PIN);
                nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)m_buffer_tx,1,m_buffer_rx,4); 
                //nrf_delay_ms(2);
                //nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)m_buffer_tx,1,m_buffer_rx,3); 
                 nrf_delay_ms(2);
                 printf(&amp;quot;\rValue is 3:&amp;quot;);
                 printf(&amp;quot;%02x,%02x,%02x\n&amp;quot;,m_buffer_rx[1],m_buffer_rx[2],m_buffer_rx[3]);
//                nrf_gpio_pin_set(SPI_SS_PIN);
                cs_high();
                break;
            default:
                printf(&amp;quot;Out of range&amp;quot;);
                break;

  }

   return true;
}


ReturnMsg cmd_rdsr( uint8_t *StatusReg )
{
    uint8_t  gDataBuffer;

    // Chip select go low to start a flash command
    cs_low();

    // Send command

    nrf_drv_spi_transfer(&amp;amp;spi,FLASH_CMD_RDSR,1,gDataBuffer,1); 
    // Chip select go high to end a flash command
    cs_high();

    *StatusReg = gDataBuffer;
//     printf(&amp;quot;cmd_rdsr =  %d \n&amp;quot;,gDataBuffer);

    return FlashOperationSuccess;
}

ReturnMsg cmd_rdcr( uint8_t *StatusReg )
{
    uint8_t  gDataBuffer;

    // Chip select go low to start a flash command
     cs_low();

    // Send command
//    SendByte( FLASH_CMD_RDSR, SIO );
//    gDataBuffer = GetByte( SIO );
    nrf_drv_spi_transfer(&amp;amp;spi,FLASH_CMD_RDCR,1,gDataBuffer,1); 
    // Chip select go high to end a flash command
    cs_high();

    *StatusReg = gDataBuffer;
//    printf(&amp;quot;status register = %x \n&amp;quot;,StatusReg);

    return FlashOperationSuccess;
}


bool IsFlashBusy( void )
{
    uint8_t  gDataBuffer;

    cmd_rdsr( &amp;amp;gDataBuffer );
    
    if( (gDataBuffer &amp;amp; FLASH_WIP_MASK)  == FLASH_WIP_MASK )
        return true;
    else
        return false;
}

bool WaitFlashReady( uint32_t ExpectTime )
{

    uint32_t temp = 0;
    while( IsFlashBusy() )
    {
        if( temp &amp;gt; ExpectTime )
        {
            return false;
        }
        temp = temp + 1;
    }
       return true;
}

ReturnMsg cmd_wren( void )
{
    // Chip select go low to start a flash command
    cs_low();

    // Write Enable command = 0x06, Setting Write Enable Latch Bit
    uint8_t instruction = FLASH_CMD_WREN;
    m_buffer_tx[0] = instruction;
    
   nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)m_buffer_tx,1,m_buffer_rx,1);
    // Chip select go high to end a flash command
    cs_high();

    return FlashOperationSuccess;
}



ReturnMsg cmd_wrdis( void )
{
    // Chip select go low to start a flash command
    cs_low();

    // Write Enable command = 0x06, Setting Write Enable Latch Bit
    uint8_t instruction = FLASH_CMD_WRDI;
    m_buffer_tx[0] = instruction;
    
   nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)m_buffer_tx,1,m_buffer_rx,1);
    // Chip select go high to end a flash command
    cs_high();

    return FlashOperationSuccess;
}

ReturnMsg cmd_pp( uint32_t flash_address, uint8_t *source_address, uint32_t byte_length )
{
    uint32_t index;
    // Check flash address
    if( flash_address &amp;gt; FLASH_SIZE ) return FlashAddressInvalid;
    //
    //    // Check flash is busy or not
    if( IsFlashBusy() )    return FlashIsBusy;

    // Setting Write Enable Latch bit
    cmd_wren();
    
    nrf_delay_ms(5);

    // Chip select go low to start a flash command
    cs_low();
    nrf_delay_ms(100);

    // Write Page Program command
    uint8_t len = 4;
    m_buffer_tx[0]=FLASH_CMD_PP;
//    memcpy(m_buffer_tx,instruction,4);
    //    nrf_drv_spi_transfer(&amp;amp;spi,instruction,len,m_buffer_rx,len+1); 
    memcpy(m_buffer_tx[4],flash_address &amp;gt;&amp;gt; 16,1);

    m_buffer_tx[1] = flash_address &amp;gt;&amp;gt; 16;
    m_buffer_tx[2] = flash_address &amp;gt;&amp;gt; 8;
    m_buffer_tx[3] = flash_address;

    for( index=4; index &amp;lt; 20; index++ )
    {
       m_buffer_tx[index] = source_address[index];//0xaa;
    }
     printf(&amp;quot;\r data transmitted:  &amp;quot;);
           for( index=0; index &amp;lt; 20; index++ )
          {
            printf(&amp;quot; %.02x &amp;quot;,m_buffer_tx[index]);
            nrf_delay_ms(10);
          }
          printf(&amp;quot;\n&amp;quot;);

//    nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)m_buffer_tx,20,m_data_receive,40);
        nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)m_buffer_tx,20,m_data_receive,0);
    // Chip select go high to end a flash command
    cs_high();

    if( WaitFlashReady( PageProgramCycleTime ) )
        return FlashOperationSuccess;
    else
      return FlashTimeOut;
}

uint8_t cmd_se( uint32_t flash_address )
{
    // Check flash address
    if( flash_address &amp;gt; FLASH_SIZE ) return FlashAddressInvalid;

    // Check flash is busy or not
    if( IsFlashBusy() )    return FlashIsBusy;

    // Setting Write Enable Latch bit
    cmd_wren();

    // Chip select go low to start a flash command
    cs_low();

    //Write Sector Erase command = 0x20;

    m_buffer_tx[0] = FLASH_CMD_SE;
    m_buffer_tx[1] = flash_address &amp;gt;&amp;gt; 16;
    m_buffer_tx[2] = flash_address &amp;gt;&amp;gt; 8;
    m_buffer_tx[3] = flash_address;

    printf(&amp;quot; \r sectore esrase command : %0.2x,%0.2x,%0.2x,%0.2x\n &amp;quot;,m_buffer_tx[0],m_buffer_tx[1],m_buffer_tx[2],m_buffer_tx[3]);

    nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)m_buffer_tx,4,m_buffer_rx,4); 
    // Chip select go high to end a flash command
    cs_high();

//    if( WaitFlashReady( SectorEraseCycleTime ) )
    if( WaitFlashReady( 240000000 ))
    {
        cmd_rdscur(SecurityReg);
        printf(&amp;quot;SecurityReg   %d \n &amp;quot;,SecurityReg);
        return FlashOperationSuccess;
    }
    else
        return FlashTimeOut;
}

uint8_t cmd_block_erase( uint32_t flash_address )
{
    // Check flash address
    if( flash_address &amp;gt; FLASH_SIZE ) return FlashAddressInvalid;

    // Check flash is busy or not
    if( IsFlashBusy() )    return FlashIsBusy;

    // Setting Write Enable Latch bit
//    cmd_wren();

    // Chip select go low to start a flash command
    cs_low();

    //Write Sector Erase command = 0x20;
    uint8_t instruction;
    instruction= FLASH_CMD_SE;
//    instruction[1]= 0;
//    instruction[2] =0;
//    instruction[3]=0;
    m_buffer_tx[0] = instruction;
//    memcpy(m_buffer_tx,instruction,4);
    m_buffer_tx[1] = flash_address &amp;gt;&amp;gt; 16;
    m_buffer_tx[2] = flash_address &amp;gt;&amp;gt; 8;
    m_buffer_tx[3] = flash_address;

//    SendByte( FLASH_CMD_SE, SIO );
//    SendFlashAddr( flash_address, SIO, addr_4byte_mode );
    nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)m_buffer_tx,4,m_buffer_rx,4); 
    // Chip select go high to end a flash command
    cs_high();

    if( WaitFlashReady( SectorEraseCycleTime ) )
        return FlashOperationSuccess;
    else
        return FlashTimeOut;
}

/*
 * Function:       CMD_CE
 * Arguments:      None.
 * Description:    The CE instruction is for erasing the data
 *                 of the whole chip to be &amp;quot;1&amp;quot;.
 * Return Message: FlashIsBusy, FlashOperationSuccess, FlashTimeOut
 */
ReturnMsg cmd_ce( void )
{
    // Check flash is busy or not
    if( IsFlashBusy() )    return FlashIsBusy;

    // Setting Write Enable Latch bit
    cmd_wren();

    // Chip select go low to start a flash command
    cs_low();
    nrf_delay_ms(100);
    //Write Chip Erase command = 0x60;
     m_buffer_tx[0] = 0xC7;//FLASH_CMD_CE;
     nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)m_buffer_tx,1,m_buffer_rx,0);

    // Chip select go high to end a flash command
    cs_high();
//    cmd_rdsr(StatusReg);
//    printf(&amp;quot;StatusReg= %d \n&amp;quot;,StatusReg);

    //if( WaitFlashReady( 60000 ) )
      nrf_delay_ms(60000);
        return FlashOperationSuccess;
//    else
//        return FlashTimeOut;
//return FlashOperationSuccess;
}


/*
 * Simple flash read/write test
 */
uint8_t flash_read_write_test( void )
{
    uint8_t  message= 0;
    FlashStatus  flash_state = {0};

    uint32_t  flash_addr;
    uint32_t  trans_len = 0;
    uint16_t  i=0, error_cnt = 0;
    uint16_t  seed = 0;
    uint8_t   st_reg = 0;

    /* Assign initial condition */
    flash_addr = FLASH_TARGET_ADDR;
    trans_len = TRANS_LENGTH;
    seed = RANDOM_SEED;

    /* Erase 4K sector of flash memory
       Note: It needs to erase dirty sector before program */
    uint8_t err_code;
//    err_code = cmd_ce();//cmd_block_erase(flash_addr);//cmd_se( flash_addr );
//    printf(&amp;quot;error code = %d \n&amp;quot;,err_code);
//     nrf_delay_ms(300);


//    cmd_read( flash_addr, m_data_receive, TRANS_LENGTH );
//     nrf_delay_ms(300);
//
//                printf(&amp;quot;\r data after chip erase:  &amp;quot;);
//           for( i=4; i &amp;lt; 20; i++ )
//          {
//            printf(&amp;quot; %.02x &amp;quot;,m_data_receive[i]);
//            nrf_delay_ms(10);
//          }
//          printf(&amp;quot;\n&amp;quot;);
    

    /* Program data to flash memory */
    cmd_pp( flash_addr, m_data_send, TRANS_LENGTH );
    nrf_delay_ms(100);

    /* Read flash memory data to memory buffer */
    cmd_read( flash_addr, m_data_receive, TRANS_LENGTH );
     nrf_delay_ms(300);

    /* Compare original data and flash data */
    
//    for( i=4; i &amp;lt; (trans_len); i=i+1 )
//    {
//        if( m_data_send[i] != m_data_receive[i] )
//        {
//            printf(&amp;quot;wrong data \n&amp;quot;);
//            Error_inc( error_cnt );
//        }
//        else
//         {
           printf(&amp;quot;\r data received:  &amp;quot;);
           for( i=4; i &amp;lt; 20; i++ )
          {
            printf(&amp;quot; %.02x &amp;quot;,m_data_receive[i]);
            nrf_delay_ms(10);
          }
          printf(&amp;quot;\n&amp;quot;);

//         }
//    }
    
    /* Erase 4K sector of flash memory */
    cmd_ce();//cmd_block_erase(flash_addr); //cmd_se( flash_addr );
    nrf_delay_ms(240); //240    60000


    if( error_cnt != 0 )
        return false;
    else
        return true;

}
uint8_t ext_flash_init(void)
{

    uint8_t retval = false;

    /* Configure SPI pins */
    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    spi_config.ss_pin   = SPI_SS_PIN;
    spi_config.miso_pin = SPI_MISO_PIN;
    spi_config.mosi_pin = SPI_MOSI_PIN;
    spi_config.sck_pin  = SPI_SCK_PIN;
    spi_config.mode     = NRF_DRV_SPI_MODE_0;
    spi_config.frequency= NRF_DRV_SPI_FREQ_125K;
    APP_ERROR_CHECK(nrf_drv_spi_init(&amp;amp;spi, &amp;amp;spi_config, spi_event_handler, NULL));

    nrf_gpio_pin_set(SPI_WP_PIN);

    uint8_t err_code;
    cmd_rsten();
    cmd_rst();
    err_code = cmd_wrdis();

    /* Set CS pin to High*/

//    cs_high();

    wait_flash_warm_up();
    nrf_delay_ms(100);
    flash_ID_test(2);

    /* read and verify manufacturer and device id from external flash to ensure external flash is working */
    if(flash_ID_test(2) == true)
    {
       return true;
    }



    return retval;
}


&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/204953?ContentTypeID=1</link><pubDate>Tue, 20 Aug 2019 08:43:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b18e06f4-357d-4acd-8225-e95267ee1473</guid><dc:creator>sara</dc:creator><description>&lt;p&gt;Ok sharing with you the datasheet and the code which I am using. I added delay after CS_LOW so I am able to get the chip erase done. but still the issue is that after sending chip erase function I am not abl to write it. Also sector earse is not working ,I think I am struggling with the timing issues. I will be grateful if you can help me with these issues and make my flash running propelry.&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/MX25R1635F_2C00_-Wide-Range_2C00_-16Mb_2C00_-v1.6.pdf"&gt;devzone.nordicsemi.com/.../MX25R1635F_2C00_-Wide-Range_2C00_-16Mb_2C00_-v1.6.pdf&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/204930?ContentTypeID=1</link><pubDate>Tue, 20 Aug 2019 08:04:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1ae3c18a-b12c-4abf-877c-b110ac273a95</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This should be described in the datasheet of your flash device.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you can&amp;#39;t find it there please share the datasheet with me, and I will have a look.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/204802?ContentTypeID=1</link><pubDate>Mon, 19 Aug 2019 13:40:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b7fdc2b3-698c-4abf-8e73-6c57437ec422</guid><dc:creator>sara</dc:creator><description>&lt;p&gt;Hi Torbjorn,&lt;/p&gt;
&lt;p&gt;I am able to read the data now.It was due to some hardware issues that I was not able to read on MISO line.But now I am facing issue in erasing the chip.what else do I need to send to erase chip/ sector/block with it&amp;#39;s instruction command?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/204676?ContentTypeID=1</link><pubDate>Mon, 19 Aug 2019 09:01:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:04bf8893-0004-4508-86bc-c03b92d8579e</guid><dc:creator>sara</dc:creator><description>&lt;p&gt;I am able to see only a high pulse on MISO line on logic analyser. I did try RDID command I am getting correct values but data which I get is always 0XFF.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/204630?ContentTypeID=1</link><pubDate>Mon, 19 Aug 2019 06:38:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eeac5f30-78dd-4481-a44b-73c3968de25c</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Can you see on the logic analyzer what the MISO data actually is?&lt;/p&gt;
&lt;p&gt;In other words, is the problem that the MISO data doesn&amp;#39;t make it into the nRF52832, or is the problem that the external flash device doesn&amp;#39;t output anything on MISO?&lt;/p&gt;
&lt;p&gt;Did you try to issue the RDID command?&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/203930?ContentTypeID=1</link><pubDate>Wed, 14 Aug 2019 04:50:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:992cec4f-330c-431b-80af-5c296e44eef5</guid><dc:creator>sara</dc:creator><description>&lt;p&gt;Hi , Torbjorn,&lt;/p&gt;
&lt;p&gt;I tried interfacing the external flash with nrf52832. I a able to see the MOSI data which I send on Logic analyzer and it shows correct data but I am not able to get the data on MISO. it always gives 0xFF.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So what should I do&amp;nbsp; now?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;And I also referred the following link :&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/37196/spi-miso-data-is-not-reflecting-on-the-receive-buffer"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/37196/spi-miso-data-is-not-reflecting-on-the-receive-buffer&lt;/a&gt;&amp;nbsp;but still the same problem persists.&lt;/p&gt;
&lt;p&gt;when I send write instruction - My tx buffer size is 20 bytes( 4 instruction byte and 16 data bytes) and I also kept by rx buffer size as 20&amp;nbsp;&lt;/p&gt;
&lt;p&gt;when I send read instruction -&lt;span&gt;My tx buffer size is 4 bytes( 1 bytes opcode and 3 byte address to read from) and I also kept by rx buffer size as 20 still not getting data even though the data bytes is 16&lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/203202?ContentTypeID=1</link><pubDate>Fri, 09 Aug 2019 06:20:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:47b9aa08-2065-429a-b95e-63ac046f8566</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t think we have an example for this kind of flash device unfortunately.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You would have to set up the SPI interface yourself using the nrfx_spim driver ideally, and implement the functions you need from the device as described in the datasheet.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I suggest starting with the RDID command, as it lets you read a known value from the device which you can use to ensure that the SPI communication is working OK, that you are using the right SPI mode etc.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/202957?ContentTypeID=1</link><pubDate>Thu, 08 Aug 2019 06:42:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ae62c98f-98a4-4046-afaf-5b50ee2eb2a8</guid><dc:creator>sara</dc:creator><description>&lt;p&gt;I want to interface MX25R1635F FLASH memory with nrf52832. And no file system but want to access its read,write and erase commands. I have seen the qspi example but got confused with it as my I have nrf52832 that does not support QSPI.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Interface External flash to nrf52832</title><link>https://devzone.nordicsemi.com/thread/202956?ContentTypeID=1</link><pubDate>Thu, 08 Aug 2019 06:39:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:359a67f6-8fa3-4462-be37-227d0dcba4bd</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;What kind of external flash device do you want to connect?&lt;/p&gt;
&lt;p&gt;Are you planning to use a file system, or will you just access the flash using low level read/write/erase commands?&lt;/p&gt;
&lt;p&gt;The usbd_msc example in the SDK allows you to access SD cards over the SPI interface, if you compile the example with the&amp;nbsp;USE_SD_CARD define set to 1 (located on line 106 of main.c).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Unfortunately this example is designed for the nRF52840 only, since it uses the USB interface in the nRF52840 to enumerate the connected SD card as a flash drive when connected to a PC.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>