This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

INTERFACE EXTERNAL 2MB FLASH WITH SPI

I am working on nrf52832 and sdk11. I want to store my accelerometer and gyroscope data into external memory.Does anyone have code of it? or any one having .c and .h file.

I am using winbond W25Q16JV memory ic.

Any kind of help will be appreciable...

Parents Reply Children
  • how to write in page of memory and how deal with adress

    None of that has anything to do with Nordic or the nRF52832.

    The memory chip neither knows nor cares what microcontroller you use - it just behaves as described in its datasheet.

    So you need to study the memory documentation, and do what it tells you.

    http://www.8052mcu.com/forum/read/160143

  • i read the documentation...

    i am able to read jedec id and able to write and read data, but problem is i can read data where i haven't write anything. means it is writting automatically.

  • means it is writting automatically

    more likely, your addressing is wrong.

  • i am attaching my code, will you suggest what am i doing wrong..

    in main i first write and then after some delay i read.memory.h

    #include "memory.h"
    #include "nrf_gpio.h"
    #include "nrf_delay.h"
    
    #include "nrf_drv_spi.h"
    
    static volatile bool spi_xfer_done;
    #define SPI_INSTANCE  0 
    static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);  /**< SPI instance. */
    void write_register(uint8_t reg)
    {uint8_t reg_p[1]={reg};
      nrf_drv_spi_transfer(&spi,reg_p,1, NULL, 0);
      spi_xfer_done = false;
    }
    void sector_erase()
    { write_enable();
    	uint8_t reg_p[4]={SECTOR_E,0x00,0x00,0x00};
      nrf_drv_spi_transfer(&spi,reg_p,4, NULL, 0);
    	write_disable();
      spi_xfer_done = false;
    }
    void write_enable()
    { 
    	uint8_t reg_p[1]={W_EN};
    	nrf_drv_spi_transfer(&spi,reg_p,1, NULL, 0);
      spi_xfer_done = false;
    }
    void write_disable()
    {
    	uint8_t reg_p[1]={W_DE};
      nrf_drv_spi_transfer(&spi,reg_p,1, NULL, 0);
      spi_xfer_done = false;
    }
    uint8_t read_register(uint8_t reg,uint32_t length)
    {uint8_t p_data[1];
     reg = reg | 0x80;
    uint8_t reg_p[1]={reg};
    nrf_drv_spi_transfer(&spi,reg_p,1, p_data, sizeof(p_data));
    //SEGGER_RTT_printf(0,"rx=%x",p_data[0]);
    }
    
    uint8_t write_memory(uint8_t *ptr)
    {
    	
    uint8_t test_string_[252+3]={0x00,0x00,0x00};
    	
    	
    /*for(uint8_t i=3;i<131;i++)
    {test_string_[i]=i;}*/
    sector_erase();
    write_enable();
    write_register(PAGE_PGM);
    uint8_t *temp;
    for(uint8_t i = 3; i < (252+3); i++ ) 
    {
    	temp = (ptr + (i - 3));
    	test_string_[i] = *temp;
    }
     uint32_t err_code=nrf_drv_spi_transfer(&spi,test_string_, sizeof(test_string_), NULL, 0);
    APP_ERROR_CHECK(err_code);
    SEGGER_RTT_printf(0,"err_code=%d",err_code);
    
    write_disable();
    return 0;
    }
    
    uint8_t read_memory()
    {
    uint8_t p_data[255];
    write_enable();
    
    
    uint8_t test_string_[4]={READ,0x00,0x00,0x00};
    nrf_drv_spi_transfer(&spi,test_string_,4,p_data,sizeof(p_data));
    for(int i=0;i<=255;i++)
    {
    SEGGER_RTT_printf(0,"\n%d,%d",i,p_data[i]);
    nrf_delay_ms(10);
    }
    return 0;
    }
    void read_status_reg()
    {
    	uint8_t p_data[1];
    	uint8_t reg_p[1]={0x80|R_SR1};
    	nrf_drv_spi_transfer(&spi,reg_p,1, p_data, sizeof(p_data));
     //SEGGER_RTT_printf(0,"rx=%x",p_data[1]);
    }
    bool busy()
    {
    	uint8_t p_data[1];
    	uint8_t reg_p[1]={0x80|R_SR1};
    	nrf_drv_spi_transfer(&spi,reg_p,1, p_data, sizeof(p_data));
     SEGGER_RTT_printf(0,"rx=%x",p_data[0]);
    	if(p_data[0]==1)
    	{return 1;}
    	else
    		return 0;
    }
    void chip_erase()
    { write_enable();
    	uint8_t reg_p[1]={CHIP_ERASE};
    	nrf_drv_spi_transfer(&spi,reg_p,1, NULL,0);
    	write_disable();
    	spi_xfer_done = false;
    }
    	

  • Hey did you get solution. please help me if you already got solution

Related