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

Connection is disconnected automatically

Hi,

I'm trying to implement a pulse counter, and send the data to client via BLE. I have debugged the module of the counter without connection separately, it's working well. But when I'm using USB Dongle for debugging the data, some issue happens: Once the pulse generator is connected, the connection will be disconnected automatically, and same thing happens if I try to reconnect it.

I opened the UART, and got below logs:

[DM]: Request to allocation connection instance
[DM]:[00]: Connection Instance Allocated.
[DM]: Searching for device 0xD7 0xAD 0x10 0x2D 0xFB 0x8A.
[DM]:[DI 0x00]: Device type 0xFF.
[DM]: Device Addr 0x00 0x00 0x00 0x00 0x00 0x00.
[DM]:[DI 0x01]: Device type 0xFF.
[DM]: Device Addr 0x00 0x00 0x00 0x00 0x00 0x00.
[DM]:[DI 0x02]: Device type 0xFF.
[DM]: Device Addr 0x00 0x00 0x00 0x00 0x00 0x00.
[DM]:[DI 0x03]: Device type 0xFF.
[DM]: Device Addr 0x00 0x00 0x00 0x00 0x00 0x00.
[DM]:[DI 0x04]: Device type 0xFF.
[DM]: Device Addr 0x00 0x00 0x00 0x00 0x00 0x00.
[DM]:[DI 0x05]: Device type 0xFF.
[DM]: Device Addr 0x00 0x00 0x00 0x00 0x00 0x00.
[DM]:[DI 0x06]: Device type 0xFF.
[DM]: Device Addr 0x00 0x00 0x00 0x00 0x00 0x00.
[DM]: Notifying application of event 0x11
I: Device connected
[DM]: Disconnect Reason 0x003E
[DM]: Notifying application of event 0x12
[DM]:[CI 0x00]: Freeing connection instance
[DM]:[00]: Freed connection instance.
[DM]: Initializing Connection Instance 0x00000000.
I: Device disconnected

Would you please help me check what might cause this disconnection?

The counter I'm using is implemented with LPCOMP + TIMER which have been described in my previous two questions: 1) and 2).

I was using s110 based on SDK 7.2, and just upgraded to latest SDK 8.1, the issue is still there.

The USB Dongle was initialized based on SDK7.2, and the logs were captured from UART which was implemented with simple_uart library in SDK7.2.

Just as I pre-mentioned, if there is no pulse generator connected, I can use USB Dongle to debug my customized service to control the board (pca10028) to start sampling and stop sampling. But once it's connected to P0.05, the connection is disconnected immediately.

Any feedback will be really appreciated.

Thanks & Regards, Stanley

Parents
  • Hi Hung Bui,

    I tried to use sniffer to capture the communication between phone and device, but looks like only the advertising data can be captured. Once the connection is setup, no data can be captured. Maybe the way I'm using it is not right.

    For debugging this issue, I found if the counter is not enabled, the issue is gone as well. Below is the code how the counter is initialized:

    static void counter_timer_init(void)
    {
            NRF_TIMER2->MODE = TIMER_MODE_MODE_Counter;            // Set the timer in Counter Mode
            NRF_TIMER2->BITMODE = TIMER_BITMODE_BITMODE_16Bit;     //Set counter to 16 bit resolution
    
            NRF_TIMER2->MODE = TIMER_MODE_MODE_Timer;  // Set the timer in Counter Mode
            NRF_TIMER2->PRESCALER = 6;   //Set prescaler. Higher number gives slower timer. Prescaler = 0 gives 16MHz timer
            NRF_TIMER2->BITMODE = TIMER_BITMODE_BITMODE_16Bit;            //Set counter to 16 bit resolution
            NRF_TIMER2->CC[0] = MS_TO_TICK(SAMPLING_COUNTER_TIMER_INTERVAL);     //Set value for TIMER compare register 0
    }
    
    static void LPCOMP_init(void)
    {
            /* Enable interrupt on LPCOMP CROSS event */
            NRF_LPCOMP->INTENSET = LPCOMP_INTENSET_CROSS_Msk;
    
            /* Configure LPCOMP - set input source to AVDD*4/8 */
            NRF_LPCOMP->REFSEL |= (LPCOMP_REFSEL_REFSEL_SupplyFourEighthsPrescaling << LPCOMP_REFSEL_REFSEL_Pos);
            /* Configure LPCOMP - set reference input source to AIN pin 6, i.e. P0.5 */
            NRF_LPCOMP->PSEL |= (COUNTER_PULSE_INPUT << LPCOMP_PSEL_PSEL_Pos);
    
            /* Enable and start the low power comparator */
            NRF_LPCOMP->ENABLE = LPCOMP_ENABLE_ENABLE_Enabled;
    
            NVIC_SetPriority(LPCOMP_IRQn, APP_IRQ_PRIORITY_LOW);
            NVIC_EnableIRQ(LPCOMP_IRQn);
    }
    
    /** @brief Function for initializing Programmable Peripheral Interconnect (PPI) peripheral.
    *   The PPI connects together the LPCOMP event and the TIMER2 COUNT task. 
     */
    static void ppi_init(void)
    {
            // Configure PPI channel 0 to count up the TIMER counter on every LPCOMP event
            // NRF_PPI->CH[COUNTER_PPI_CHANNEL].EEP = (uint32_t)&NRF_LPCOMP->EVENTS_CROSS;
            // NRF_PPI->CH[COUNTER_PPI_CHANNEL].TEP = (uint32_t)&COUNTER_TIMER->TASKS_COUNT;
    
            // Enable PPI channel 0
            NRF_PPI->CHEN = (COUNTER_PPI_ENABLED << COUNTER_PPI_POS);
    }
     
    int counter_init(void)
    {
            LPCOMP_init();
            counter_timer_init();
            ppi_init();
    
            return 0;
    }
    

    Would you please help check what might cause connection disconnected?

    Thanks, Stanley

