<?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>Problem Interfacing SPI external Flash and writing to the Flash Registers</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/65400/problem-interfacing-spi-external-flash-and-writing-to-the-flash-registers</link><description>Hi, 
 I am trying to interface External Flash (IS25LP064A ) using SPI example in SDK v16. I am able to read the Manufacturer_ID and the device ID from the external flash. Now I want to Read, write and Erase the flash. But I am unable to do so. Please</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 08 Sep 2020 05:51:45 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/65400/problem-interfacing-spi-external-flash-and-writing-to-the-flash-registers" /><item><title>RE: Problem Interfacing SPI external Flash and writing to the Flash Registers</title><link>https://devzone.nordicsemi.com/thread/268393?ContentTypeID=1</link><pubDate>Tue, 08 Sep 2020 05:51:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:297697a0-42b4-48ee-bca7-be13a9576422</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;I would suggest using &lt;span&gt;a scope or analyzer on the&lt;/span&gt;&lt;span&gt;&amp;nbsp;SPI bus to check.&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;As I said at first, I don&amp;#39;t think we have an example for that flash. You might search other flash cases on DZ for reference.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;-Amanda H.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem Interfacing SPI external Flash and writing to the Flash Registers</title><link>https://devzone.nordicsemi.com/thread/267847?ContentTypeID=1</link><pubDate>Thu, 03 Sep 2020 13:04:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e415d86c-337d-4a71-b640-b451097eb406</guid><dc:creator>Mushtakh Shaikh</dc:creator><description>&lt;p&gt;Yes I did that too. But Still not able to write and read the data to and from the external flash.&lt;/p&gt;
&lt;p&gt;Can u please provide any sample code that will help?.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem Interfacing SPI external Flash and writing to the Flash Registers</title><link>https://devzone.nordicsemi.com/thread/267829?ContentTypeID=1</link><pubDate>Thu, 03 Sep 2020 12:13:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ede0f684-b5c7-4bc1-b88f-afba70e6de47</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Did you change the code to &lt;br /&gt;printf(&amp;quot;Rdsr-stat: %02X\n&amp;quot;,spi_rx_cmd[2]);&lt;br /&gt;printf(&amp;quot;Rdsd stat %02X\n&amp;quot;,spi_rx_cmd[3]);&lt;/p&gt;
&lt;p&gt;after increasing rx_buffer_length to 4?&lt;/p&gt;
&lt;p&gt;-Amanda H.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem Interfacing SPI external Flash and writing to the Flash Registers</title><link>https://devzone.nordicsemi.com/thread/267813?ContentTypeID=1</link><pubDate>Thu, 03 Sep 2020 11:29:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:189aa25f-a3b7-48aa-9867-47b9619e1b61</guid><dc:creator>Mushtakh Shaikh</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Can u please tell me what went&amp;nbsp; wrong in my code ??&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem Interfacing SPI external Flash and writing to the Flash Registers</title><link>https://devzone.nordicsemi.com/thread/267727?ContentTypeID=1</link><pubDate>Thu, 03 Sep 2020 05:08:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3b010d2a-4d77-4bd8-8b2c-72bb6d7fcf67</guid><dc:creator>Mushtakh Shaikh</dc:creator><description>&lt;p&gt;This is the output when after read_status_register();&lt;/p&gt;
&lt;p&gt;I have changed the rx_buffer_length to 4 as per your suggestion.Still I am unable to write the data to flash and read the data from flash. Please help me with any code example if u have.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Status_Reg_Err_code : 0&lt;br /&gt;Rdsr-stat: 00&lt;br /&gt;Rdsd stat 00&lt;br /&gt;RDSR Transfer Successful&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem Interfacing SPI external Flash and writing to the Flash Registers</title><link>https://devzone.nordicsemi.com/thread/267726?ContentTypeID=1</link><pubDate>Thu, 03 Sep 2020 05:04:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e213d1ee-690e-4ff6-b8f6-2170fa485a33</guid><dc:creator>Mushtakh Shaikh</dc:creator><description>&lt;p&gt;After write_enable, I am getting the following output.&lt;/p&gt;
&lt;p&gt;RDID_3 Transfer Successful&lt;br /&gt;Flash_ID_3: 0&lt;br /&gt;Manufacturer_ID: 9d Memory_Type : 60, Capacity:17&lt;br /&gt;Write_enable_err_code : 0&lt;br /&gt;WREN Transfer Successful&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem Interfacing SPI external Flash and writing to the Flash Registers</title><link>https://devzone.nordicsemi.com/thread/267646?ContentTypeID=1</link><pubDate>Wed, 02 Sep 2020 13:32:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f55fea28-037b-4124-90c4-8701471c14e3</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
[quote user="Mushtakh Shaikh"]I am unable to set the WEL using WREN command.[/quote]
&lt;p&gt;Did you get any error, out log, or &lt;span&gt;logic trance of the SPI bus for&lt;/span&gt;&amp;nbsp;the&amp;nbsp;write_enable()?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Mushtakh Shaikh"]The only output I am getting after reading a status register or any adress is 0.[/quote]
&lt;p&gt;&amp;nbsp;Could you try to increase the&amp;nbsp;&lt;span&gt;rx_buffer_length to 4 as this &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/37196/spi-miso-data-is-not-reflecting-on-the-receive-buffer/144359#144359"&gt;suggestion&lt;/a&gt;?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;-Amanda H.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem Interfacing SPI external Flash and writing to the Flash Registers</title><link>https://devzone.nordicsemi.com/thread/267581?ContentTypeID=1</link><pubDate>Wed, 02 Sep 2020 09:52:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8c71e456-19a7-4e8d-905e-78a8b295d035</guid><dc:creator>Mushtakh Shaikh</dc:creator><description>&lt;p&gt;HI Amanda,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Here is my complete code. and here is the data sheet.&amp;nbsp;&lt;a href="http://www.issi.com/WW/pdf/25LP032-64A-B.pdf"&gt;http://www.issi.com/WW/pdf/25LP032-64A-B.pdf&lt;/a&gt;. I am trying to read and write data to flash. But I am unable to write or read. Also I am unable to set the WEL using WREN command. The only output I am getting after reading a status register or any adress is 0. Please let me know what&amp;#39;s the missing things in my code. Please help me with any example code if u have or please let me know what is wrong or missing in my code.&lt;pre class="ui-code" data-mode="text"&gt;/**
 * Copyright (c) 2015 - 2019, Nordic Semiconductor ASA
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA &amp;quot;AS IS&amp;quot; AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
#include &amp;quot;nrf_drv_spi.h&amp;quot;
#include &amp;quot;app_util_platform.h&amp;quot;
#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;lt;string.h&amp;gt;
#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;



