Hi ,
Here is my code used to write in to non volatile memory.
#include "nrf.h" #include <stdint.h> #include <stdbool.h> #include "nrf_nvmc.h"
static void flash_page_erase(uint32_t * p_page) { // Turn on flash erase enable and wait until the NVMC is ready. NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Een << NVMC_CONFIG_WEN_Pos); while (NRF_NVMC->READY == NVMC_READY_READY_Busy) { // Do nothing. }
// Erase page.
NRF_NVMC->ERASEPAGE = (uint32_t)p_page;
while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
{
// Do nothing.
}
// Turn off flash erase enable and wait until the NVMC is ready.
NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);
while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
{
// Do nothing
}
}
static void flash_word_write(uint32_t * p_address, uint32_t value) { // If radio is active, wait for it to become inactive. while (m_radio_active) { // Do nothing (just wait for radio to become inactive). (void) sd_app_event_wait(); }
// Turn on flash write enable and wait until the NVMC is ready.
NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos);
while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
{
// Do nothing.
}
*p_address = value;
// Wait flash write to finish
while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
{
// Do nothing.
}
// Turn off flash write enable and wait until the NVMC is ready.
NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);
while (NRF_NVMC->READY == NVMC_READY_READY_Busy)
{
// Do nothing
}
}
int main(void) { uint32_t write=0; uint32_t check = 0;
write = 0x73A34;
flash_page_erase((uint32_t *)0x28400);
flash_word_write((uint32_t *)0x28400, write);
check = *(uint32_t *)0x28400;
}
when i am testing this code in debug mode i can able to erase, read, write.
But the problem we are facing is when i do power reset the data is getting erased (like volatile memory).
i can see in debug mode in memory window that values are getting removed after power-reset
Kindly suggest me, where i am wrong.
Regards Balaji