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 631.2k 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 Offline
    NeverDieN Offline
    NeverDie
    Hero Member
    wrote on last edited by NeverDie
    #1456

    I don't remember. I've lately been using LoRa modules, plus getting distracted by CNC, so my nRF5 work has been on hold. I'm hoping that d00616 continues to work on the software though so that more than one nRF5 interrupt can be active at a time.

    1 Reply Last reply
    0
    • Nca78N Nca78

      @korttoma have you tried the code @NeverDie put together using the LPCOMP ? With a QFAAH0 (which I believe is the same version than QFABC0, but with 256K flash) he went down to something like 4µA.
      From the document you link, anomaly 70, it will be necessary to add an extra wait of 36us after that line, it's strange that @NeverDie never had any problem with it. Or maybe I misunderstand the document :)

      void activateLpComp() {
      ...
        while (!(NRF_LPCOMP->EVENTS_READY)) {}  //wait until ready
      ...
      }
      

      Test code from @NeverDie using LPCOMP is here:
      https://forum.mysensors.org/topic/6961/nrf5-bluetooth-action/1307

      I will try it on my board (using a module with QFAAH0) tomorrow, if power consumption is as low as expected I'll try on the beacon board.

      [Edit] Just checked quickly my "beacon" board and it's using a QFAAH1 chip (made in 2017), so the test might not be relevant...

      korttomaK Offline
      korttomaK Offline
      korttoma
      Hero Member
      wrote on last edited by
      #1457

      @nca78 thanks for the hint.

      I tried to merge my sketch with the code provided by @NeverDie but I can not seem to get it to detect my button and I don't quite understand where I should attach my button that is on pin 28 to the interrupt thingie.

      Here is my code now:

      //This sketch is applicable to Coincell Multisensor nRF51822, version 10
      
      // Define a static node address, remove if you want auto address assignment
      //#define MY_NODE_ID 26                                                          // Kök
      #define MY_NODE_ID 27                                                          // Test device
                                                        
      
      // Enable and select radio type attached
      
      #define MY_RADIO_NRF5_ESB
      
      #define SN "NRF5 Scene"
      #define SV "1.0"
      
      #define CHILD_ID_SCENE 1
      
      //#define MY_CORE_ONLY
      
      
      #define IS_NRF51  //true iff the target is an nRF51.  If an nRF52, then comment this line out!
      
      // PIN for the buttons
      byte buttonOne = 28;
      
      //Bounce debouncer[NUMBUTTONS];
      int buttonOneoldValue;
      
      
      // Pin definitions
      //#define DIGITAL_INPUT_INT 28   // The digital input you attached your interrupt  (Only 2 and 3 generates interrupt!)
      
      
      //#define I2C_INTERRUPT_PIN PIN_BUTTON1
      //#define LEAK_DETECTION_PIN PIN_BUTTON1
      
      #include <nrf.h>
      #include <MySensors.h>
      
      volatile bool button_pressed=false;
      
      // Sensor messages
      MyMessage msgOn(CHILD_ID_SCENE, V_SCENE_ON);
      
      // Global settings
      uint16_t SceneOne = 0;
      uint16_t SceneTwo = 1;
      
      void blinkityBlink(uint8_t pulses, uint8_t repetitions) {
        for (int x=0;x<repetitions;x++) {
          for (int i=0;i<pulses;i++) {
            digitalWrite(LED_BUILTIN,HIGH);
            wait(20);
            digitalWrite(LED_BUILTIN,LOW);
            wait(100);
          }    
            wait(500);
        }
      }
      
      void disableNfc() {  //only applied to nRF52
      
      #ifndef IS_NRF51
        //Make pins 9 and 10 usable as GPIO pins.
        NRF_NFCT->TASKS_DISABLE=1;  //disable NFC
        NRF_NVMC->CONFIG=1;  // Write enable the UICR
        NRF_UICR->NFCPINS=0; //Make pins 9 and 10 usable as GPIO pins.
        NRF_NVMC->CONFIG=0;  // Put the UICR back into read-only mode.
      #endif
      }
      
      
      void turnOffRadio() {
        NRF_RADIO->TASKS_DISABLE=1;
        while (!(NRF_RADIO->EVENTS_DISABLED)) {}  //until radio is confirmed disabled
      }
      
      void turnOffUarte0() {
      #ifndef IS_NRF51  
        NRF_UARTE0->TASKS_STOPRX = 1;
        NRF_UARTE0->TASKS_STOPTX = 1;
        NRF_UARTE0->TASKS_SUSPEND = 1;
        NRF_UARTE0->ENABLE=0;  //disable UART0
        while (NRF_UARTE0->ENABLE!=0) {};  //wait until UART0 is confirmed disabled.
      #endif
      
      #ifdef IS_NRF51
        NRF_UART0->TASKS_STOPRX = 1;
        NRF_UART0->TASKS_STOPTX = 1;
        NRF_UART0->TASKS_SUSPEND = 1;
        NRF_UART0->ENABLE=0;  //disable UART0
        while (NRF_UART0->ENABLE!=0) {};  //wait until UART0 is confirmed disabled.
      #endif
      }
      
      void turnOffAdc() {
      #ifndef IS_NRF51
        if (NRF_SAADC->ENABLE) { //if enabled, then disable the SAADC
          NRF_SAADC->TASKS_STOP=1;
          while (NRF_SAADC->EVENTS_STOPPED) {} //wait until stopping of SAADC is confirmed
          NRF_SAADC->ENABLE=0;  //disable the SAADC
          while (NRF_SAADC->ENABLE) {} //wait until the disable is confirmed
        }
      #endif
      }
      
      
      void turnOffHighFrequencyClock() {
          NRF_CLOCK->TASKS_HFCLKSTOP = 1;
          while ((NRF_CLOCK->HFCLKSTAT) & 0x0100) {}  //wait as long as HF clock is still running.
      }
      
      
      void mySleepPrepare()
      {
        turnOffHighFrequencyClock();
        turnOffRadio();
        turnOffUarte0();
      }
       
      
      void activateLpComp() {
        //NRF_LPCOMP->PSEL=1; // monitor AIN1 (pin P0.03 on nRF52832 test board).
        //while (!(NRF_LPCOMP->PSEL==1)) {} //wait until confirmed
        NRF_LPCOMP->PSEL=3; // monitor AIN3 (pin P0.02 on nRF51822 for coincell_multisensor_v10)
        while (!(NRF_LPCOMP->PSEL==3)) {} //wait until confirmed
        NRF_LPCOMP->REFSEL=1;  // choose 1/4 VDD as the reference voltage
        while (!(NRF_LPCOMP->REFSEL==1)) {} //wait until confirmed
        NRF_LPCOMP->ANADETECT=1;  //detect UP events.
        while (NRF_LPCOMP->ANADETECT!=1) {} //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
        
        NVIC_SetPriority(LPCOMP_IRQn, 15);
        NVIC_ClearPendingIRQ(LPCOMP_IRQn);
        NVIC_EnableIRQ(LPCOMP_IRQn);
      }
      
      void suspendLpComp() { //suspend getting more interrupts from LPCOMP before the first interrupt can be handled
        if ((NRF_LPCOMP->ENABLE) && (NRF_LPCOMP->EVENTS_READY)) {  //if LPCOMP is enabled
          NRF_LPCOMP->INTENCLR=B0100;  //disable interrupt from LPCOMP
          while (NRF_LPCOMP->INTENCLR==B0100) {} //wait until confirmed
        }
      }
      
      void resumeLpComp() { //suspend getting interrupts from LPCOMP
        NRF_LPCOMP->INTENSET=B0100;  //Enable interrupt for UP event
        while (!(NRF_LPCOMP->INTENSET==B0100)) {} //wait until confirmed
      }
      
      /****************************************************
       *
       * Setup code 
       *
       ****************************************************/
       
      void setup() {
      
        hwInit();
        hwPinMode(LED_BUILTIN,OUTPUT_D0H1);
        disableNfc();
        turnOffAdc();
        activateLpComp();
        blinkityBlink(2,1);  //Signify end of setup with two quick pulses.
        mySleepPrepare();
        button_pressed=false;
      
        //NRF_CLOCK->INTENSET=B11;  //enable interrupts for EVENTS_HFCLKSTARTED and  EVENTS_LFCLKSTARTED
       // NRF_CLOCK->TASKS_HFCLKSTART=1;  //start the high frequency crystal oscillator clock
       // while (!(NRF_CLOCK->EVENTS_HFCLKSTARTED)) {} //wait until high frequency crystal oscillator clock is up to speed and working
                                                      
        //hwPinMode(DIGITAL_INPUT_INT, INPUT_PULLUP);
          
          /// Make input & enable pull-up resistors on switch pins
        hwPinMode(buttonOne, INPUT_PULLUP);
        //buttonOneoldValue = -1;
        
      
        //sendBattLevel();
        
      
      }
      
      void presentation()  {
        sendSketchInfo(SN, SV);
        //present the scene controller to gateway
        wait(10);
        present(CHILD_ID_SCENE, S_SCENE_CONTROLLER);
            
        wait(10);
        sendBattLevel();
        
      }
      
      void sendBattLevel()
      {
          long vcc = hwCPUVoltage();
        
          // Calculate percentage
      
          vcc = vcc - 1800; // subtract 1.9V from vcc, as this is the lowest voltage we will operate at
          
          long percent = vcc / 14.0;
          sendBatteryLevel(percent);    
        
      }
      
      void loop() {
      
        sleep(10000);  //sleep for 5 seconds.
        mySleepPrepare();  //An ounce of prevention: Turn-off HF clock, etc, ASAP to save power, just in case the library's sleep() routine resumed them.
        if (button_pressed) {   //if a leak is detected
          suspendLpComp(); //suspend LPCOMP to prevent multiple interrupts
          //blinkityBlink(10,3);  //blink a lot to show that a leak was detected.
          send(msgOn.set(SceneOne));
              
              wait(20);
      
              send(msgOn.set(SceneTwo));
      
              sendBattLevel();
          button_pressed=false;  //Clear the semaphore
          NRF_LPCOMP->EVENTS_UP=0;  //Clear the semaphore
          resumeLpComp();  //operations of LPCOMP were suspended after detecting the LPCOMP iterrupt
        }
        else {
          blinkityBlink(1,1);  //otherwise, just one short blink to indicate the wakeup was scheduled by the RTC
        }
      }
      
      
      // * 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 LPCOMP_IRQHandler(void) {button_pressed=true; NRF5_RESET_EVENT(NRF_LPCOMP->EVENTS_UP); NRF_LPCOMP->EVENTS_UP=0; MY_HW_RTC->CC[0]=(MY_HW_RTC->COUNTER+2);}}
      

      I thought that I should do it like this:

      void activateLpComp() {
         NRF_LPCOMP->PSEL=28; // monitor AIN3 (pin P0.02 on nRF51822 for coincell_multisensor_v10)
        while (!(NRF_LPCOMP->PSEL==28)) {} //wait until confirmed
      

      But then it does not seem to run the loop anymore because I do not get the 10s blink.

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

        Guys, help me understand: when do I need to enable DC-DC?
        My breakout board consists of Ebyte module and a couple of buttons. Battery is CR2450 directly connected to the module.
        Do I need DC-DC?

        NeverDieN 1 Reply Last reply
        0
        • T Toyman

          Guys, help me understand: when do I need to enable DC-DC?
          My breakout board consists of Ebyte module and a couple of buttons. Battery is CR2450 directly connected to the module.
          Do I need DC-DC?

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

          @toyman With DC-DC, it uses roughly half the current during Tx and Rx. Seems like a no brainer to me, but you don't literally "need" to have it. I'm not aware of any downsides to it.

          T 1 Reply Last reply
          0
          • NeverDieN NeverDie

            @toyman With DC-DC, it uses roughly half the current during Tx and Rx. Seems like a no brainer to me, but you don't literally "need" to have it. I'm not aware of any downsides to it.

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

            @neverdie thx. What is needed hardware-wise? Two inductors between dc and dec4? Like in your breakout board?

            NeverDieN 1 Reply Last reply
            0
            • T Toyman

              @neverdie thx. What is needed hardware-wise? Two inductors between dc and dec4? Like in your breakout board?

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

              @toyman Correct. You can review the schematic for this project: https://www.openhardware.io/view/472/Ebyte-nRF52832-Prototyping-Board

              T 1 Reply Last reply
              1
              • korttomaK Offline
                korttomaK Offline
                korttoma
                Hero Member
                wrote on last edited by korttoma
                #1462

                I guess this is why I cant get LPCOMP to work on the device.

                Eight input options (AIN0 to AIN7)
                

                I would have to use the analog inputs because pin 28 is just a general purpose I/O pin.

                0_1521609771691_nrf51822-beacon-schematic.png

                0_1521609830464_nrf51822-beacon-schematic2.png

                • Tomas
                Nca78N 1 Reply Last reply
                0
                • T Offline
                  T Offline
                  Toyman
                  wrote on last edited by
                  #1463

                  ebyte module is currently on sale at roughly $2.5
                  Total bargain!

                  1 Reply Last reply
                  0
                  • korttomaK korttoma

                    I guess this is why I cant get LPCOMP to work on the device.

                    Eight input options (AIN0 to AIN7)
                    

                    I would have to use the analog inputs because pin 28 is just a general purpose I/O pin.

                    0_1521609771691_nrf51822-beacon-schematic.png

                    0_1521609830464_nrf51822-beacon-schematic2.png

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

                    @korttoma using MySensors NRF5 boards you should be able to assign one AINx pin to physical pin 28.
                    The index you need to put in the code is the AIN index not the pin number.

                    korttomaK 1 Reply Last reply
                    0
                    • Nca78N Nca78

                      @korttoma using MySensors NRF5 boards you should be able to assign one AINx pin to physical pin 28.
                      The index you need to put in the code is the AIN index not the pin number.

                      korttomaK Offline
                      korttomaK Offline
                      korttoma
                      Hero Member
                      wrote on last edited by
                      #1465

                      @nca78 sorry but I cannot figure out how to do this. Should I do it in the MyBoardNRF5.cpp, MyBoardNRF5.h or in the sketch?

                      • Tomas
                      Nca78N 1 Reply Last reply
                      0
                      • korttomaK korttoma

                        @nca78 sorry but I cannot figure out how to do this. Should I do it in the MyBoardNRF5.cpp, MyBoardNRF5.h or in the sketch?

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

                        @korttoma sorry I said stupid things as I'm a beginner too, you can't reassign analog inputs and LPCOMP to different pins on NRF5 chips.

                        korttomaK 1 Reply Last reply
                        1
                        • Nca78N Nca78

                          @korttoma sorry I said stupid things as I'm a beginner too, you can't reassign analog inputs and LPCOMP to different pins on NRF5 chips.

                          korttomaK Offline
                          korttomaK Offline
                          korttoma
                          Hero Member
                          wrote on last edited by
                          #1467

                          @nca78 it is ok, I think I will have to set up a test system with a different device with witch I can measure current consumption, attach serial logging and then try to fiddle with the code. I'm flying in the dark with this bluetooth beacon device since I cannot access any pins.

                          • Tomas
                          1 Reply Last reply
                          0
                          • NeverDieN NeverDie

                            @toyman Correct. You can review the schematic for this project: https://www.openhardware.io/view/472/Ebyte-nRF52832-Prototyping-Board

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

                            @neverdie thx. Why don't you have a capacitor between DEC4 to GND? I can see only 2 inductors, while Nordic power guidelines prescribe an LC filter between DCC and DEC, ie inductors and a capacitor. nrf52dk also has it.

                            NeverDieN 1 Reply Last reply
                            1
                            • T Toyman

                              @neverdie thx. Why don't you have a capacitor between DEC4 to GND? I can see only 2 inductors, while Nordic power guidelines prescribe an LC filter between DCC and DEC, ie inductors and a capacitor. nrf52dk also has it.

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

                              @toyman I guess I made an error then. Thanks for pointing that out. In general, I haven't gotten much feedback on the PCB's that I've posted, so any feedback is always appreciated. :)

                              O YveauxY 2 Replies Last reply
                              1
                              • NeverDieN NeverDie

                                @toyman I guess I made an error then. Thanks for pointing that out. In general, I haven't gotten much feedback on the PCB's that I've posted, so any feedback is always appreciated. :)

                                O Offline
                                O Offline
                                Omemanti
                                wrote on last edited by
                                #1470

                                @neverdie Question is, did the DC/DC still work without the cap?

                                NeverDieN 1 Reply Last reply
                                0
                                • O Omemanti

                                  @neverdie Question is, did the DC/DC still work without the cap?

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

                                  @omemanti said in nRF5 Bluetooth action!:

                                  @neverdie Question is, did the DC/DC still work without the cap?

                                  I believe it did. If you look at: https://www.openhardware.io/view/471/Ebyte-nRF52832-Small-Breakout-Board
                                  which has the inductors soldered on, I believe that is the one that I tested. Enough time has passed though that I can't be 100% sure now. I made a number of different variations, and I didn't post all of them.

                                  O 1 Reply Last reply
                                  1
                                  • NeverDieN NeverDie

                                    @omemanti said in nRF5 Bluetooth action!:

                                    @neverdie Question is, did the DC/DC still work without the cap?

                                    I believe it did. If you look at: https://www.openhardware.io/view/471/Ebyte-nRF52832-Small-Breakout-Board
                                    which has the inductors soldered on, I believe that is the one that I tested. Enough time has passed though that I can't be 100% sure now. I made a number of different variations, and I didn't post all of them.

                                    O Offline
                                    O Offline
                                    Omemanti
                                    wrote on last edited by Omemanti
                                    #1472

                                    @neverdie said in nRF5 Bluetooth action!:

                                    nough time has passed though that I can't be 100% sure now. I made a number of different variations, and I didn't post all of them

                                    I used your schematic for a PCB I ordered yesterday :), did saw the post about the cap until it was too late :(
                                    part of the game!

                                    Edit: according to your post https://forum.mysensors.org/topic/6961/nrf5-bluetooth-action/797 it did work

                                    1 Reply Last reply
                                    0
                                    • Nca78N Nca78

                                      @korttoma have you tried the code @NeverDie put together using the LPCOMP ? With a QFAAH0 (which I believe is the same version than QFABC0, but with 256K flash) he went down to something like 4µA.
                                      From the document you link, anomaly 70, it will be necessary to add an extra wait of 36us after that line, it's strange that @NeverDie never had any problem with it. Or maybe I misunderstand the document :)

                                      void activateLpComp() {
                                      ...
                                        while (!(NRF_LPCOMP->EVENTS_READY)) {}  //wait until ready
                                      ...
                                      }
                                      

                                      Test code from @NeverDie using LPCOMP is here:
                                      https://forum.mysensors.org/topic/6961/nrf5-bluetooth-action/1307

                                      I will try it on my board (using a module with QFAAH0) tomorrow, if power consumption is as low as expected I'll try on the beacon board.

                                      [Edit] Just checked quickly my "beacon" board and it's using a QFAAH1 chip (made in 2017), so the test might not be relevant...

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

                                      @nca78 said in nRF5 Bluetooth action!:

                                      I will try it on my board (using a module with QFAAH0) tomorrow, if power consumption is as low as expected I'll try on the beacon board.

                                      @NeverDie I have tried the sketch nearly unchanged (only changed to lines because I use pin P0.01 so AIN2) and my current consumption is a bit over 30uA, do you have any idea of what I should check ? (I tried with both versions 0.1 and 0.3 of MySensors NRF5 boards).
                                      At the moment my board only has a led and a DRV5032FB (<<1uA) in addition to the nrf51 module.

                                      NeverDieN Nca78N 2 Replies Last reply
                                      0
                                      • T Offline
                                        T Offline
                                        Toyman
                                        wrote on last edited by
                                        #1474

                                        Just to close the loop on DC-DC:

                                        http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fpower.html&anchor=concept

                                        Figure 2

                                        1 Reply Last reply
                                        0
                                        • Nca78N Nca78

                                          @nca78 said in nRF5 Bluetooth action!:

                                          I will try it on my board (using a module with QFAAH0) tomorrow, if power consumption is as low as expected I'll try on the beacon board.

                                          @NeverDie I have tried the sketch nearly unchanged (only changed to lines because I use pin P0.01 so AIN2) and my current consumption is a bit over 30uA, do you have any idea of what I should check ? (I tried with both versions 0.1 and 0.3 of MySensors NRF5 boards).
                                          At the moment my board only has a led and a DRV5032FB (<<1uA) in addition to the nrf51 module.

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

                                          @nca78 said in nRF5 Bluetooth action!:

                                          do you have any idea of what I should check ?

                                          Have you tried disabling serial?

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


                                          23

                                          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