/* Flash memory parameters */
#define FLASH_PAGESIZE          256                     /* 256 Bytes */         /**&amp;lt; External Flash - Page Size */
#define FLASH_SECTORSIZE        (16 * FLASH_PAGESIZE)	/* 16 Pages = 4KB */    /**&amp;lt; External Flash - Sector Size */
#define FLASH_BLOCKSIZE		(16 * FLASH_SECTORSIZE)	/* 16 Sectors = 64KB */ /**&amp;lt; External Flash - Block Size */
#define FLASH_SIZE              (128 * FLASH_BLOCKSIZE)	/* 128 Blocks = 8MB */  /**&amp;lt; External Flash - Total Memory Size */
#define FLASH_BLOCK32K		(32 * 1024)		/* 32KB Block */   
#define FLASH_PAGESIZE_OFFSET    0x000100


#define REG_SR_BIT_WIP    0
#define READ_WRITE_LENGTH 200
#define SPI_INSTANCE  0 /**&amp;lt; SPI instance index. */
static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);  /**&amp;lt; SPI instance. */
static volatile bool spi_xfer_done;  /**&amp;lt; Flag used to indicate that SPI instance completed the transfer. */


#define WAIT_FOR_PERIPH() do { \
        while (!m_finished) {} \
        m_finished = false;    \
    } while (0)

#define TEST_STRING &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);        /**&amp;lt; Transfer length. */



static uint8_t m_buffer_rx[256];
static uint8_t m_buffer_tx[256];


void cs_low(void)
{

  nrf_gpio_pin_clear(SPI_SS_PIN);
}

void cs_high(void)
{

   nrf_gpio_pin_set(SPI_SS_PIN);
}


