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

combining 2 examples

Hi 

i am using the nrf52832 dk.

I am trying to combine the ble_app_uart code along with the fds code using ses.

what are the changes i have to make in the config file of ble_app_uart.

Please suggest the most ideal method to combine the 2 projects.

The only flash function i require is the write function.

Parents
  • Hi,

    First of all: Do you need a filesystem (like FDS) or do you just want to write directly to flash? If you just need to write directly to flash, you can use fstorage instead.

    If you want FDS in the NUS example you can use this approach:

    1. Start with the NUS example (which use SoftDevice and is generally more complex) and add things from the FDS example as needed.
    2. Add the FDS files and include path to your project. 
    3. Add required includes and code to your main.c file.
    4. Modify the sdk_config.h file to enable FDS and add related configurations. Refer to the FDS example or other examples that use FDS.
    5. Compile the application
      1. If there are errors or warnings, go back to pint 2 and resolve the errors before you build again. This will probably happen several times.
    6. Test application.

    Note that most other BLE examples include the FDS, as it is used by the Peer manager for storing bonding information, so they can be used as a reference.

  • Hi,

    I made the following changes to the nus_data_handler function.

    the 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 devise gets disconnected and starts advertising again.

    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);
            }
            if (p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] == '\r')
            {
                while (app_uart_put('\n') == NRF_ERROR_BUSY);
            }
        }
        //changes i made 
        ret_code_t rc;
        nrf_fstorage_api_t * p_fs_api;
        p_fs_api = &nrf_fstorage_sd;
        rc = nrf_fstorage_init(&fstorage, p_fs_api, NULL);
        APP_ERROR_CHECK(rc);
        rc = nrf_fstorage_write(&fstorage, 0x3e000, wagon, strlen(wagon), NULL);
        APP_ERROR_CHECK(rc);
    
    }

    i used the function from the flash storage example

Reply
  • Hi,

    I made the following changes to the nus_data_handler function.

    the 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 devise gets disconnected and starts advertising again.

    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);
            }
            if (p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] == '\r')
            {
                while (app_uart_put('\n') == NRF_ERROR_BUSY);
            }
        }
        //changes i made 
        ret_code_t rc;
        nrf_fstorage_api_t * p_fs_api;
        p_fs_api = &nrf_fstorage_sd;
        rc = nrf_fstorage_init(&fstorage, p_fs_api, NULL);
        APP_ERROR_CHECK(rc);
        rc = nrf_fstorage_write(&fstorage, 0x3e000, wagon, strlen(wagon), NULL);
        APP_ERROR_CHECK(rc);
    
    }

    i used the function from the flash storage example

Children
Related