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

Sending custom BLE characteristic to SD card

I have developed my own custom BLE service. I need to send BLE characteristic to an SD card. I have implemented the FATFS example and it works.

Now I'm trying to merge my custom BLE application with FATFS. However, I've not been able to link a BLE characteristic WRITE event to write to writing to FATFS. 

Here is the code snippet. Here I'm just trying to link a BLE WRITE event to a FATFS WRITE function to write a generic string to the file (not sending characteristic data).

However, on debugging, the program execution never seems to enter the fatfs_write() function. 

What could be happening? Is there something wrong in the program flow logic? Please help. 

Thanks

static void on_cus_evt(ble_cus_t     * p_cus_service,
                       ble_cus_evt_t * p_evt,
                       ble_evt_t const * p_ble_evt_main)
{
    ret_code_t err_code;
    
    switch(p_evt->evt_type)
    {
        
        case BLE_CUS_EVT_WRITE:

            nrf_gpio_pin_toggle(LED_3);
            printf("%s"," write to sd card ");
            flag =1;
            break;
        case 2: ....
        case 3: ....
}

void fatfs_write()
{
      NRF_LOG_INFO("Writing to file " FILE_NAME "...");
                ff_result = f_open(&file, FILE_NAME, FA_READ | FA_WRITE | FA_OPEN_APPEND);
                if (ff_result != FR_OK)
                {
                    NRF_LOG_INFO("Unable to open or create file: " FILE_NAME ".");
                    printf("%s"," unable to open ");
                    return;
                }

                ff_result = f_write(&file, TEST_STRING, sizeof(TEST_STRING) - 1, (UINT *) &bytes_written);
                if (ff_result != FR_OK)
                {
                    NRF_LOG_INFO("Write failed\r\n.");
                    printf("%s"," write failed ");

                }
                else
                {
                    NRF_LOG_INFO("%d bytes written.", bytes_written);
                    printf("%s"," byted written ");
                }

                (void) f_close(&file);
                flag =0;
                return;
}

void main()
{
//initialize BLE, FATFS
for (;;)
    {
        if(flag)
        {
           fatfs_write();
        }
}
}

Parents Reply Children
  • This tutorial is what I had followed.

    STEP 6:

    "Whenever a characteristic is written to, a BLE_GATTS_EVT_WRITE event will be propagated to the application and dispatched to the functions in ble_evt_dispatch(). So this means that we need to add another case to our ble_cus_on_ble_evt switch-case statement, namely BLE_GATTS_EVT_WRITE"

    "we get the Write event we have to get hold of the Write event parameters that are passed with the event and we have to verify that the the handle that is written to matches the Custom Value Characteristic handle"

  • Can you test with an older version of Segger Embedded Studio? I doubt that this should make any difference, but SDK 15.0.0 is tested with SES v3.34. If this does not work, I'm afraid I do not have any other ideas than trying the application with different hardware. It's very hard to debug this when your code is working on my board.

Related