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

nRF51822 FLASH Erase while in a connection

Hi everybody, i am working with a nrf51822. S110 with sdk6.1 IDE:keil

I want to do FLASH Erase while in a connection. I have read this page devzone.nordicsemi.com/.../ and found out that the fail is related to the connection interval.It have to sufficiently long for flash to erase. I changed the value of MAX_CONN_INTERVAL to 100 (125ms),but it doesn't work at all. Please ,does anyone have any suggestion for this question ?Thank you for any help.

below is my code int main(void) {

static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
static uint8_t index = 0;
uint8_t index_backup = 0;
uint8_t newbyte;

	leds_init();//BLE LED 
    timers_init();
	buttons_init();
    uart_init();
	
	ble_stack_init();

	gap_params_init();
	services_init();
	advertising_init();
    conn_params_init();
    sec_params_init();
	
     //advertising_start();
	
uint32_t *addr;
uint8_t   patwr;
uint8_t   patrd;
uint8_t   patold;
uint32_t  i;
uint32_t  pg_size;
uint32_t  pg_num;

init();//gpio read port and output port

patold  = 0;
pg_size = NRF_FICR->CODEPAGESIZE;
pg_num  = NRF_FICR->CODESIZE - 1;  // Use last page in flash

while (true)
{
    // Start address:
    addr = (uint32_t *)(pg_size * pg_num);
    // Erase page:
    flash_page_erase(addr);
    i = 0;
    while (1)
    {
					nrf_delay_ms(1000); 
				flash_page_erase(addr);					
				// Read pattern from port 0 (pins0-7), and write it to flash:
        patwr =  nrf_gpio_port_read(NRF_GPIO_PORT_SELECT_PORT0);
        
           
            flash_word_write(addr, (uint32_t)patwr);
           
        
        // Read pattern from flash and write it to port 1 (pins8-15):
        patrd = (uint8_t)*addr;
        nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, patrd);
    } 
}

}

Parents
  • It is actually the master(central) that determines the connection interval, so increasing the maximum connection interval on the slave(peripheral) doesn't necessarily help. You can try to increase the minimum connection interval as well, then the master will either use a connection interval between min and max, or reject the slave.

    Edit 07.05.2015: When the SoftDevice is enabled you should use sd_flash_page_erase() and sd_flash_write() functions. Please see Section 7 in the S110 SoftDevice Specification 2.0 for more information. If the flash operation is succesful you will get a NRF_EVT_FLASH_OPERATION_SUCCESS event in sys_evt_dispatch(). I recommend you to have a flag that is set you do a flash operation, and is unset when you get NRF_EVT_FLASH_OPERATION_SUCCESS. Check the flag before you do a flash operation.

    We also have a module for handling flash operations, Pstorage.

  • Thank you for your answer. I tried.Increase both maximum and minimum connection.MIN 100(125ms) MAX 120(150ms) but my nrf51822 also occurs the same circumstances.Have any further solution or something i missed?

Reply Children
No Data
Related