uint8_t flash_ID_test( uint8_t id )
{
  ret_code_t err_code;
  static uint8_t instruction[8] = {0};
  
  uint8_t id_read = id;
  switch (id_read)  
  {
            case 1:
                
                instruction[0] = 0xAB ;//RDID Command: Read Manufacturer and Product ID
                instruction[1] = 0x00;
                instruction[2] = 0x00;
                instruction[3] = 0x00;

               spi_xfer_done = false;
               cs_low();
               err_code = nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)instruction,sizeof(instruction),m_buffer_rx,7);
               if(err_code == NRF_SUCCESS)
               {
                    printf(&amp;quot;RDID Transfer Successful\n&amp;quot;);
               }
               printf(&amp;quot;Flash_ID_1: %d\n&amp;quot;,err_code);
               while(spi_xfer_done == false)
               {}
               printf(&amp;quot;\rDevice ID is :&amp;quot;);
               printf(&amp;quot;%02x \n&amp;quot;,m_buffer_rx[4]);
               cs_high();
               break;
            case 2:
                
                instruction[0] = 0x90 ;//Read Manufacturer and Device ID
                instruction[1]= 0x00;
                instruction[2] = 0x00;
                instruction[3]= 0x00;

                spi_xfer_done = false;
                memset(m_buffer_rx,0x00,sizeof(m_buffer_rx));
                cs_low();
                nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)instruction,sizeof(instruction),m_buffer_rx,8); 
               if(err_code == NRF_SUCCESS)
               {
                    printf(&amp;quot;RDID_2 Transfer Successful\n&amp;quot;);
               }
               while(spi_xfer_done == false)
               {}

                printf(&amp;quot;Flash_ID_2: %d\n&amp;quot;,err_code);
                cs_high();
//                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]);
                 printf(&amp;quot; Manufacturer_ID: %02x,Device_ID:%02x\n&amp;quot;,m_buffer_rx[4],m_buffer_rx[5]);
//                printf(&amp;quot;%d,%d,%d,%d,%d,%d\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] = 0x9f;//FLASH_CMD_RDID
                 spi_xfer_done = false;

                
                cs_low();
//                nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)m_buffer_tx,1,m_buffer_rx,4); 

                err_code = nrf_drv_spi_transfer(&amp;amp;spi,m_buffer_tx,1,m_buffer_rx,5);
                nrf_delay_ms(2);
                if(err_code == NRF_SUCCESS)
                {
                    printf(&amp;quot;RDID_3 Transfer Successful\n&amp;quot;);
                }
                while(spi_xfer_done == false){}
                 printf(&amp;quot;Flash_ID_3: %d\n&amp;quot;,err_code);
             
                printf(&amp;quot;Manufacturer_ID: %02x Memory_Type : %02x, Capacity:%02x\n&amp;quot;,m_buffer_rx[1],m_buffer_rx[2],m_buffer_rx[3]);
                cs_high();
                break;
                
                default:
                    printf(&amp;quot;Out of range&amp;quot;);
                break;

  }

   return err_code;
}





void enable_software_request(void)
{
	cs_low();
	uint8_t rsten = 0x66;
	m_buffer_tx[0] = rsten;
	
	nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)m_buffer_tx,1,m_buffer_rx,1);
	
	cs_high();
	printf(&amp;quot;Flash Enable Software request(RTSEN) Successful\n&amp;quot;);
}



void reset_software()
{
	cs_low();
	uint8_t rst = 0x99;
	m_buffer_tx[0] = rst;
	
	nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)m_buffer_tx,1,m_buffer_rx,1);
	cs_high();
	printf(&amp;quot;Flash Software reset successful\n&amp;quot;);
}

void disable_write()
{
        ret_code_t err_code;
        spi_xfer_done = false;
	
        cs_low();
	uint8_t wrdi = 0x04;
	m_buffer_tx[0] = wrdi;
	
	err_code = nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)m_buffer_tx,1,m_buffer_rx,1);

	
        cs_high();
	
	printf(&amp;quot;Flash disable write opearation successful\n&amp;quot;);
}

uint8_t read_status_register()
{
     ret_code_t err_code;
     spi_xfer_done = false;
     uint8_t data;
     static uint8_t spi_tx_cmd[2];
     static uint8_t spi_rx_cmd[2];
     uint8_t RDSR =0x05;
    
     cs_low();

     spi_tx_cmd[0] = RDSR;
     spi_tx_cmd[1] = 0x00;

     err_code = nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)spi_tx_cmd,2,spi_rx_cmd,2);
      printf(&amp;quot;Status_Reg_Err_code : %d\n&amp;quot;,err_code);

      printf(&amp;quot;Rdsr-stat: %02X\n&amp;quot;,spi_rx_cmd[0]);
      printf(&amp;quot;Rdsd stat %02X\n&amp;quot;,spi_rx_cmd[1]);
     if(err_code == NRF_SUCCESS)
     {
        printf(&amp;quot;RDSR Transfer Successful\n&amp;quot;);
     }
     while(spi_xfer_done == false)   {}

    cs_high();


    return  data;
}


