Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Bluefruit NRF52 Count Storage
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Bluefruit NRF52 Count Storage

by jimbatsynergy on Thu Nov 21, 2019 3:20 pm

Hi,
I am trying to figure out how to write a current count to the Bluefruit NRF52832 so that when a power cycle has occurred (like battery disconnected) I don't lose the total cycle count. Is there something like EEPROM where I could write to and have it stored without concern of power cycle reset?

Thanks in advance...Jim

jimbatsynergy
 
Posts: 4
Joined: Mon Nov 18, 2019 10:39 am

Re: Bluefruit NRF52 Count Storage

by jimbatsynergy on Sat Nov 23, 2019 8:11 pm

Update: I added the 10uF capacitor between Gnd and Rst, so now when I disconnect the usb cord and reconnect I don't lose the count as long as I have my lipo plugged in.

Just curious if anyone can point me to a way to store the count in case the lipo stops powering the board. In looking on the Nordic site they talk about writing to Flash memory but I don't know if that is something that has to be setup through the boot loader or if can be handled in programming.

Thanks to all that contribute to the Forum, I am learning a lot, fast from reading about other topics.

jimbatsynergy
 
Posts: 4
Joined: Mon Nov 18, 2019 10:39 am

Re: Bluefruit NRF52 Count Storage

by jevada on Mon Nov 25, 2019 8:09 am

You can use the flash memory for storing data, but that is not advised since (1) the flash is where your code lives too (it thus is dangerous) and (2) the flash can only be flashed some 10.000 times (note: it probably won't fail at the 10.001st time, but it is spec'd at 10k times, see chapter 5 "Absolute maximum ratings", table 7 of the nRF52832 product specification v1.3).

Also, before writing flash, you'll first need to erase it*. This is a rather slow process by the way, it takes up to 338 us to write one word and erasing a block may take up to 89.7 ms. During a write or erase action, the CPU is halted. See chapter 11 "NVMC - Non-volatile memory controller" in the product specification.

You wouldn't need to change the bootloader for this but you must make sure that the flash block you plan to use is not part of the application; you'll either need to allocate the memory (marking it as "noinit") in your application or exclude it in the linker controlfile.

*): when writing to flash, you can only clear bits, not set them. You could work around this by writing new counter values after the previous one, but know that a block can be written to only 181 times before it must be erased. Also, you'll always need to write to 32-bit aligned words.

Anyway, I strongly advise against the use of on-chip memory for storing such a counter. Unfortunately, there is no external eeprom on the feather. Your best option would probably be to use an FRAM memory on a breakout board like https://www.adafruit.com/product/1895.

jevada
 
Posts: 141
Joined: Fri Dec 15, 2017 5:29 am

Re: Bluefruit NRF52 Count Storage

by jimbatsynergy on Wed Nov 27, 2019 6:15 pm

Thanks p2w for the reply and idea of using the FRAM memory!

jimbatsynergy
 
Posts: 4
Joined: Mon Nov 18, 2019 10:39 am

Re: Bluefruit NRF52 Count Storage

by hathach on Wed Mar 04, 2020 7:08 am

if you are using Arduino repo, you could use the Internal Filesystem which implement LFS on internal flash
https://github.com/adafruit/Adafruit_nR ... _ReadWrite

hathach
 
Posts: 1126
Joined: Tue Apr 23, 2013 1:02 am

Please be positive and constructive with your questions and comments.