Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. nRF5 action!

nRF5 action!

Scheduled Pinned Locked Moved My Project
1.9k Posts 49 Posters 630.9k Views 44 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • NeverDieN NeverDie

    It's too bad Fanstel's shipping rates outside the US are high. I received the modules I ordered from Fanstel in just a couple of days. I'll try them out after I receive the PCB's from OSH PARK, which should happen in about another 1-2 weeks. The pinout for Fanstel's "micro" version (BC832) is different, and obviously the land pattern is much smaller, so I just now did a separate breakout board for it and sent it to the fab.

    I'm trying to think now as to whether I'll have any future need for nRF24L01's. The very small and cheap nRF51822 seems to supplant it now with its 4dbm higher Tx power, and the nRF52 affords lower current consumption while in Tx or Rx, because of its DCDC option.

    T Offline
    T Offline
    Toyman
    wrote on last edited by
    #1204

    @NeverDie said in nRF5 Bluetooth action!:

    It's too bad Fanstel's shipping rates outside the US are high

    No issue for me as I am a using a mail forwarder(s) and I can highly recommend them to others. Bringing nrf52Dk from Arrow to Russia costed me $10 (inter-US shipping is free at Arrow).
    I am considering switching to Fanstel modules completely, especially to their PA+LNA ones

    Nca78N 1 Reply Last reply
    0
    • NeverDieN NeverDie

      @d00616 Is it still the case that we're limited to a single interrupt? For instance, I'd like to put the nRF52832 to wake-up periodically as a heartbeat where it reports its battery level, and I also want it to wake-up if a particular pin goes HIGH (e.g. if a PIR sensor is triggered). Presently I'm using the RTC to provide the one interrupt, and I use the PPI to create an RTC interrupt if it detects that the PIR sensor pin has gone HIGH. Then the interrupt code must determine the true cause of the interrupt. It would be cleaner if I could separate them into separate interrupts. This is just a simple example to explain what I mean by the question.

      d00616D Offline
      d00616D Offline
      d00616
      Contest Winner
      wrote on last edited by
      #1205

      @NeverDie said in nRF5 Bluetooth action!:

      @d00616 Is it still the case that we're limited to a single interrupt? For instance, I'd like to put the nRF52832 to wake-up periodically as a heartbeat where it reports its battery level, and I also want it to wake-up if a particular pin goes HIGH (e.g. if a PIR sensor is triggered). Presently I'm using the RTC to provide the one interrupt, and I use the PPI to create an RTC interrupt if it detects that the PIR sensor pin has gone HIGH. Then the interrupt code must determine the true cause of the interrupt. It would be cleaner if I could separate them into separate interrupts.

      You can wake up the MCU via:

      • GPIO pin sense; used for sleep()
      • GPIOTE; consumes less engergy but pin must be dedected in software (0.1µA-0.5µA)
      • LPCOMP (0.5µA)
      • QDEC (5µA)

      The interrupts for LPCOMP and QDEC are not allocated by the arduino-port. I think the LPCOMP is a good point to start with.

      NeverDieN 1 Reply Last reply
      1
      • T Toyman

        @NeverDie said in nRF5 Bluetooth action!:

        It's too bad Fanstel's shipping rates outside the US are high

        No issue for me as I am a using a mail forwarder(s) and I can highly recommend them to others. Bringing nrf52Dk from Arrow to Russia costed me $10 (inter-US shipping is free at Arrow).
        I am considering switching to Fanstel modules completely, especially to their PA+LNA ones

        Nca78N Offline
        Nca78N Offline
        Nca78
        Hardware Contributor
        wrote on last edited by
        #1206

        @Toyman said in nRF5 Bluetooth action!:

        Bringing nrf52Dk from Arrow to Russia costed me $10 (inter-US shipping is free at Arrow).

        Do they ask you for shipment fee directly to Russia ?
        I'm in Vietnam and bringing nrf52DK from Arrow was free, like everything I order from them, and over US$20 it's even express shipment (By the way they have a 25% flash sale right now !)

        I'm interested on info on your mail forwarder if it's not only for Russia.

        T 1 Reply Last reply
        0
        • Nca78N Nca78

          @Toyman said in nRF5 Bluetooth action!:

          Bringing nrf52Dk from Arrow to Russia costed me $10 (inter-US shipping is free at Arrow).

          Do they ask you for shipment fee directly to Russia ?
          I'm in Vietnam and bringing nrf52DK from Arrow was free, like everything I order from them, and over US$20 it's even express shipment (By the way they have a 25% flash sale right now !)

          I'm interested on info on your mail forwarder if it's not only for Russia.

          T Offline
          T Offline
          Toyman
          wrote on last edited by
          #1207

          @Nca78 Arrow ships free to Russia, but only to companies, not to direct consumers this is linked to the fact they use couriers (DHL/Fedex) and not vanilla USPS.
          Have a look at www.shipito.com, it's not the one I am currently using, but Shipito works with the whole world. Pricing might be a bit steep, but I haven't looked at it for a long time.

          1 Reply Last reply
          1
          • T Offline
            T Offline
            Toyman
            wrote on last edited by
            #1208

            http://blog.nordicsemi.com/getconnected/power-consumption-explained?utm_campaign=Blog update notifications&utm_source=hs_email&utm_medium=email&utm_content=57717514&_hsenc=p2ANqtz-9HxcPCGqL9z_8UZBj38TZu8vg-vE-JmEgmzOlt-uiiGj32PO4Vm0brgVaCxtEly5tGV5aioj1vJezIbGK_-xZVXV6zxQ&_hsmi=57717514

            1 Reply Last reply
            0
            • O Offline
              O Offline
              Omemanti
              wrote on last edited by Omemanti
              #1209

              Had the nrf52dk shipped from arrow to the Netherlands. Because it was above 22 euro( something like that) DHL had to let it apply tax and some administration cost.

              The board costed 28 euro(inc shipping). The tax office estimate was that is was around 120 euro??? so they charged me a little to much. I filled in some forms to get some of the taxes back.

              When the board arrived I had to pay DHL 43 euro . So getting it though customes cost more than the board itself. 😏

              Nca78N 1 Reply Last reply
              0
              • O Omemanti

                Had the nrf52dk shipped from arrow to the Netherlands. Because it was above 22 euro( something like that) DHL had to let it apply tax and some administration cost.

                The board costed 28 euro(inc shipping). The tax office estimate was that is was around 120 euro??? so they charged me a little to much. I filled in some forms to get some of the taxes back.

                When the board arrived I had to pay DHL 43 euro . So getting it though customes cost more than the board itself. 😏

                Nca78N Offline
                Nca78N Offline
                Nca78
                Hardware Contributor
                wrote on last edited by
                #1210

                @Omemanti said in nRF5 Bluetooth action!:

                When the board arrived I had to pay DHL 43 euro .
                DHL is selling it's shipment service cheaper to shops so the cost seems interesting for buyer. But their trick is to force you to pay some "service fee" when you receive your parcel in addition to custom taxes. This is borderline scam IMHO as this fee is mandatory and has a fixed value for each destination country, so DHL should include it upfront when customer orders.
                No more DHL shipment for me.

                1 Reply Last reply
                0
                • d00616D d00616

                  @NeverDie said in nRF5 Bluetooth action!:

                  @d00616 Is it still the case that we're limited to a single interrupt? For instance, I'd like to put the nRF52832 to wake-up periodically as a heartbeat where it reports its battery level, and I also want it to wake-up if a particular pin goes HIGH (e.g. if a PIR sensor is triggered). Presently I'm using the RTC to provide the one interrupt, and I use the PPI to create an RTC interrupt if it detects that the PIR sensor pin has gone HIGH. Then the interrupt code must determine the true cause of the interrupt. It would be cleaner if I could separate them into separate interrupts.

                  You can wake up the MCU via:

                  • GPIO pin sense; used for sleep()
                  • GPIOTE; consumes less engergy but pin must be dedected in software (0.1µA-0.5µA)
                  • LPCOMP (0.5µA)
                  • QDEC (5µA)

                  The interrupts for LPCOMP and QDEC are not allocated by the arduino-port. I think the LPCOMP is a good point to start with.

                  NeverDieN Offline
                  NeverDieN Offline
                  NeverDie
                  Hero Member
                  wrote on last edited by NeverDie
                  #1211

                  @d00616 said in nRF5 Bluetooth action!:

                  @NeverDie said in nRF5 Bluetooth action!:

                  @d00616 Is it still the case that we're limited to a single interrupt?  For instance, I'd like to put the nRF52832 to wake-up periodically as a heartbeat where it reports its battery level, and I also want it to wake-up if a particular pin goes HIGH (e.g. if a PIR sensor is triggered).  Presently I'm using the RTC to provide the one interrupt, and I use the PPI to create an RTC interrupt if it detects that the PIR sensor pin has gone HIGH.  Then the interrupt code must determine the true cause of the interrupt.  It would be cleaner if I could separate them into separate interrupts. 
                  

                  You can wake up the MCU via:

                  • GPIO pin sense; used for sleep()
                  • GPIOTE; consumes less engergy but pin must be dedected in software (0.1µA-0.5µA)
                  • LPCOMP (0.5µA)
                  • QDEC (5µA)

                  The interrupts for LPCOMP and QDEC are not allocated by the arduino-port. I think the LPCOMP is a good point to start with.

                  I have it now where LPCOMP does detect pin AIN1 (i.e. pin P0.03) going HIGH, but it still doesn't wake-up the MCU, and the interrupt code never runs. I could use the PPI to trigger an RTC interrupt when it detects the NRF_LPCOMP->EVENTS_UP event, which would wake up the MCU, but then I'm back to square one. Is that the best that can be done given the current state of the software?

                  #define MY_CORE_ONLY
                  
                  #include <nrf.h>
                  #include <MySensors.h>
                  
                  uint32_t blinkCounter=0;
                  uint32_t interruptCounter=0;
                  bool button_pressed=false;
                  
                  void setup() {
                    Serial.begin(9600);
                    Serial.println();
                    Serial.println("Starting...");
                  
                    // Enable interrupt
                    NVIC_SetPriority(LPCOMP_IRQn, 15);
                    NVIC_ClearPendingIRQ(LPCOMP_IRQn);
                    NVIC_EnableIRQ(LPCOMP_IRQn);
                  
                    hwPinMode(LED_BUILTIN,OUTPUT_H0H1);
                    //hwPinMode(PIN_BUTTON1,INPUT);
                    NRF_LPCOMP->PSEL=1; // monitor AIN1 (pin P0.03).
                    while (!(NRF_LPCOMP->PSEL==1)) {} //wait until confirmed
                    NRF_LPCOMP->REFSEL=3;  // choose 1/2 VDD as the reference voltage
                    while (!(NRF_LPCOMP->REFSEL==3)) {} //wait until confirmed
                    NRF_LPCOMP->INTENSET=B0100;  //Enable interrupt for UP event
                    while (!(NRF_LPCOMP->INTENSET==B0100)) {} //wait until confirmed
                    NRF_LPCOMP->ENABLE=1;  //Enable LPCOMP
                    while (!(NRF_LPCOMP->ENABLE==1)) {} //wait until confirmed
                    NRF_LPCOMP->TASKS_START=1;  //start the LPCOMP
                    while (!(NRF_LPCOMP->EVENTS_READY)) {}  //wait until ready
                  }
                  
                  
                  void loop() {
                    Serial.print(blinkCounter++);
                    Serial.println("HIGH");
                    digitalWrite(LED_BUILTIN,HIGH);
                    delay(20);
                  
                  /*
                    if (NRF_LPCOMP->EVENTS_UP) {
                      digitalWrite(LED_BUILTIN,HIGH);
                      delay(2000);
                      NRF_LPCOMP->EVENTS_UP=0;  //Clear the semaphore
                    }
                    */
                  
                    if (button_pressed) {
                      digitalWrite(LED_BUILTIN,HIGH);
                      delay(2000);
                      button_pressed=false;  //Clear the semaphore
                      NRF_LPCOMP->EVENTS_UP=0;  //Clear the semaphore
                    }
                    
                    digitalWrite(LED_BUILTIN,LOW);
                    hwSleep(5000);
                  }
                  
                  
                  // * Reset events and read back on nRF52
                  //* http://infocenter.nordicsemi.com/pdf/nRF52_Series_Migration_v1.0.pdf
                   
                  #if __CORTEX_M == 0x04
                  #define NRF5_RESET_EVENT(event)                                                 \
                          event = 0;                                                                   \
                          (void)event
                  #else
                  #define NRF5_RESET_EVENT(event) event = 0
                  #endif
                  
                  
                  // This must be in one line
                  //extern "C" { void GPIO_IRQHandler(void) {interruptCounter++; NRF5_RESET_EVENT(NRF_RTC0->EVENTS_OVRFLW); NRF_RTC0->EVENTS_OVRFLW=0; }}
                  extern "C" { void LPCOMP_IRQHandler(void) {button_pressed=true; interruptCounter++; NRF5_RESET_EVENT(NRF_LPCOMP->EVENTS_UP); NRF_LPCOMP->EVENTS_UP=0; }}
                  
                  NeverDieN 1 Reply Last reply
                  0
                  • NeverDieN NeverDie

                    @d00616 said in nRF5 Bluetooth action!:

                    @NeverDie said in nRF5 Bluetooth action!:

                    @d00616 Is it still the case that we're limited to a single interrupt?  For instance, I'd like to put the nRF52832 to wake-up periodically as a heartbeat where it reports its battery level, and I also want it to wake-up if a particular pin goes HIGH (e.g. if a PIR sensor is triggered).  Presently I'm using the RTC to provide the one interrupt, and I use the PPI to create an RTC interrupt if it detects that the PIR sensor pin has gone HIGH.  Then the interrupt code must determine the true cause of the interrupt.  It would be cleaner if I could separate them into separate interrupts. 
                    

                    You can wake up the MCU via:

                    • GPIO pin sense; used for sleep()
                    • GPIOTE; consumes less engergy but pin must be dedected in software (0.1µA-0.5µA)
                    • LPCOMP (0.5µA)
                    • QDEC (5µA)

                    The interrupts for LPCOMP and QDEC are not allocated by the arduino-port. I think the LPCOMP is a good point to start with.

                    I have it now where LPCOMP does detect pin AIN1 (i.e. pin P0.03) going HIGH, but it still doesn't wake-up the MCU, and the interrupt code never runs. I could use the PPI to trigger an RTC interrupt when it detects the NRF_LPCOMP->EVENTS_UP event, which would wake up the MCU, but then I'm back to square one. Is that the best that can be done given the current state of the software?

                    #define MY_CORE_ONLY
                    
                    #include <nrf.h>
                    #include <MySensors.h>
                    
                    uint32_t blinkCounter=0;
                    uint32_t interruptCounter=0;
                    bool button_pressed=false;
                    
                    void setup() {
                      Serial.begin(9600);
                      Serial.println();
                      Serial.println("Starting...");
                    
                      // Enable interrupt
                      NVIC_SetPriority(LPCOMP_IRQn, 15);
                      NVIC_ClearPendingIRQ(LPCOMP_IRQn);
                      NVIC_EnableIRQ(LPCOMP_IRQn);
                    
                      hwPinMode(LED_BUILTIN,OUTPUT_H0H1);
                      //hwPinMode(PIN_BUTTON1,INPUT);
                      NRF_LPCOMP->PSEL=1; // monitor AIN1 (pin P0.03).
                      while (!(NRF_LPCOMP->PSEL==1)) {} //wait until confirmed
                      NRF_LPCOMP->REFSEL=3;  // choose 1/2 VDD as the reference voltage
                      while (!(NRF_LPCOMP->REFSEL==3)) {} //wait until confirmed
                      NRF_LPCOMP->INTENSET=B0100;  //Enable interrupt for UP event
                      while (!(NRF_LPCOMP->INTENSET==B0100)) {} //wait until confirmed
                      NRF_LPCOMP->ENABLE=1;  //Enable LPCOMP
                      while (!(NRF_LPCOMP->ENABLE==1)) {} //wait until confirmed
                      NRF_LPCOMP->TASKS_START=1;  //start the LPCOMP
                      while (!(NRF_LPCOMP->EVENTS_READY)) {}  //wait until ready
                    }
                    
                    
                    void loop() {
                      Serial.print(blinkCounter++);
                      Serial.println("HIGH");
                      digitalWrite(LED_BUILTIN,HIGH);
                      delay(20);
                    
                    /*
                      if (NRF_LPCOMP->EVENTS_UP) {
                        digitalWrite(LED_BUILTIN,HIGH);
                        delay(2000);
                        NRF_LPCOMP->EVENTS_UP=0;  //Clear the semaphore
                      }
                      */
                    
                      if (button_pressed) {
                        digitalWrite(LED_BUILTIN,HIGH);
                        delay(2000);
                        button_pressed=false;  //Clear the semaphore
                        NRF_LPCOMP->EVENTS_UP=0;  //Clear the semaphore
                      }
                      
                      digitalWrite(LED_BUILTIN,LOW);
                      hwSleep(5000);
                    }
                    
                    
                    // * Reset events and read back on nRF52
                    //* http://infocenter.nordicsemi.com/pdf/nRF52_Series_Migration_v1.0.pdf
                     
                    #if __CORTEX_M == 0x04
                    #define NRF5_RESET_EVENT(event)                                                 \
                            event = 0;                                                                   \
                            (void)event
                    #else
                    #define NRF5_RESET_EVENT(event) event = 0
                    #endif
                    
                    
                    // This must be in one line
                    //extern "C" { void GPIO_IRQHandler(void) {interruptCounter++; NRF5_RESET_EVENT(NRF_RTC0->EVENTS_OVRFLW); NRF_RTC0->EVENTS_OVRFLW=0; }}
                    extern "C" { void LPCOMP_IRQHandler(void) {button_pressed=true; interruptCounter++; NRF5_RESET_EVENT(NRF_LPCOMP->EVENTS_UP); NRF_LPCOMP->EVENTS_UP=0; }}
                    
                    NeverDieN Offline
                    NeverDieN Offline
                    NeverDie
                    Hero Member
                    wrote on last edited by
                    #1212

                    Getting closer... The LPCOMP interrupt code does run, but the main loop doesn't resume until the RTC timer makes it resume because the programmed time interval has expired.

                    I know this is true because if, during sleep, I make AIN1 go HIGH, and then LOW, then when the MCU later wakes up because of the RTC, it so indicates by making the LED go HIGH for 2 seconds. However, even though there's now solid proof that the LPCOMP interrupt hardware does execute, the main loop doesn't immediately resume, as it does when the RTC times out.

                    So.... How to make the main loop immediately resume whenever LPCOMP goes UP?

                    NeverDieN 1 Reply Last reply
                    0
                    • NeverDieN NeverDie

                      Getting closer... The LPCOMP interrupt code does run, but the main loop doesn't resume until the RTC timer makes it resume because the programmed time interval has expired.

                      I know this is true because if, during sleep, I make AIN1 go HIGH, and then LOW, then when the MCU later wakes up because of the RTC, it so indicates by making the LED go HIGH for 2 seconds. However, even though there's now solid proof that the LPCOMP interrupt hardware does execute, the main loop doesn't immediately resume, as it does when the RTC times out.

                      So.... How to make the main loop immediately resume whenever LPCOMP goes UP?

                      NeverDieN Offline
                      NeverDieN Offline
                      NeverDie
                      Hero Member
                      wrote on last edited by NeverDie
                      #1213

                      Well, I have to re-build the timer part of this, and clean up the code, but at least now a PIR sensor trigger will immediately wake-up the MCU. That's progress! Unfortunately, current drawn during sleep is now 456ua, which is much higher than it should be.

                      #define MY_CORE_ONLY
                      
                      #include <nrf.h>
                      #include <MySensors.h>
                      
                      uint32_t rtcInterruptCounter=0;
                      uint32_t buttonPressInterruptCounter=0;
                      bool button_pressed=false;
                      
                      
                      void myHwSleepPrepare(unsigned long ms)
                      {
                        // Idle serial device
                        NRF_UART0->TASKS_STOPRX = 1;
                        NRF_UART0->TASKS_STOPTX = 1;
                        NRF_UART0->TASKS_SUSPEND = 1;
                        //NRF_UART0->ENABLE=0;  //disable UART0
                      
                        //NRF_CLOCK->TASKS_HFCLKSTOP = 1;
                        
                        // Enable low power sleep mode
                        NRF_POWER->TASKS_LOWPWR = 1;
                      
                      }
                      
                      // Sleep in System ON mode
                      inline void doTheSleep()
                      {
                        __WFE();
                        __SEV();
                        __WFE();
                      }
                      
                      void myHwSleepEnd(unsigned long ms)
                      {
                        // Start HFCLK
                        //if (nrf5_pwr_hfclk) {
                        if (false) {
                          NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
                          NRF_CLOCK->TASKS_HFCLKSTART = 1;
                          while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)
                            ;
                          // Enable low latency sleep mode
                          //NRF_POWER->TASKS_CONSTLAT = 1;
                        }
                      }
                       
                      void myHwSleep(unsigned long ms)
                      {
                        myHwSleepPrepare(ms);
                        doTheSleep();
                        //now sleeping
                        myHwSleepEnd(ms);
                      
                      }
                      
                      
                      void setup() {
                        //Serial.begin(9600);
                        //Serial.println();
                        //Serial.println("Starting...");
                      
                        
                          // Enable interrupt
                        NVIC_SetPriority(LPCOMP_IRQn, 15);
                        NVIC_ClearPendingIRQ(LPCOMP_IRQn);
                        NVIC_EnableIRQ(LPCOMP_IRQn);
                        
                        hwPinMode(LED_BUILTIN,OUTPUT_H0H1);
                        //hwPinMode(PIN_BUTTON1,INPUT);
                        NRF_LPCOMP->PSEL=1; // monitor AIN1 (pin P0.03).
                        while (!(NRF_LPCOMP->PSEL==1)) {} //wait until confirmed
                        NRF_LPCOMP->REFSEL=3;  // choose 1/2 VDD as the reference voltage
                        while (!(NRF_LPCOMP->REFSEL==3)) {} //wait until confirmed
                        NRF_LPCOMP->INTENSET=B0100;  //Enable interrupt for UP event
                        while (!(NRF_LPCOMP->INTENSET==B0100)) {} //wait until confirmed
                        NRF_LPCOMP->ENABLE=1;  //Enable LPCOMP
                        while (!(NRF_LPCOMP->ENABLE==1)) {} //wait until confirmed
                        NRF_LPCOMP->TASKS_START=1;  //start the LPCOMP
                        while (!(NRF_LPCOMP->EVENTS_READY)) {}  //wait until ready
                      
                        //NRF_PPI->CH[0].EEP = (uint32_t)&NRF_LPCOMP->EVENTS_UP;  //If PIR sensor is triggered
                        //NRF_PPI->CH[0].TEP = (uint32_t)&NRF_RTC0->TASKS_TRIGOVRFLW;  //make the RTC wake-up the MCU
                      
                        //NRF_PPI->CHENSET=B00000001; //enable Channel 0.
                        
                        NRF_RTC0->INTENSET = B10;  //interrupt MCU if an OVRFLW is detected.
                        while (NRF_RTC0->INTENSET != B10) {}  //wait until confirmed
                      
                      }
                      
                      
                      void loop() {
                        //Serial.print(blinkCounter++);
                        //Serial.println("HIGH");
                        digitalWrite(LED_BUILTIN,HIGH);
                        delay(20);
                      
                      /*
                        if (NRF_LPCOMP->EVENTS_UP) {
                          digitalWrite(LED_BUILTIN,HIGH);
                          delay(2000);
                          NRF_LPCOMP->EVENTS_UP=0;  //Clear the semaphore
                        }
                        */
                      
                        if (button_pressed) {
                          digitalWrite(LED_BUILTIN,HIGH);
                          delay(2000);
                          button_pressed=false;  //Clear the semaphore
                          NRF_LPCOMP->EVENTS_UP=0;  //Clear the semaphore
                        }
                        
                        digitalWrite(LED_BUILTIN,LOW);
                        myHwSleep(5000);
                      }
                      
                      
                      // * Reset events and read back on nRF52
                      //* http://infocenter.nordicsemi.com/pdf/nRF52_Series_Migration_v1.0.pdf
                       
                      #if __CORTEX_M == 0x04
                      #define NRF5_RESET_EVENT(event)                                                 \
                              event = 0;                                                                   \
                              (void)event
                      #else
                      #define NRF5_RESET_EVENT(event) event = 0
                      #endif
                      
                      
                      // This must be in one line
                      extern "C" { void RTC0_IRQHandler(void) {rtcInterruptCounter++; NRF5_RESET_EVENT(NRF_RTC0->EVENTS_OVRFLW); NRF_RTC0->EVENTS_OVRFLW=0; }}
                      extern "C" { void LPCOMP_IRQHandler(void) {button_pressed=true; buttonPressInterruptCounter++; NRF5_RESET_EVENT(NRF_LPCOMP->EVENTS_UP); NRF_LPCOMP->EVENTS_UP=0; }}
                      
                      NeverDieN 1 Reply Last reply
                      0
                      • NeverDieN NeverDie

                        Well, I have to re-build the timer part of this, and clean up the code, but at least now a PIR sensor trigger will immediately wake-up the MCU. That's progress! Unfortunately, current drawn during sleep is now 456ua, which is much higher than it should be.

                        #define MY_CORE_ONLY
                        
                        #include <nrf.h>
                        #include <MySensors.h>
                        
                        uint32_t rtcInterruptCounter=0;
                        uint32_t buttonPressInterruptCounter=0;
                        bool button_pressed=false;
                        
                        
                        void myHwSleepPrepare(unsigned long ms)
                        {
                          // Idle serial device
                          NRF_UART0->TASKS_STOPRX = 1;
                          NRF_UART0->TASKS_STOPTX = 1;
                          NRF_UART0->TASKS_SUSPEND = 1;
                          //NRF_UART0->ENABLE=0;  //disable UART0
                        
                          //NRF_CLOCK->TASKS_HFCLKSTOP = 1;
                          
                          // Enable low power sleep mode
                          NRF_POWER->TASKS_LOWPWR = 1;
                        
                        }
                        
                        // Sleep in System ON mode
                        inline void doTheSleep()
                        {
                          __WFE();
                          __SEV();
                          __WFE();
                        }
                        
                        void myHwSleepEnd(unsigned long ms)
                        {
                          // Start HFCLK
                          //if (nrf5_pwr_hfclk) {
                          if (false) {
                            NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
                            NRF_CLOCK->TASKS_HFCLKSTART = 1;
                            while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)
                              ;
                            // Enable low latency sleep mode
                            //NRF_POWER->TASKS_CONSTLAT = 1;
                          }
                        }
                         
                        void myHwSleep(unsigned long ms)
                        {
                          myHwSleepPrepare(ms);
                          doTheSleep();
                          //now sleeping
                          myHwSleepEnd(ms);
                        
                        }
                        
                        
                        void setup() {
                          //Serial.begin(9600);
                          //Serial.println();
                          //Serial.println("Starting...");
                        
                          
                            // Enable interrupt
                          NVIC_SetPriority(LPCOMP_IRQn, 15);
                          NVIC_ClearPendingIRQ(LPCOMP_IRQn);
                          NVIC_EnableIRQ(LPCOMP_IRQn);
                          
                          hwPinMode(LED_BUILTIN,OUTPUT_H0H1);
                          //hwPinMode(PIN_BUTTON1,INPUT);
                          NRF_LPCOMP->PSEL=1; // monitor AIN1 (pin P0.03).
                          while (!(NRF_LPCOMP->PSEL==1)) {} //wait until confirmed
                          NRF_LPCOMP->REFSEL=3;  // choose 1/2 VDD as the reference voltage
                          while (!(NRF_LPCOMP->REFSEL==3)) {} //wait until confirmed
                          NRF_LPCOMP->INTENSET=B0100;  //Enable interrupt for UP event
                          while (!(NRF_LPCOMP->INTENSET==B0100)) {} //wait until confirmed
                          NRF_LPCOMP->ENABLE=1;  //Enable LPCOMP
                          while (!(NRF_LPCOMP->ENABLE==1)) {} //wait until confirmed
                          NRF_LPCOMP->TASKS_START=1;  //start the LPCOMP
                          while (!(NRF_LPCOMP->EVENTS_READY)) {}  //wait until ready
                        
                          //NRF_PPI->CH[0].EEP = (uint32_t)&NRF_LPCOMP->EVENTS_UP;  //If PIR sensor is triggered
                          //NRF_PPI->CH[0].TEP = (uint32_t)&NRF_RTC0->TASKS_TRIGOVRFLW;  //make the RTC wake-up the MCU
                        
                          //NRF_PPI->CHENSET=B00000001; //enable Channel 0.
                          
                          NRF_RTC0->INTENSET = B10;  //interrupt MCU if an OVRFLW is detected.
                          while (NRF_RTC0->INTENSET != B10) {}  //wait until confirmed
                        
                        }
                        
                        
                        void loop() {
                          //Serial.print(blinkCounter++);
                          //Serial.println("HIGH");
                          digitalWrite(LED_BUILTIN,HIGH);
                          delay(20);
                        
                        /*
                          if (NRF_LPCOMP->EVENTS_UP) {
                            digitalWrite(LED_BUILTIN,HIGH);
                            delay(2000);
                            NRF_LPCOMP->EVENTS_UP=0;  //Clear the semaphore
                          }
                          */
                        
                          if (button_pressed) {
                            digitalWrite(LED_BUILTIN,HIGH);
                            delay(2000);
                            button_pressed=false;  //Clear the semaphore
                            NRF_LPCOMP->EVENTS_UP=0;  //Clear the semaphore
                          }
                          
                          digitalWrite(LED_BUILTIN,LOW);
                          myHwSleep(5000);
                        }
                        
                        
                        // * Reset events and read back on nRF52
                        //* http://infocenter.nordicsemi.com/pdf/nRF52_Series_Migration_v1.0.pdf
                         
                        #if __CORTEX_M == 0x04
                        #define NRF5_RESET_EVENT(event)                                                 \
                                event = 0;                                                                   \
                                (void)event
                        #else
                        #define NRF5_RESET_EVENT(event) event = 0
                        #endif
                        
                        
                        // This must be in one line
                        extern "C" { void RTC0_IRQHandler(void) {rtcInterruptCounter++; NRF5_RESET_EVENT(NRF_RTC0->EVENTS_OVRFLW); NRF_RTC0->EVENTS_OVRFLW=0; }}
                        extern "C" { void LPCOMP_IRQHandler(void) {button_pressed=true; buttonPressInterruptCounter++; NRF5_RESET_EVENT(NRF_LPCOMP->EVENTS_UP); NRF_LPCOMP->EVENTS_UP=0; }}
                        
                        NeverDieN Offline
                        NeverDieN Offline
                        NeverDie
                        Hero Member
                        wrote on last edited by
                        #1214

                        Aha! Most likely the high current draw is from the high frequency clock, which I need to turn off prior to sleep but haven't done yet.

                        NeverDieN 1 Reply Last reply
                        0
                        • NeverDieN NeverDie

                          Aha! Most likely the high current draw is from the high frequency clock, which I need to turn off prior to sleep but haven't done yet.

                          NeverDieN Offline
                          NeverDieN Offline
                          NeverDie
                          Hero Member
                          wrote on last edited by
                          #1215

                          Anyhow, the basic question remains and boils down to this: Can I have both

                              // Enable interrupt
                            NVIC_SetPriority(LPCOMP_IRQn, 15);
                            NVIC_ClearPendingIRQ(LPCOMP_IRQn);
                            NVIC_EnableIRQ(LPCOMP_IRQn);
                          

                          AND an equivalent incantation for the RTC both active at the same time? Or am I forced into having it be just one or the other?

                          NeverDieN 1 Reply Last reply
                          0
                          • NeverDieN NeverDie

                            @Terrence

                            Around 30 feet, through some walls, but at 2mbps. I realize that's not very far, but even so the measured packet loss (informal testing) is pretty high at that speed. I can see why most people default to 250kbps instead.

                            I don't have the 840 dev kit yet, mostly because I don't see anyother 840 modules on the market right now.

                            ahmedadelhosniA Offline
                            ahmedadelhosniA Offline
                            ahmedadelhosni
                            wrote on last edited by
                            #1216

                            @NeverDie Did you manage to get more than 10m ? maybe by another modules.

                            I thought the nrf52 will have better range !

                            1 Reply Last reply
                            0
                            • U Uhrheber

                              @NeverDie
                              Exactly. There are two pads labelled SWD and SWC, originally meant for pogo pins.
                              I patched them with wires to the pin header.
                              Programming with a Chinese STLink V2 clone works flawlessly.

                              ahmedadelhosniA Offline
                              ahmedadelhosniA Offline
                              ahmedadelhosni
                              wrote on last edited by
                              #1217

                              @Uhrheber I am a bit confused. To program the nRF52 from eByte I need a special programmer but they are expensive. So you mean you used a clone StLink V2 and it worked fine ?

                              I found this.

                              https://www.aliexpress.com/item/Hot-Sale-1PCS-ST-LINK-Stlink-ST-Link-V2-Mini-STM8-STM32-Simulator-Download-Programmer-Programming/32343514985.html?spm=2114.search0104.3.26.LR8eH0&ws_ab_test=searchweb0_0,searchweb201602_1_10152_10065_10151_10344_10068_10345_10342_10174_10343_10340_10341_10541_10084_10083_10307_10060_10155_10154_10056_10055_10539_10538_10537_10312_10536_10059_10313_10314_10534_10533_10317_10318_100031_10103_10073_10102_10142_10107-10318,searchweb201603_30,ppcSwitch_4&btsid=f4d09b48-5aa7-4688-b0e9-a02d8227ed05&algo_expid=2d114a26-895f-4334-aad3-f372504ef95c-3&algo_pvid=2d114a26-895f-4334-aad3-f372504ef95c

                              U 1 Reply Last reply
                              0
                              • ahmedadelhosniA ahmedadelhosni

                                @Uhrheber I am a bit confused. To program the nRF52 from eByte I need a special programmer but they are expensive. So you mean you used a clone StLink V2 and it worked fine ?

                                I found this.

                                https://www.aliexpress.com/item/Hot-Sale-1PCS-ST-LINK-Stlink-ST-Link-V2-Mini-STM8-STM32-Simulator-Download-Programmer-Programming/32343514985.html?spm=2114.search0104.3.26.LR8eH0&ws_ab_test=searchweb0_0,searchweb201602_1_10152_10065_10151_10344_10068_10345_10342_10174_10343_10340_10341_10541_10084_10083_10307_10060_10155_10154_10056_10055_10539_10538_10537_10312_10536_10059_10313_10314_10534_10533_10317_10318_100031_10103_10073_10102_10142_10107-10318,searchweb201603_30,ppcSwitch_4&btsid=f4d09b48-5aa7-4688-b0e9-a02d8227ed05&algo_expid=2d114a26-895f-4334-aad3-f372504ef95c-3&algo_pvid=2d114a26-895f-4334-aad3-f372504ef95c

                                U Offline
                                U Offline
                                Uhrheber
                                wrote on last edited by
                                #1218

                                @ahmedadelhosni
                                Sure, I'm using a similar one.
                                Why wouldn't it work? The nrf52 is an ARM Mx, like the ST chips. The programming interface is the same. You could also use one of the many other ARM programmers, like J-Link, or nearly any JTAG programmer supported by OpenOCD.

                                Just follow this guide: https://www.openhardware.io/view/376/MySensors-NRF5-Platform
                                And: https://github.com/sandeepmistry/arduino-nRF5/#installing

                                ahmedadelhosniA 1 Reply Last reply
                                0
                                • U Uhrheber

                                  @ahmedadelhosni
                                  Sure, I'm using a similar one.
                                  Why wouldn't it work? The nrf52 is an ARM Mx, like the ST chips. The programming interface is the same. You could also use one of the many other ARM programmers, like J-Link, or nearly any JTAG programmer supported by OpenOCD.

                                  Just follow this guide: https://www.openhardware.io/view/376/MySensors-NRF5-Platform
                                  And: https://github.com/sandeepmistry/arduino-nRF5/#installing

                                  ahmedadelhosniA Offline
                                  ahmedadelhosniA Offline
                                  ahmedadelhosni
                                  wrote on last edited by
                                  #1219

                                  @Uhrheber Great. Thanks for the help.

                                  So if I understand well. If I have a TIVA board like TM4C123G Launchpad and it is ARM Mx also, then I can use it to program my nRF ?

                                  This is the datasheet for the board : http://www.ti.com/lit/ug/spmu296/spmu296.pdf

                                  I searched and found those links describing how to use the Launchad but I am not sure whether this will work for nRF also or not.

                                  http://processors.wiki.ti.com/index.php/Stellaris_LM4F120_LaunchPad_Debug_How_To
                                  http://ucsolutions.blogspot.com.eg/2014/08/ti-launchpad-as-external-debugger-with.html

                                  Thanks.

                                  Nca78N 1 Reply Last reply
                                  0
                                  • ahmedadelhosniA ahmedadelhosni

                                    @Uhrheber Great. Thanks for the help.

                                    So if I understand well. If I have a TIVA board like TM4C123G Launchpad and it is ARM Mx also, then I can use it to program my nRF ?

                                    This is the datasheet for the board : http://www.ti.com/lit/ug/spmu296/spmu296.pdf

                                    I searched and found those links describing how to use the Launchad but I am not sure whether this will work for nRF also or not.

                                    http://processors.wiki.ti.com/index.php/Stellaris_LM4F120_LaunchPad_Debug_How_To
                                    http://ucsolutions.blogspot.com.eg/2014/08/ti-launchpad-as-external-debugger-with.html

                                    Thanks.

                                    Nca78N Offline
                                    Nca78N Offline
                                    Nca78
                                    Hardware Contributor
                                    wrote on last edited by
                                    #1220

                                    @ahmedadelhosni said in nRF5 Bluetooth action!:

                                    @Uhrheber Great. Thanks for the help.

                                    So if I understand well. If I have a TIVA board like TM4C123G Launchpad and it is ARM Mx also, then I can use it to program my nRF ?

                                    This is the datasheet for the board : http://www.ti.com/lit/ug/spmu296/spmu296.pdf

                                    I searched and found those links describing how to use the Launchad but I am not sure whether this will work for nRF also or not.

                                    http://processors.wiki.ti.com/index.php/Stellaris_LM4F120_LaunchPad_Debug_How_To
                                    http://ucsolutions.blogspot.com.eg/2014/08/ti-launchpad-as-external-debugger-with.html

                                    Thanks.

                                    I think it's a question of the licence of the programmer that is on your board.
                                    For example the J-Link version on the NRF52 DK is only allowed to program NRF52 and NRF51 chips. It's logic because the NRF52DK is just over 30$ while a J-Link programmer is x00$.
                                    You have pins SWDIO and SWDCLK on pins PC0 and PC1 of your board so just try it and you will know :)

                                    ahmedadelhosniA 1 Reply Last reply
                                    0
                                    • Nca78N Nca78

                                      @ahmedadelhosni said in nRF5 Bluetooth action!:

                                      @Uhrheber Great. Thanks for the help.

                                      So if I understand well. If I have a TIVA board like TM4C123G Launchpad and it is ARM Mx also, then I can use it to program my nRF ?

                                      This is the datasheet for the board : http://www.ti.com/lit/ug/spmu296/spmu296.pdf

                                      I searched and found those links describing how to use the Launchad but I am not sure whether this will work for nRF also or not.

                                      http://processors.wiki.ti.com/index.php/Stellaris_LM4F120_LaunchPad_Debug_How_To
                                      http://ucsolutions.blogspot.com.eg/2014/08/ti-launchpad-as-external-debugger-with.html

                                      Thanks.

                                      I think it's a question of the licence of the programmer that is on your board.
                                      For example the J-Link version on the NRF52 DK is only allowed to program NRF52 and NRF51 chips. It's logic because the NRF52DK is just over 30$ while a J-Link programmer is x00$.
                                      You have pins SWDIO and SWDCLK on pins PC0 and PC1 of your board so just try it and you will know :)

                                      ahmedadelhosniA Offline
                                      ahmedadelhosniA Offline
                                      ahmedadelhosni
                                      wrote on last edited by ahmedadelhosni
                                      #1221

                                      @Nca78 Yeah actually this makes sense. I forgot about the licence thing. Actually I didn't bug the boards and I want to get everything at once without missing anything. I am in a hurry :D

                                      it is strange that this clone can do the work as @Uhrheber mentioned.

                                      http://s.click.aliexpress.com/deep_link.htm?dl_target_url=https%3A%2F%2Fwww.aliexpress.com%2Fitem%2FHot-Sale-1PCS-ST-LINK-Stlink-ST-Link-V2-Mini-STM8-STM32-Simulator-Download-Programmer-Programming%2F32343514985.html%3Fspm%3D2114.search0104.3.26.LR8eH0%26ws_ab_test%3Dsearchweb0_0&aff_short_key=e2Vzr3v

                                      1 Reply Last reply
                                      0
                                      • T Offline
                                        T Offline
                                        Toyman
                                        wrote on last edited by
                                        #1222

                                        Guys, your best bet is to reflash STM32 Bluepill into BlackMagicProbe.
                                        It's awesome!
                                        https://medium.com/@paramaggarwal/converting-an-stm32f103-board-to-a-black-magic-probe-c013cf2cc38c

                                        1 Reply Last reply
                                        0
                                        • NeverDieN NeverDie

                                          Anyhow, the basic question remains and boils down to this: Can I have both

                                              // Enable interrupt
                                            NVIC_SetPriority(LPCOMP_IRQn, 15);
                                            NVIC_ClearPendingIRQ(LPCOMP_IRQn);
                                            NVIC_EnableIRQ(LPCOMP_IRQn);
                                          

                                          AND an equivalent incantation for the RTC both active at the same time? Or am I forced into having it be just one or the other?

                                          NeverDieN Offline
                                          NeverDieN Offline
                                          NeverDie
                                          Hero Member
                                          wrote on last edited by
                                          #1223

                                          @NeverDie said in nRF5 Bluetooth action!:

                                          Anyhow, the basic question remains and boils down to this: Can I have both

                                              // Enable interrupt
                                            NVIC_SetPriority(LPCOMP_IRQn, 15);
                                            NVIC_ClearPendingIRQ(LPCOMP_IRQn);
                                            NVIC_EnableIRQ(LPCOMP_IRQn);
                                          

                                          AND an equivalent incantation for the RTC both active at the same time? Or am I forced into having it be just one or the other?

                                          @d00616 Any thoughts or comments regarding this?

                                          d00616D 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          14

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          Posts


                                          Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular