Hi,
I'm currently trying to make a flash logger using the nRF51822_XXAB. My logger is also advertising temperature, battery and other informations in beacon form. I also want to make it connectable so that I can push a 32bit word of epoch type that will then be written in flash between what I want to log to keep track of real time. All worked pretty well until I tried to turn my beacon to be connectable. I succesfully added everything I needed I thought, and I can now connect to it, write my characteristic and it is then written in flash as intended.
My problem is that I call advertising_init in my main loop after making various readings so that my data is updated. I also have a flag that looks if a connection has been made which is set to 1 in case BLE_GAP_EVT_CONNECTED in on_ble_evt function. It is then set to 0 in case BLE_GAP_EVT_DISCONNECTED. My adfvertising_init in my main loop is called only if(!connection_has_been_made). The thing is, sometimes when I connect and then disconnect I go in hard fault. I tried to look for where this is happenning and I don't see anywhere where my error_status is not 0. This error happens way less if I delay my main loop by doing something like : for (;;) { thicking++; if(thicking>1000000) { thicking=0; ..whole main loop.. }}. It must have something to do with where I am in my loop when I connect but I can't find it.
I have also a second problem, I write in flash once every 10 seconds and the process takes about 200 ms for various reasons, if I connect during this time I go in hard fault once I disconnect. For this error, I found that it happens when I call err_code = ble_advertising_start(BLE_ADV_MODE_FAST) in case BLE_GAP_EVT_DISCONNECTED in on_ble_evt function. The error status is 7, which means NRF_ERROR_INVALID_PARAM.
These are my .h and .c for everythng related to BLE:
This is my main:
This is my fstorsge event handler:
EDIT: Forgot to mention I'm using SDK 12.3.0 with S130