void write_enable()
{
    ret_code_t err_code;
     spi_xfer_done = false;
    
    uint8_t status_register;
    uint8_t spi_tx_cmd[1];

    cs_low();
    uint8_t WREN = 0x06;
    spi_tx_cmd[0] = WREN;

    err_code = nrf_drv_spi_transfer(&amp;amp;spi,spi_tx_cmd,sizeof(spi_tx_cmd),NULL,0);
    printf(&amp;quot;Write_enable_err_code : %d\n&amp;quot;,err_code);

    if(err_code == NRF_SUCCESS)
    {
       printf(&amp;quot;WREN Transfer Successful\n&amp;quot;);
    }
    while(spi_xfer_done == false)   {}



//    cs_high();

//    printf(&amp;quot;Flash Write Enable Latch operation successful\n&amp;quot;);
}



void write_status_register(uint8_t newStatus)
{
  ret_code_t err_code;
  spi_xfer_done = false;
  uint8_t WRSR = 0x01;
  static uint8_t spi_tx_cmd[2];
  static uint8_t spi_rx_cmd[2];
  cs_low();
  spi_tx_cmd[0] = WRSR;
  spi_tx_cmd[1] = newStatus;

  nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)spi_tx_cmd,2,spi_rx_cmd,1);

  if(err_code = NRF_SUCCESS)
   {
      printf(&amp;quot;RDID Transfer Successful\n&amp;quot;);
   }
   while(spi_xfer_done == false)   {}

  cs_high();

}

uint8_t read_function_register()
{
     ret_code_t err_code;
     spi_xfer_done = false;

     uint8_t data ;
     uint8_t RDFR = 0x48;
     static uint8_t spi_tx_cmd[2];
     static uint8_t spi_rx_cmd[2];

   

     cs_low();
     spi_tx_cmd[0] = RDFR;
     spi_tx_cmd[1] = 0x00;

     err_code = nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)spi_tx_cmd,sizeof(spi_tx_cmd),spi_rx_cmd,sizeof(spi_rx_cmd));

     if(err_code = NRF_SUCCESS)
     {
        printf(&amp;quot;RDFR Transfer Successful\n&amp;quot;);
     }
     while(spi_xfer_done == false)   {}

     cs_high();
//     printf(&amp;quot;%02x\n&amp;quot;,spi_rx_cmd[1]);
//     printf(&amp;quot;%02x\n&amp;quot;,data);
//     printf(&amp;quot;%02d\n&amp;quot;,data);

       return  data;
}

void write_function_register( uint8_t newValue)
{
    ret_code_t err_code;
    spi_xfer_done = false;

    uint8_t WRFR = 0x42;
    static uint8_t spi_tx_cmd[2];
    static uint8_t spi_rx_cmd[2];
    cs_low();
    spi_tx_cmd[0] = WRFR;
    spi_tx_cmd[1] = newValue;

   err_code = nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)spi_tx_cmd,2,spi_rx_cmd,1);
   printf(&amp;quot;WRFR Err_code: %d\n&amp;quot;,err_code);

    if(err_code == NRF_SUCCESS)
    {
       printf(&amp;quot;WRFR Transfer Successful\n&amp;quot;);
    }
    while(spi_xfer_done == false)   {}
    
    cs_high();

}


