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

Ble advertising and timer conflict

Hi

I would like to ask you for advice on how to solve my problem with Ble and the timer I have nRf52840 and I am trying to add a timer to examples\ble_peripheral\ble_app_uart timer works properly unless advertising_start(); and then the timer conflict with Ble begins. Does anyone have a solution to this problem ? I am adding part of the timer code and also photos where to see my problem.

#define GPIO_24       NRF_GPIO_PIN_MAP(0,24)

void timer_init(void)
{
    NRF_TIMER2->TASKS_STOP = 1;

    NRF_TIMER2->SHORTS    = (TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos);
    NRF_TIMER2->MODE      = TIMER_MODE_MODE_Timer;
    NRF_TIMER2->BITMODE   = (TIMER_BITMODE_BITMODE_24Bit << TIMER_BITMODE_BITMODE_Pos);
    NRF_TIMER2->PRESCALER = 1;  
    NRF_TIMER2->INTENSET  = (TIMER_INTENSET_COMPARE0_Set << TIMER_INTENSET_COMPARE0_Pos);

    NRF_TIMER2->CC[0]       = 100;

    NRF_TIMER2->TASKS_START = 1;
	NVIC_EnableIRQ(TIMER2_IRQn);
} 

void TIMER2_IRQHandler(void)
{
    if (NRF_TIMER2->EVENTS_COMPARE[0])
    {
       nrf_gpio_pin_toggle(GPIO_24);
	   NRF_TIMER2->EVENTS_COMPARE[0] = 0;
    }
}

not start advertising

start advertising

Parents Reply
  • The frequency will be about 40-80 kHz and must run continuously.

    Here is part of the code


    int32_t AD7982_Read_GPIO(void){
    
      int16_t  AD_Data = 0;
      char BitCounts = 0;
    
      NRF_GPIO->OUTSET = (1UL << ADC_CNV_PIN);
      Delay_ADC(40);
      NRF_GPIO->OUTCLR = (1UL << ADC_CNV_PIN);
      Delay_ADC(10);
    	
    for(BitCounts = 0; BitCounts < 18; BitCounts++)
    {
      AD_Data = AD_Data << 1;
    	NRF_GPIO->OUTSET = (1UL << ADC_CLK_PIN);
      AD_Data |= nrf_gpio_pin_read(ADC_MISO_PIN);
      NRF_GPIO->OUTCLR = (1UL << ADC_CLK_PIN);
    }
      return AD_Data;
    }
    
    void TIMER2_IRQHandler(void){
    
      if (NRF_TIMER2->EVENTS_COMPARE[0]){
    			
      ctr++;
      ticks++;
    	
      int32_t AD_Read = AD7982_Read_GPIO();
      bins[ctr] = AD_Read;
    	
      if (ctr == SAMPLES -1)
      {
        ++numSamples;
        if (numSamples == numSamplesToAverage)
        {
          numSamples = 0;
          if (!sampleReady)     
          {
            memcpy((void*)averages, bins, sizeof(averages));
            sampleReady = true;
          }
          memset(bins, 0, sizeof(bins));
        }
    		ctr = -1;
       } 
        NRF_TIMER2->EVENTS_COMPARE[0] = 0;
      }
    }

Children
Related