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

Logging realtime sensor data to flash

I would like to know if it is possible to log realtime sensor data to flash while advertising. I would like to have a device which transmits real time ECG data over ble UART to an android device when in range and once out of range, should start logging the data to the nrf51822 flash. It should resume transferring the data to android device once it is in range again and connected. I would be glad if you could give me a clue as to how to realise this if it is possible.

  • Yes, that is certainly possible. You will have to decide on your approach as there are several ways to crack this nut. If you want to manage the flash yourself there are sd_flash_xxxxxx functions for writing, reading and erasing flash. If you want some abstraction and help managing the flash access you can use the pstorage utility and its API. I also believe there may be a higher level of abstraction through use of a device manager facility but I am not familiar with that.

  • Hi, please could you give a pstorage example code showing this? I need to write at least 20kb sensor data as the value changes, read and periodically send said values on instruction and then clear the flash on system off. Thank you, this would be very helpful as most of the code i've seen show storage of predefined data of small size( 10 blocks of 16 bytes of known value)

  • Sorry, I've never had to implement anything like this so I do not have an example. If you search this forum there are discussions touching on pstorage usage when the data spans more than one page.

  • @Kosidinma There is a pstorage example here that uses 1.5 pages in flash (the pstorage_test_multipage_page_aligned function). I think the general rule to follow is to have blocks alligned with pages, i.e. to have block size e.g. 128 or 1024 bytes. Also note the two notes in the pstorage documentation:

    *- In case blocks span across multiple flash pages update and clear of blocks might not work as expected

    • Loading, storing, updating and clearing of each block is supported. A single operation can not be requested for multiple blocks. However, clear is permitted on requested blocks. This is the only exception.*
  • Hi

    You should not do advertising and perform flash operation at the same time. This is ensured in i.e. the ble_app_hrs example in nRF51 SDK 6.1.0, see the advertising_start in main.c. Also in nRF51 SDK 8.0.0, see ble_advertising_start.

    So if you want to flash application data, then stop advertising, perform the flash operations and then restart advertising again.

Related