void program_page(uint32_t address, uint8_t *data_ptr, uint32_t data_length)
{
     int i=0;
     ret_code_t err_code;

      uint8_t CMD_PROGRAM = 0x02;
      uint8_t spi_tx_cmd[] = {CMD_PROGRAM, (address &amp;gt;&amp;gt; 16) &amp;amp; 0xFF, (address &amp;gt;&amp;gt; 8) &amp;amp; 0xFF, (address &amp;gt;&amp;gt; 0) &amp;amp; 0xFF};

      uint8_t spi_rx_cmd[8];
      write_enable();


//      read_status_register();

      cs_low();
      spi_xfer_done = false;
      err_code =  nrf_drv_spi_transfer(&amp;amp;spi, (uint8_t const *)spi_tx_cmd, sizeof(spi_tx_cmd),spi_rx_cmd,1);

       if(err_code == NRF_SUCCESS)
       {
         printf(&amp;quot;RDID Transfer Successful\n&amp;quot;);
       }
     while(spi_xfer_done == false)   {}
        printf(&amp;quot;Program_page_Err_2: %d\n&amp;quot;,err_code);

      while(data_length &amp;gt; 255)
      {  
          spi_xfer_done = false;
          err_code = nrf_drv_spi_transfer(&amp;amp;spi,data_ptr,255,0,0);

          if(err_code == NRF_SUCCESS)
          {
             printf(&amp;quot;RDID Transfer Successful\n&amp;quot;);
          }
          while(spi_xfer_done == false)   {}
             printf(&amp;quot;Program_page_Err_3: %d\n&amp;quot;,err_code);
          data_ptr = data_ptr + 255;
          data_length = data_length - 255;
      }
      spi_xfer_done = false;
     err_code = nrf_drv_spi_transfer(&amp;amp;spi, data_ptr, data_length,m_buffer_rx,0);
      if(err_code == NRF_SUCCESS)
      {
         printf(&amp;quot;RDID Transfer Successful\n&amp;quot;);
      }
      while(spi_xfer_done == false)   {}
         printf(&amp;quot;Program_page_Err_4: %d\n&amp;quot;,err_code);

      cs_high();
}


void normal_read(uint32_t address, uint8_t * data_ptr, uint32_t data_length)
{
     ret_code_t err_code;
    
     
     uint8_t CMD_READ = 0x03;

     uint8_t spi_tx_cmd[] = {CMD_READ, (address &amp;gt;&amp;gt; 16) &amp;amp; 0xFF, (address &amp;gt;&amp;gt; 8) &amp;amp; 0xFF, (address &amp;gt;&amp;gt; 0) &amp;amp; 0xFF};
     static uint8_t spi_rx_cmd[256];

     spi_xfer_done = false;

     cs_low();
 
//   data = nrf_drv_spi_transfer(&amp;amp;spi, spi_tx_cmd, sizeof(spi_tx_cmd), spi_rx_cmd,sizeof(spi_rx_cmd));
     err_code = nrf_drv_spi_transfer(&amp;amp;spi, spi_tx_cmd, sizeof(spi_tx_cmd), spi_rx_cmd,4);
      if(err_code == NRF_SUCCESS)
      {
         printf(&amp;quot;RDID Transfer Successful\n&amp;quot;);
      }
      while(spi_xfer_done == false)   {}
     
      while(data_length &amp;gt; 255)
      {
         spi_xfer_done = false;
        err_code = nrf_drv_spi_transfer(&amp;amp;spi, 0, 0, data_ptr, 255);
        if(err_code == NRF_SUCCESS)
        {
           printf(&amp;quot;RDID Transfer Successful\n&amp;quot;);
        }
        while(spi_xfer_done == false)   {}
        data_ptr += 255;
        data_length -= 255;
      }
       spi_xfer_done = false;
       err_code = nrf_drv_spi_transfer(&amp;amp;spi, 0, 0, data_ptr, data_length);
       if(err_code == NRF_SUCCESS)
        {
           printf(&amp;quot;RDID Transfer Successful\n&amp;quot;);
        }
        while(spi_xfer_done == false)   {}


      cs_high();


}



void sector_erase(uint32_t address)
{
    uint8_t CMD_SECTOR_ERASE = 0x20;
    uint8_t spi_tx_cmd[] = {CMD_SECTOR_ERASE, (address &amp;gt;&amp;gt; 16) &amp;amp; 0xFF, (address &amp;gt;&amp;gt; 8) &amp;amp; 0xFF, (address &amp;gt;&amp;gt; 0) &amp;amp; 0xFF};

   

    cs_low();
    write_enable();
       uint8_t WREN = 0x06;
       uint8_t spi_tx_cmd_1[1];
       spi_tx_cmd_1[0] = WREN;
        
       nrf_drv_spi_transfer(&amp;amp;spi,spi_tx_cmd_1,sizeof(spi_tx_cmd_1),0,0); // Enabling Write
   
    nrf_drv_spi_transfer(&amp;amp;spi, spi_tx_cmd, sizeof(spi_tx_cmd), 0, 0);
   cs_high();
}

