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

BLE_UART_APP + restart BLE with NFC

Hi...

Sorry if the question is simple.. but Im stuck....

Im using 52840 + SDK 15 + SD 6.0.0

Im starting with Ble_uart_app..

I added some function of when it connected to cellphone the device sends some information to cellphone.. that is ok..

When the Advertising is stop by  BLE_ADV_EVT_IDLE: the device go to sleep_mode  (NO power off mode)

static void sleep_mode_enter(void)
{
  uint32_t err_code = bsp_indication_set(BSP_INDICATE_IDLE);
  APP_ERROR_CHECK(err_code);
  
  // Prepare wakeup buttons.
  err_code = bsp_btn_ble_sleep_mode_prepare();
  APP_ERROR_CHECK(err_code);
  
  Prepare_NFC_Wake_up();
    
  // Go to system-off mode (this function will not return; wakeup will cause a reset).
  //err_code = sd_power_system_off();
  //APP_ERROR_CHECK(err_code);
}

When I near NFC card to the device, the device is Turn on Again... it is OK..

void NFCT_IRQHandler(void)
{
  if (NRF_NFCT->EVENTS_FIELDDETECTED == 1)
  {
    Prepare_NFC_Turn_off();
    NRF_NFCT->EVENTS_FIELDDETECTED = 0;
    NRF_LOG_INFO(" ***************  Turn On By NFC  ***************\r\n");
    NRF_LOG_FLUSH();
    Wakeup_by_NFC = true;
  }
}

here I am Stuck, in the main loop, I dont know how start the advertising start again..

 for (;;)
  {
    if (Wakeup_by_NFC)
      
    {
    Wakeup_by_NFC = false;
    printf("NFC detectado\r\n");
    NRF_LOG_INFO("Nfc detectado");
    NRF_LOG_FLUSH();
     
    // err_code = sd_ble_gap_adv_start(&m_advertising->adv_handle,BLE_ADV_MODE_FAST);  // it didnt work I have problem with compiling line
    // APP_ERROR_CHECK(err_code);
    // NRF_LOG_INFO("Starting advertising");
    // NRF_LOG_FLUSH();
    
    }    
        __SEV();
        __WFE();
        __WFE(); 
    // idle_state_handle();
  }
}

I get an error of compilation when I using sd_ble_gap_adv_start ... I haven't found any example with this function in the main loop ..

If you have a part of code.. I'll appreciate..

Ricardo

Parents
  • HI Ricardo, 

    My understanding is that you don't really put the chip to sleep mode. You simply enable NFC to wake the CPU up from SystemON mode. 

    If it's the case, you can call advertising_start() to start advertising again, inside     if (Wakeup_by_NFC) {}

  • Hi Hung

    Thanks for your answer, yes I included this call advertising_start() inside the  if (Wakeup_by_NFC) {}

    But the software going to NRF_BREAKPOINT_COND

    I'll try to explain the problem.. 

     

    My software has the following Step...

    1.- when you turn on the device start advertising.

    2.- with the nRF Connect in the cellphone, it connect to the device (nrf52840 DEVelop board)

    3.- I send by NUS an character to the device

    4.- The device receive the character and execute a routine (READ SAADC  )

    5.- Send the SAADC result by NUS to cellphone

    6.- if you disconnect the device.. the device continue advertising for 8 second, after that, and when event of BLE_ADV_EVT_IDLE, it activate NRF and go to systemON mode.

    7.- If you approach the cellphone with his NRF activated, the device wake up...

    8.- In main loop the sentence "if (Wakeup_by_NFC)" has inside a call advertising_start() 

     

    that is the routine.. the problem is ...

    my program WORKS fine without advertising_start()  in the step 8. every step works fine..

    IF i Add the CALL " advertising_start() " in the step 8 the program Stop in the step 4... 

    I don’t know why but If I include the "advertising_start() " in the step 8, the program FAIL in the step 4..

    There are not any reason... It doesn't make sense, because the if (Wakeup_by_NFC) , only run when I near my cellphone..

    well I tried different strategies..

    1.- change the position of the advertising_start(), using an function. but it doesn’t work

    2.- I'm using SDK 15.0.0, y tested it with SDK 15.2.0, It have the same behavior.

     

    Finally I found the problem...

    IAR has a different optimization level.. I have used always the High level...

    I tried use "NONE" optimizing... and finally the code works... in other word. adding the call advertising_start() in the step 8, the program finish sending the data by nus, sleep, wake up by NFC, start again advertising..

    uff.. It was a very strange behavior...

    Do you know why? Is it common? What is the normal optimizing level?

    I tried the following optimization level, and the result in my program..

    None Level      = Works

    Low level           = Works

    Medium level    = works

    High Level + Size + All the ticket in the right hand                = Doesn’t work

    High Level + Balanced + All the ticket in the right hand        = Works

    High Level + speed + All the ticket in the right hand              = Doesn’t works

    High Level + speed + no size restriction + All the ticket in the right hand = Doesn’t works

     

    Thanks

    Ricardo

     

  • Hi Ricardo, 

    Usually optimization level should not affect how the code works, only reducing the size of the code. 

    But when you are in optimized code, you can't really step into the code since there would be no debug information. 

    When testing with code with optimization, you would want to use logging instead of stepping the code. 

Reply Children
No Data
Related