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

BLE not working with timer interrupt (RFduino)

Hi guys,

I am using the RFduino nrf51822 chip. I am using the TIMER2 interrupt and it works fine. But when I try to use the BLE along with the timer interrupt both don't work. I don't get the advertisement for the connection to be made neither does the timer work.

When I stop the timer the Bluetooth works fine and vice versa. I want both the timer and BLE to work together. Here is the code:

#include<RFduinoBLE.h>
  
  
  
  int i = 0;
  uint_fast16_t volatile number_of_ms = 10;
  
  
  void timers(void)                    // directly pass the value you want the cycle to be in mS
  {
    NRF_TIMER2->TASKS_STOP = 1;  // Stop timer
    NRF_TIMER2->MODE = TIMER_MODE_MODE_Timer;  // taken from Nordic dev zone
    NRF_TIMER2->BITMODE = TIMER_BITMODE_BITMODE_16Bit;
    NRF_TIMER2->PRESCALER = 9;  // 32us resolution
    NRF_TIMER2->TASKS_CLEAR = 1; // Clear timer
    // With 32 us ticks, we need to multiply by 31.25 to get milliseconds
    NRF_TIMER2->CC[0] = number_of_ms * 31;
    NRF_TIMER2->CC[0] += number_of_ms / 4;
    NRF_TIMER2->INTENSET = TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos;
    NRF_TIMER2->SHORTS = (TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos);
    attachInterrupt(TIMER2_IRQn, TIMER2_Interrupt);
    NRF_TIMER2->TASKS_START = 1;  // Start TIMER
  
  
  }
  
  void setup() {
    // put your setup code here, to run once:
    RFduinoBLE.advertisementData = "abc";
    RFduinoBLE.deviceName = "abc";
  
    RFduinoBLE.txPowerLevel = +4;
    RFduinoBLE.begin();
    Serial.begin(9600);
    timers();
  }
  
  void loop() {
  
  }
        
  void TIMER2_Interrupt(void)
  {
    if (NRF_TIMER2->EVENTS_COMPARE[0] != 0)
    {
  
      Serial.println(i);
      RFduinoBLE.send(i);
      i++;
      NRF_TIMER2->EVENTS_COMPARE[0] = 0;
  
    }
  }
Parents
  • you should try priority 1 or 3. (I recommend 3 if you do not have serious real time constraints with your handler) 0 and 2 are reserved for softdevice and SVC.

  • as long as you are using priority 1 or 3, then you are not interfering with BLE SD activity. you can use as many peripherals as you wish. Just make sure that if they both use same priority then their handling could be delayed until the current interupt routine is finished. Apart for that there is nothing to think about.

Reply
  • as long as you are using priority 1 or 3, then you are not interfering with BLE SD activity. you can use as many peripherals as you wish. Just make sure that if they both use same priority then their handling could be delayed until the current interupt routine is finished. Apart for that there is nothing to think about.

Children
No Data