void block_erase(uint32_t address)
{
    uint8_t CMD_BLOCK_ERASE = 0xd8;
    uint8_t spi_tx_cmd[] = {CMD_BLOCK_ERASE, (address &amp;gt;&amp;gt; 16) &amp;amp; 0xFF, (address &amp;gt;&amp;gt; 8) &amp;amp; 0xFF, (address &amp;gt;&amp;gt; 0) &amp;amp; 0xFF};
    write_enable();
    cs_low();

    nrf_drv_spi_transfer(&amp;amp;spi, spi_tx_cmd, sizeof(spi_tx_cmd), 0, 0);
   cs_high();
}


void chip_erase(void)
{
    uint8_t CMD_CHIP_ERASE = 0x60;
   uint8_t spi_tx_cmd[] = {CMD_CHIP_ERASE};

    write_enable();
    cs_low();
      nrf_drv_spi_transfer(&amp;amp;spi, spi_tx_cmd, sizeof(spi_tx_cmd), 0, 0);
    cs_high();
}



/**
 * @brief SPI user event handler.
 * @param event
 */
void spi_event_handler(nrf_drv_spi_evt_t const * p_event,
                       void *                    p_context)
{
    spi_xfer_done = true;
    NRF_LOG_INFO(&amp;quot;Transfer completed.&amp;quot;);
    if (m_rx_buf[0] != 0)
    {
        NRF_LOG_INFO(&amp;quot; Received:&amp;quot;);
        NRF_LOG_HEXDUMP_INFO(m_rx_buf, strlen((const char *)m_rx_buf));
    }
}

void flash_spi_init()
{   ret_code_t err_code;
    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.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_delay_ms(100);
}

void flash_access_switch()
{
  
    uint8_t man_id, dev_id, status_register, function_register;
    uint8_t data_buf[READ_WRITE_LENGTH] ;

    char str_buff[50] =&amp;quot;Hello&amp;quot;;
    char str_read_buff[50] ={0};

    uint8_t data_read_buffer[READ_WRITE_LENGTH];
    uint32_t address;
    uint8_t choice;
    address = 0x1000;

     uint8_t var =10;

     while(1)
     {
     
         printf(&amp;quot;Enter your choice\n&amp;quot;);
         printf(&amp;quot;1.Flash_ID_test\n2.Read status Register\n3.Read Function register\n4.Normal read\n5. Enable write\n6.Sector erase\n&amp;quot;);
         printf(&amp;quot;7.Program Page\n8.Block Erase\r\n &amp;quot;);

         scanf(&amp;quot;%d&amp;quot;,&amp;amp;choice);
	
	
          switch(choice)
          {
              case 1:
                  flash_ID_test(3);

              case 2:
                   status_register = read_status_register();

                   printf(&amp;quot;Status: %i\r\n&amp;quot;, (int)status_register);
                  break;

              case 3:
                  function_register = read_function_register();
                  printf(&amp;quot;Function: %i\r\n&amp;quot;, (int)function_register);
                  break;

              case 4:
           
                  normal_read(address, data_read_buffer, 50);
                  printf(&amp;quot;Reading address %.8x: &amp;quot;, address);
                  for(int i = 0; i &amp;lt; 50; i++)
                  {
                          printf(&amp;quot;%d\r\n&amp;quot; ,(int)data_read_buffer[i]);
                  }
                  printf(&amp;quot;\r\n&amp;quot;);
                  break;

              case 5:
                  printf(&amp;quot;Running write enable\r\n&amp;quot;);
                  write_enable();
                  break;
        
              case 6:
                  printf(&amp;quot;Running sector erase at address %8x\r\n&amp;quot;,address);
                  sector_erase(address);
                  break;

              case 7:
                  for(int i =0; i &amp;lt; 50; i++) 
                  {
         
                      data_buf[i] = var;
                      var++;
                  }
   
                  program_page(address, data_buf,sizeof(data_buf));
 
       
                  printf(&amp;quot;Programming data at address %.8X\r\n&amp;quot;, address);
                  break;
	
              case 8:
                  printf(&amp;quot;Erasing block at addres %.8X\r\n&amp;quot;,address);
                  block_erase(address);
                  break;

          } //switch

     }//while

 } // function 




