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

flash write

hi,

i able to write and read unsigned integer value from the flash, but when i try to write some string to it ,the device is not responding.

void Reading_the_data_from_flash(void)
{
static char rec_data;

nrf_fstorage_read(&fstorage,0x3e000, &READ_BAUDRATE_FLASH, sizeof(READ_BAUDRATE_FLASH));
NRF_UART_TASK_STARTTX;
nrf_gpio_pin_set(TX_D);
printf("Configured BaudRate Reading From Flash is \"%d\" \n",READ_BAUDRATE_FLASH);
wait_for_flash_ready(&fstorage);
NRF_LOG_INFO("Done.");

nrf_fstorage_read(&fstorage,0x3f000, &READ_MSGINTRVL_FROM_FLASH, sizeof(READ_MSGINTRVL_FROM_FLASH));
NRF_UART_TASK_STARTTX;
nrf_gpio_pin_set(TX_D);
printf("Configured MsgInterval Reading From Flash is \"%d\" \n",READ_MSGINTRVL_FROM_FLASH);
wait_for_flash_ready(&fstorage);
NRF_LOG_INFO("Done.");

nrf_fstorage_read(&fstorage,0x30000, &rec_data, 1);
NRF_UART_TASK_STARTTX;
nrf_gpio_pin_set(TX_D);
printf("Configured Default Device Name Reading From Flash is:\"%c\" \n",rec_data);
wait_for_flash_ready(&fstorage);
NRF_LOG_INFO("Done.");

/* tostring(DEVICE_NAME,READ_DEVICE_NAME_FROM_FLASH[0]);
NRF_UART_TASK_STARTTX;
nrf_gpio_pin_set(TX_D);
printf("%c",DEVICE_NAME[0]);*/

}

void Default_configuration_writing_to_flash(void)
{
ret_code_t rc;
uint32_t Default_baudrate = 9600;
uint32_t Default_msgintrvl = 1;
static char Default_DEVICE_NAME_IN_FLASH[] = "DIGANT";

if(READ_BAUDRATE_FLASH == (-1))
{
nrf_fstorage_erase(&fstorage,0x3e000, pages_to_erase,NULL);

NRF_UART_TASK_STARTTX;
nrf_gpio_pin_set(TX_D);
printf("Writing \"%d\" to flash.\n", Default_baudrate);
rc = nrf_fstorage_write(&fstorage, 0x3e000, &Default_baudrate, sizeof(Default_baudrate), NULL);
APP_ERROR_CHECK(rc);

wait_for_flash_ready(&fstorage);
NRF_UART_TASK_STARTTX;
nrf_gpio_pin_set(TX_D);
printf("Done.\n");
}

if(READ_MSGINTRVL_FROM_FLASH == (-1))
{
nrf_fstorage_erase(&fstorage,0x3f000, pages_to_erase,NULL);

NRF_UART_TASK_STARTTX;
nrf_gpio_pin_set(TX_D);
printf("Writing \"%d\" to flash.\n", Default_msgintrvl);
rc = nrf_fstorage_write(&fstorage, 0x3f000, &Default_msgintrvl, sizeof(Default_msgintrvl), NULL);
APP_ERROR_CHECK(rc);

wait_for_flash_ready(&fstorage);
NRF_UART_TASK_STARTTX;
nrf_gpio_pin_set(TX_D);
printf("Done.\n");
}

 nrf_fstorage_erase(&fstorage,0x30000, pages_to_erase,NULL);

NRF_UART_TASK_STARTTX;
nrf_gpio_pin_set(TX_D);
printf("Writing \"%s\" to flash.\n",Default_DEVICE_NAME_IN_FLASH);
rc = nrf_fstorage_write(&fstorage, 0x30000, Default_DEVICE_NAME_IN_FLASH, sizeof(Default_DEVICE_NAME_IN_FLASH), NULL);
APP_ERROR_CHECK(rc);

wait_for_flash_ready(&fstorage);
NRF_UART_TASK_STARTTX;
nrf_gpio_pin_set(TX_D);
printf("Done.\n");
}

regards,

jagadeesh

Related