Reply
  • Hi Hung Bui,

    I tried to use sniffer to capture the communication between phone and device, but looks like only the advertising data can be captured. Once the connection is setup, no data can be captured. Maybe the way I'm using it is not right.

    For debugging this issue, I found if the counter is not enabled, the issue is gone as well. Below is the code how the counter is initialized:

    static void counter_timer_init(void)
    {
            NRF_TIMER2->MODE = TIMER_MODE_MODE_Counter;            // Set the timer in Counter Mode
            NRF_TIMER2->BITMODE = TIMER_BITMODE_BITMODE_16Bit;     //Set counter to 16 bit resolution
    
            NRF_TIMER2->MODE = TIMER_MODE_MODE_Timer;  // Set the timer in Counter Mode
            NRF_TIMER2->PRESCALER = 6;   //Set prescaler. Higher number gives slower timer. Prescaler = 0 gives 16MHz timer
            NRF_TIMER2->BITMODE = TIMER_BITMODE_BITMODE_16Bit;            //Set counter to 16 bit resolution
            NRF_TIMER2->CC[0] = MS_TO_TICK(SAMPLING_COUNTER_TIMER_INTERVAL);     //Set value for TIMER compare register 0
    }
    
    static void LPCOMP_init(void)
    {
            /* Enable interrupt on LPCOMP CROSS event */
            NRF_LPCOMP->INTENSET = LPCOMP_INTENSET_CROSS_Msk;
    
            /* Configure LPCOMP - set input source to AVDD*4/8 */
            NRF_LPCOMP->REFSEL |= (LPCOMP_REFSEL_REFSEL_SupplyFourEighthsPrescaling << LPCOMP_REFSEL_REFSEL_Pos);
            /* Configure LPCOMP - set reference input source to AIN pin 6, i.e. P0.5 */
            NRF_LPCOMP->PSEL |= (COUNTER_PULSE_INPUT << LPCOMP_PSEL_PSEL_Pos);
    
            /* Enable and start the low power comparator */
            NRF_LPCOMP->ENABLE = LPCOMP_ENABLE_ENABLE_Enabled;
    
            NVIC_SetPriority(LPCOMP_IRQn, APP_IRQ_PRIORITY_LOW);
            NVIC_EnableIRQ(LPCOMP_IRQn);
    }
    
    /** @brief Function for initializing Programmable Peripheral Interconnect (PPI) peripheral.
    *   The PPI connects together the LPCOMP event and the TIMER2 COUNT task. 
     */
    static void ppi_init(void)
    {
            // Configure PPI channel 0 to count up the TIMER counter on every LPCOMP event
            // NRF_PPI->CH[COUNTER_PPI_CHANNEL].EEP = (uint32_t)&NRF_LPCOMP->EVENTS_CROSS;
            // NRF_PPI->CH[COUNTER_PPI_CHANNEL].TEP = (uint32_t)&COUNTER_TIMER->TASKS_COUNT;
    
            // Enable PPI channel 0
            NRF_PPI->CHEN = (COUNTER_PPI_ENABLED << COUNTER_PPI_POS);
    }
     
    int counter_init(void)
    {
            LPCOMP_init();
            counter_timer_init();
            ppi_init();
    
            return 0;
    }
    

    Would you please help check what might cause connection disconnected?

    Thanks, Stanley

Children
No Data
Related