int main(void)
{
      //spi_xfer_done = false;

    bsp_board_init(BSP_INIT_LEDS);

    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();


    error_info_t err_code;
    flash_spi_init(); 
    flash_ID_test(3);
 

    flash_access_switch();
   
      
    while (1)
    {
        // Reset rx buffer and transfer done flag
        memset(m_rx_buf, 0, m_length);
        spi_xfer_done = false;

        APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;spi, m_tx_buf, m_length, m_rx_buf, m_length));

        while (!spi_xfer_done)
        {
            __WFE();
        }

        NRF_LOG_FLUSH();

        bsp_board_led_invert(BSP_BOARD_LED_0);
        nrf_delay_ms(200);
    }
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem Interfacing SPI external Flash and writing to the Flash Registers</title><link>https://devzone.nordicsemi.com/thread/267551?ContentTypeID=1</link><pubDate>Wed, 02 Sep 2020 08:26:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:db07acda-1c51-48b3-b32d-425caef4d652</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Hi Mushtakh,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please elaborate more on what is failing. Could you provide any&amp;nbsp;errors, post log output, the logic trance of the SPI bus,etc.? If you are able to read the device ID and Manufacturer ID, there is nothing wrong with the communication. Most likely you did not read the datasheet of the device properly and missed some essential step, etc.&lt;/p&gt;
&lt;p&gt;-Amanda H.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem Interfacing SPI external Flash and writing to the Flash Registers</title><link>https://devzone.nordicsemi.com/thread/267397?ContentTypeID=1</link><pubDate>Tue, 01 Sep 2020 08:52:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:984082f2-d5e2-4df2-a495-18d10b9ea6a6</guid><dc:creator>Mushtakh Shaikh</dc:creator><description>&lt;p&gt;Thanks Amanda, I have already seen that posts. But I am unable to enable write and hence unable to write the data as well. This is my code. Can u please help and let me know what is missing term I am unable to get.&amp;nbsp; &amp;nbsp; I am using nRF SDK v16.0 I am able to set up SPI and also I can read the device ID and Manufacturer ID.&lt;pre class="ui-code" data-mode="text"&gt;
void write_enable()
{
    ret_code_t err_code;
    uint8_t status_register;
    spi_xfer_done = false;
    static uint8_t spi_tx_cmd[1];
    cs_low();
    uint8_t WREN = 0x06;
    spi_tx_cmd[0] = WREN;


//  nrf_drv_spi_transfer(&amp;amp;spi,(uint8_t const *)spi_tx_cmd,sizeof(spi_tx_cmd),0,0);

    err_code = nrf_drv_spi_transfer(&amp;amp;spi,spi_tx_cmd,sizeof(spi_tx_cmd),m_buffer_rx,1);
       printf(&amp;quot;Write_enable_err_code : %d\n&amp;quot;,err_code);

    if(err_code == NRF_SUCCESS)
    {
       printf(&amp;quot;WREN Transfer Successful\n&amp;quot;);
    }
    while(spi_xfer_done == false)   {}

    status_register = read_status_register();
    printf(&amp;quot;Status after WREN: %d\r\n&amp;quot;, status_register);

    cs_high();

    printf(&amp;quot;Flash Write Enable Latch operation successful\n&amp;quot;);
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem Interfacing SPI external Flash and writing to the Flash Registers</title><link>https://devzone.nordicsemi.com/thread/267385?ContentTypeID=1</link><pubDate>Tue, 01 Sep 2020 08:25:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:14c91d20-0daa-4a54-9c73-0548018e4c05</guid><dc:creator>Amanda Hsieh</dc:creator><description>&lt;p&gt;Hi Mushtakh,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Unfortunately, I don&amp;#39;t think we have an example for that flash.&amp;nbsp;&lt;span&gt;You would have to set up the SPI interface yourself using the &lt;a title="Software Development Kit" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.0/hardware_driver_spi_master.html?resultof=%22%68%61%72%64%77%61%72%65%22%20%22%68%61%72%64%77%61%72%22%20%22%64%72%69%76%65%72%22%20%22%73%70%69%22%20%22%6d%61%73%74%65%72%22%20"&gt;SPI master&lt;/a&gt; driver ideally and implement the functions you need from the device as described in the datasheet.&amp;nbsp;&lt;/span&gt;&lt;span&gt;This &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/50734/interface-external-flash-to-nrf52832/203202#203202"&gt;post &lt;/a&gt;and &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/37196/spi-miso-data-is-not-reflecting-on-the-receive-buffer"&gt;this &lt;/a&gt;might give some inspiration.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;-Amanda H.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>