Hi everyone,
I am using the following: *nRF51422 *SDK11 *keil uVision 5.17 *s130
I have been working with nRF51 that scans beacons and stores it into persistent storage.
I tweaked an example code, called ble_app_uart_c in ble_central of SDK11, and was able to tweak that code to scan beacon and to read data packets.
The next step is to store that information into persistent storage.
Using pstorage_store, pstorage_load and pstorage_update work fine before BLE scan start. However, pstorage_store and pstorage_update fall into while loop because of pstorage_wait_flag, since BLE scanning started. The weird thing is that pstorage_load work fine whenever I call.
Here is some code snippets.
//Code Includes all necessary initiate functions, handlers, dispatches
void pstorage_init_block() {...}
void pstorage_load_block() {...}
void pstorage_store_block() {...}
void pstorage_update_block(uint32_t source_data)
{
uint8_t source[4] = {(source_data >> 24) & 0xFF,
(source_data >> 16) & 0xFF,
(source_data >> 8) & 0xFF,
(source_data >> 0) & 0xFF};
pstorage_block_identifier_get(&handle, 0, &block_0_handle);
pstorage_wait_handle = block_0_handle.block_id;
pstorage_wait_flag = 1;
pstorage_update(&block_0_handle, source, 4, 4);
while(pstorage_wait_flag) { power_manage(); }
}
static bool is_uuid_present(const ble_uuid_t *p_target_uuid, const ble_gap_evt_adv_report_t *p_adv_report)
{
uint32_t index = 0;
uint8_t *p_data = (uint8_t *)p_adv_report->data;
while (index < p_adv_report->dlen)
{
...
if (p_adv_report->rssi > -50)
{
pstorage_load_block(); // work fine
pstorage_update_block(10); // break here (fall into while loop in the pstorage_update_block function)
pstorage_load_block();
}
...
}
}
...
main()
{
...
...
pstorage_initialization(); // work fine
pstorage_store_block(); // work fine
pstorage_load_block(); // work fine
pstorage_update_block(4294967295); // work fine
pstorage_load_block(); // work fine
err_code = ble_db_discovery_init();
APP_ERROR_CHECK(err_code);
scan_start();
}
I would appreciate to someone who post any idea or share a solution.
Thank you so much.