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

Help for the nrf code

Hi,

Please find the attachment of code.maincode.rtf

I am using nrf52832 SDK11 s132v2.0.1. I have modified the ble_app_hrs_rscs_relay code and its main code is attached here. The idea behind this project is I will be sending some commands from my custom android app and on the nrf52 side it is in scanning mode, so it will scan for command and filter it on the basis of 16-bit complete service uuid given in on_adv_report() function.

The data I received is being encrypted and accordingly, the switch statement will work.In switch case, there are cases like 'C','A','S','D' where there are some functions.When the code comes under a particular case it first stops scanning and does advertising.After advertisement timeout we have added this code which is in ble_stack_init--->ble_evt_dispatch

static void ble_evt_dispatch(ble_evt_t * p_ble_evt) { uint16_t conn_handle; uint16_t role;

ble_conn_state_on_ble_evt(p_ble_evt);
//pm_on_ble_evt(p_ble_evt);

// The connection handle should really be retrievable for any event type.
conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
role        = ble_conn_state_role(conn_handle);

// Based on the role this device plays in the connection, dispatch to the right applications.
if (role == BLE_GAP_ROLE_PERIPH)
{
    // Manages peripheral LEDs.
    dm_ble_evt_handler(p_ble_evt); 
		 ble_conn_params_on_ble_evt(p_ble_evt);
   on_ble_peripheral_evt(p_ble_evt);
   ble_advertising_on_ble_evt(p_ble_evt);
// OUR_JOB: Step 3.C, Call ble_our_service_on_ble_evt() to do housekeeping of ble connections related to our service and characteristic
ble_our_service_on_ble_evt(&m_our_service, p_ble_evt);  	
}
	else if ( (role == BLE_GAP_ROLE_PERIPH) ||((p_ble_evt->header.evt_id == BLE_GAP_EVT_TIMEOUT) && (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISING))  )
	{

if((DISARM_MODE == true)||(ARM_MODE==true)) //these are flags which were raised in Case 'A' and 'D'. { DISARM_MODE = false;

		}
		else
		{
		scan_start();

} }

else if ((role == BLE_GAP_ROLE_CENTRAL) || (p_ble_evt->header.evt_id == BLE_GAP_EVT_ADV_REPORT)) { /** on_ble_central_evt will update the connection handles, so we want to execute it * after dispatching to the central applications upon disconnection. */ if (p_ble_evt->header.evt_id != BLE_GAP_EVT_DISCONNECTED) { on_ble_central_evt(p_ble_evt); }

    if (conn_handle < CENTRAL_LINK_COUNT + PERIPHERAL_LINK_COUNT)
    {
        ble_db_discovery_on_ble_evt(&m_ble_db_discovery[conn_handle], p_ble_evt);
    }

    // If the peer disconnected, we update the connection handles last.
    if (p_ble_evt->header.evt_id == BLE_GAP_EVT_DISCONNECTED)
    {
        on_ble_central_evt(p_ble_evt);
    }
}

}

CASE 'A' and 'D' have RTC enabled, where the value for which rtc should count is mentioned in fourth bit of 16 bit commands.

We have an appRTCinit function() where it configures the rtc. we have used rtc2 in this code. For Case 'A' and 'D' where after 1 minute time it has to go to apprtc handler compare the event increase the count_timer value to 1, disable the rtc and go to scheduler_event_handler for enabling scanning.

  1. Now we are facing the problem that for once or twice for any command related to rtc_enable, it will work properly and after that if we send any other command it is stuck somewhere.Sometimes the timer will not stop counting and will go on.

And also the compiler is sometimes confused between the calls.

  1. How to get this timer and RTC run properly? since in my app_timer.c I can see it makes the use of rtc1 and I am using rtc2.

Either you test my code or you can give me the simple code where there are two commands issuing the timer value and the timer is running upto the value specified by user. Thanks.

Related