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

Writing to flash in the nus example

Hi

I am using the nrf53832 dk.

In the nus example once the data is received from the phone(central) I want to write this data to the flash. I referred to the fstorage example for flash write.

 I made the following changes to the nus_data_handler function.

I am able to run the code, but when i send data from my phone(central) to the dk no data is sent and the device  gets disconnected and starts advertising again.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
static void nus_data_handler(ble_nus_evt_t * p_evt)
{
char wagon[20];//string i added
if (p_evt->type == BLE_NUS_EVT_RX_DATA)
{
uint32_t err_code;
NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART.");
NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
strcpy(wagon,p_evt->params.rx_data.p_data);//string copy
for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
{
do
{
err_code = app_uart_put(p_evt->params.rx_data.p_data[i]);
if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
{
NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
APP_ERROR_CHECK(err_code);
}
} while (err_code == NRF_ERROR_BUSY);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Is my methodology of writing to flash correct?

If not what changes should i make?

Thanks in advance