<?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>How to read and write the data to the external flash</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/66520/how-to-read-and-write-the-data-to-the-external-flash</link><description>Hi... 
 How to read and write to the external flash 
 I am using sdk 15.2 version, interfacing the development kit nRF52832 with w25q64 external flash via spi. I have read the datasheet of external flash using the address I am trying to read the data</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 05 Oct 2020 12:09:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/66520/how-to-read-and-write-the-data-to-the-external-flash" /><item><title>RE: How to read and write the data to the external flash</title><link>https://devzone.nordicsemi.com/thread/272962?ContentTypeID=1</link><pubDate>Mon, 05 Oct 2020 12:09:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d80c93fa-ec4c-4c19-806e-6b6daa9ab979</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You&amp;#39;re getting noise only? Not event SCLK is produced or the CS pin set low? Why is rx buffer length 0 in the first transfer at code line 503? Can you check what this function returns.&lt;/p&gt;
&lt;p&gt;I suggest that you start with an easier example such as the SPI example from the SDK. That way, you can get familiar with the API and how the peripheral and protocol works. Debugging your application with the debugger and checking if asserts somewhere is also strongly recommended. I see that some of your function calls doesn&amp;#39;t check what it returns. This is strongly recommended to do. You can check by adding APP_ERROR_CHECK() after the function call. That way you can see if returns or not.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to read and write the data to the external flash</title><link>https://devzone.nordicsemi.com/thread/272489?ContentTypeID=1</link><pubDate>Thu, 01 Oct 2020 11:03:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6444f734-3e50-4dea-a0a8-d0c4714a51f5</guid><dc:creator>ps_anu</dc:creator><description>&lt;p&gt;how to read the data from external flash , which function i need to use ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;nrf_drv_spi_transfer for writing purpose right ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to read and write the data to the external flash</title><link>https://devzone.nordicsemi.com/thread/272476?ContentTypeID=1</link><pubDate>Thu, 01 Oct 2020 10:28:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d33954d3-74b2-4d97-ac41-088554e9c12e</guid><dc:creator>ps_anu</dc:creator><description>&lt;p&gt;yes i have done testing ,i am getting noise only , nothing appeared .&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to read and write the data to the external flash</title><link>https://devzone.nordicsemi.com/thread/272423?ContentTypeID=1</link><pubDate>Thu, 01 Oct 2020 07:18:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d5a91b0b-ad60-43a8-a5c2-7f04f19acccd</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;could you use a logical analyzer or a oscilloscope and share a trace of the SCLK, CS, MISO and MOSI lines?&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to read and write the data to the external flash</title><link>https://devzone.nordicsemi.com/thread/272286?ContentTypeID=1</link><pubDate>Wed, 30 Sep 2020 12:05:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f168b8ef-c722-4b38-ac2d-07c70cbe1718</guid><dc:creator>ps_anu</dc:creator><description>&lt;p&gt;I tried myself , i am getting ff value ,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&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_FLASH  &amp;quot;flash memory &amp;quot; //&amp;quot;Nordic&amp;quot;
static uint8_t       m_tx_buf[] = TEST_FLASH;           /**&amp;lt; TX buffer. */
static uint8_t       m_rx_buf[sizeof(TEST_FLASH) + 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 ;
   
    if (m_buffer_rx[0] != 0)
    {

        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);
}



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;
}


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_SS_PIN);  WP PIN 3 
   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;);
    
   }

  }


    cs_high();


    if( WaitFlashReady( WriteStatusRegCycleTime ) )
        return FlashOperationSuccess;
    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--;
    }
}


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(100);
          }
          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;
}


/*
 * 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;

    /* 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);

  

           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;

}
int main()
{



    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_SS_PIN);
    flash_read_write_test();
    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);
    
    return retval;
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to read and write the data to the external flash</title><link>https://devzone.nordicsemi.com/thread/272242?ContentTypeID=1</link><pubDate>Wed, 30 Sep 2020 10:39:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:63346e71-0223-4b42-b333-5ae3fed2d4b1</guid><dc:creator>ps_anu</dc:creator><description>&lt;p&gt;I am getting the ff value in rx_buffer . i am receiving ff value. Even i set the delay command between the write and read . I am writing the string&amp;nbsp;&lt;/p&gt;
&lt;p&gt;#define TEST_STRING &amp;quot;Z&amp;quot; //&amp;quot;Nordic&amp;quot;&lt;br /&gt;static uint8_t m_tx_buf[] = TEST_STRING;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>