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
  • I connected the SD card socket board to the nRF51 DK, then I connected to the board from nRF Connect on the phone, write 0x01 to the characteristics. I see from the RTT output that the file is written. I remove the SD card from socket and put it in SD Card reader of computer to verify that the string is written. 

    Which board are you testing this on? You should try to pause the execution when debugging to see if you are stuck somewhere waiting for the SD card write, etc.

Children
Related