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.4k 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.
  • O Offline
    O Offline
    Omemanti
    wrote on last edited by
    #1765

    A quick Google pointed me to https://github.com/AndruPol/nrf52832-recover/blob/master/README.md

    I do have a STM32F103C8T6 laying around. But ATM no time to play with it.

    Maybe that's the €3 solution for unlocking.

    T 1 Reply Last reply
    0
    • O Omemanti

      A quick Google pointed me to https://github.com/AndruPol/nrf52832-recover/blob/master/README.md

      I do have a STM32F103C8T6 laying around. But ATM no time to play with it.

      Maybe that's the €3 solution for unlocking.

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

      @omemanti said in [nRF5 action!]Maybe that's the €3 solution for unlocking.

      BMP is enough to unlock. BluePill costs ca. €2 and it's easily convertable to BMP

      1 Reply Last reply
      0
      • mr_redM Offline
        mr_redM Offline
        mr_red
        wrote on last edited by
        #1767

        @Omemanti Good find about the BMP to recover the Ebyte module. Can you point me to an aliexpress link? "stm32" "bluepill" are not the magic chinese keywords..

        mfalkviddM 1 Reply Last reply
        1
        • mr_redM mr_red

          @Omemanti Good find about the BMP to recover the Ebyte module. Can you point me to an aliexpress link? "stm32" "bluepill" are not the magic chinese keywords..

          mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by
          #1768

          @mr_red https://medium.com/@paramaggarwal/converting-an-stm32f103-board-to-a-black-magic-probe-c013cf2cc38c has keywords and a direct link to Ali

          1 Reply Last reply
          1
          • alowhumA Offline
            alowhumA Offline
            alowhum
            Plugin Developer
            wrote on last edited by
            #1769

            I created a BMP, both from a cheap ST-Link and an STM32, and it didn't help me break open those eByte NRF52 units.

            mr_redM 1 Reply Last reply
            0
            • alowhumA alowhum

              I created a BMP, both from a cheap ST-Link and an STM32, and it didn't help me break open those eByte NRF52 units.

              mr_redM Offline
              mr_redM Offline
              mr_red
              wrote on last edited by
              #1770

              @alowhum where did you get stuck? Whats your process?

              ileneken3I 1 Reply Last reply
              0
              • monteM monte

                @smilvert I think I solved issues I mentioned. But I don't have final code yet as I am waiting for parts to arrive for my board. But I think there is no problem using WT51822 board except that you'll have to manually set PORT interrupt and also set pin SENSE register which is cannot be done with arduino function pinMode().
                So I guess you can order PCBs if you want, I'm going to post final sketch with explanations at the end of the month.

                W Offline
                W Offline
                waspie
                wrote on last edited by
                #1771

                @monte do you have final code now ? :)

                1 Reply Last reply
                0
                • mr_redM mr_red

                  @alowhum where did you get stuck? Whats your process?

                  ileneken3I Offline
                  ileneken3I Offline
                  ileneken3
                  wrote on last edited by
                  #1772

                  @mr_red

                  I got to the point where the stm32loader.py runs and outputs:

                  Bootloader version 22
                  Chip id: 0x410 (STM32 Medium-density)
                  Write 256 bytes at 0x8000000
                  Write 256 bytes at 0x8000100
                  [..snip..]
                  Write 256 bytes at 0x8001900
                  Write 256 bytes at 0x8001A00
                  Read 256 bytes at 0x8000000
                  Read 256 bytes at 0x8000100
                  [..snip..]
                  Read 256 bytes at 0x8001900
                  Read 256 bytes at 0x8001A00
                  Verification OK

                  After that, you're supposed to plug in to the USB directly. I get " USB device not recognized". Zadig doesn't help. It lists it as:

                  "Unknown USB Device (Device Descriptor Request Failed)"

                  Any ideas?

                  Thanks.

                  T 1 Reply Last reply
                  0
                  • ileneken3I ileneken3

                    @mr_red

                    I got to the point where the stm32loader.py runs and outputs:

                    Bootloader version 22
                    Chip id: 0x410 (STM32 Medium-density)
                    Write 256 bytes at 0x8000000
                    Write 256 bytes at 0x8000100
                    [..snip..]
                    Write 256 bytes at 0x8001900
                    Write 256 bytes at 0x8001A00
                    Read 256 bytes at 0x8000000
                    Read 256 bytes at 0x8000100
                    [..snip..]
                    Read 256 bytes at 0x8001900
                    Read 256 bytes at 0x8001A00
                    Verification OK

                    After that, you're supposed to plug in to the USB directly. I get " USB device not recognized". Zadig doesn't help. It lists it as:

                    "Unknown USB Device (Device Descriptor Request Failed)"

                    Any ideas?

                    Thanks.

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

                    @ileneken3 have you returned the jumpers back?

                    ileneken3I 1 Reply Last reply
                    0
                    • T Toyman

                      @ileneken3 have you returned the jumpers back?

                      ileneken3I Offline
                      ileneken3I Offline
                      ileneken3
                      wrote on last edited by
                      #1774

                      @toyman
                      Unfortunately, yes, I have returned the jumpers to their original settings, and have even tried all 4 combinations.
                      I also changed computers, changed OS's, changed cables.

                      The board LOOKS like it was well manufactured, but I suppose a bad board is a possibility. Other than that, I can't figure out what could be wrong.

                      1 Reply Last reply
                      0
                      • d00616D d00616

                        @Nca78 said in nRF5 Bluetooth action!:

                        Does that mean I have to go the long hard way with a bluepill as programmer and openocd ? Anyone has other ideas to unlock and erase the device ?

                        Select in to Tools menu "None" Softdevice and then "Burn Bootloader". This raises an error but the device is erased completely.

                        sebiS Offline
                        sebiS Offline
                        sebi
                        wrote on last edited by
                        #1775

                        @d00616 said in nRF5 action!:

                        @Nca78 said in nRF5 Bluetooth action!:

                        Does that mean I have to go the long hard way with a bluepill as programmer and openocd ? Anyone has other ideas to unlock and erase the device ?

                        Select in to Tools menu "None" Softdevice and then "Burn Bootloader". This raises an error but the device is erased completely.

                        I am having the same issue trying to write on a E73 module with read/write protections. I don't have a JLink, but a ST Link-V2 and OpenOCD.
                        Do you know how to remove the protections on the E73 with such tools? Thanks.

                        1 Reply Last reply
                        0
                        • N Offline
                          N Offline
                          novicit
                          wrote on last edited by
                          #1776

                          @sebi,
                          A couple weeks ago I began exploring deploying E73 modules and had to remove protections. I was successful and now have a working E73 ethernet gateway. Only had ST Link-V2, so I used a "blue pill" I had in inventory to load it with Black Magic Probe. This cleared the protections.

                          The instructions I followed to load the BMP are step-by-step at https://github.com/TamojitSaha/STM32f103_Black-Magic-Probe

                          The instructions followed to clear protections with BMP also are step-by-step and worked perfect. They are at https://github.com/AndruPol/nrf52832-recover

                          In item #4, the program arm-none-eabi-gdb.exe seems to be part of the Arduino tool chain as I found it just by doing a search in file explorer and it was already on my win10 machine. Also, in item #4, (gdb) is the prompt that the program arm-none-eabi-gdb.exe gives. In the first line, change the '/dev/ttyACM0' to your com port. Use 'quit' to exit the program. Also, use 'mon help' to see options.

                          There are apparently a number of ways to 'recover' the E73, but this worked easily for me, and was step-by-step.

                          1 Reply Last reply
                          2
                          • N Offline
                            N Offline
                            ncollins
                            wrote on last edited by
                            #1777

                            @NeverDie Hoping you can help me with an WTNRF51822-S4AT problem where my stop recognizing interrupt events 2ish days after the last interrupt.

                            The buttons sleep for 24 hours, then wake up and send battery level. Even though the interrupt stops triggering, they still send battery level.

                            Possible some kind of timer is expiring?

                            Any help is appreciated.

                            // General settings
                            #define SKETCH_NAME "ThinButton"
                            #define SENSOR_NAME SKETCH_NAME
                            #define SKETCH_VERSION "1.4"
                            
                            #define MY_NODE_ID 37
                            
                            
                            #define MY_BAUD_RATE 115200
                            //#define MY_DEBUG
                            
                            #define IS_NRF51 
                            #define PIR_DETECTION_PIN 3
                            #define SHORT_WAIT 50
                            #define DEBOUNCE_MS 1000
                            
                            volatile bool motion_change=false;
                            
                            #define MY_RADIO_NRF5_ESB
                            
                            #include <MySensors.h>
                            
                            #define SLEEP_MS 1000 * 60 * 60 * 24
                            
                            #define   CHILD_ID_VOLT 1
                            MyMessage msgBattery(CHILD_ID_VOLT, V_VOLTAGE);
                            
                            #define CHILD_ID_BTN 2
                            #define BTN_PIN PIR_DETECTION_PIN
                            MyMessage msgBtn(CHILD_ID_BTN, V_TRIPPED);
                            
                            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() {  //turn-off energy drains prior to sleep
                              turnOffHighFrequencyClock();
                              turnOffRadio();
                              turnOffUarte0();
                            }
                             
                            
                            void activateLpComp() {
                              NRF_LPCOMP->PSEL=4; // monitor AIN0 (i.e. pin P0.02 on nRF52832 PIR Motion Sensor v607).
                              while (!(NRF_LPCOMP->PSEL==4)) {} //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->ANADETECT=0;  //detect CROSS events on PIR detection pin
                              while (NRF_LPCOMP->ANADETECT!=0) {} //wait until confirmed
                              NRF_LPCOMP->INTENSET=B1000;  //Enable interrupt for CROSS event
                              while (!(((NRF_LPCOMP->INTENSET)&B1000)==B1000)) {} //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)==B0100) {} //wait until confirmed
                              }
                            }
                            
                            void resumeLpComp() { //suspend getting interrupts from LPCOMP
                              NRF_LPCOMP->INTENSET=B0100;  //Enable interrupt for UP event
                              while (((NRF_LPCOMP->INTENSET)&B1000)!=B0100) {} //wait until confirmed
                            }
                            // setup
                            void setup() {
                              hwInit();
                              hwPinMode(PIR_DETECTION_PIN,INPUT);
                            
                              disableNfc();  //remove unnecessary energy drains
                              turnOffAdc();  //remove unnecessary energy drains
                              activateLpComp();
                              motion_change=false;
                            }
                            
                            void mySleep(uint32_t ms) {
                               mySleepPrepare();  //Take steps to reduce drains on battery current prior to sleeping
                               sleep(ms);
                            }
                            
                            
                            // presentation
                            void presentation() {
                              sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
                            
                              present(CHILD_ID_VOLT, S_MULTIMETER, SENSOR_NAME);
                              wait(SHORT_WAIT);
                              present(CHILD_ID_BTN, S_MOTION, SENSOR_NAME);
                              wait(SHORT_WAIT);
                            }
                            
                            unsigned long lastTripped = millis();
                            
                            // loop
                            void loop() {
                              mySleep(SLEEP_MS);
                              
                              if(motion_change){
                                unsigned long ms = millis();
                                long timeDiff = ms - lastTripped; 
                                
                                if(timeDiff < 0 || timeDiff > 1000){ 
                                  send(msgBtn.set((uint8_t) 1));
                                }
                                 
                                NRF_LPCOMP->EVENTS_CROSS=0;
                                motion_change=false;
                                lastTripped = millis();
                              } else {
                                
                                send(msgBattery.set(getInternalVoltage(),3));
                              }
                            }
                            
                            float getInternalVoltage(){
                              return ((float)hwCPUVoltage())/1000.0;
                            }
                            
                            
                            #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) {motion_change=true; NRF5_RESET_EVENT(NRF_LPCOMP->EVENTS_CROSS); NRF_LPCOMP->EVENTS_CROSS=0; MY_HW_RTC->CC[0]=(MY_HW_RTC->COUNTER+2);}}
                            
                            NeverDieN W 2 Replies Last reply
                            0
                            • N ncollins

                              @NeverDie Hoping you can help me with an WTNRF51822-S4AT problem where my stop recognizing interrupt events 2ish days after the last interrupt.

                              The buttons sleep for 24 hours, then wake up and send battery level. Even though the interrupt stops triggering, they still send battery level.

                              Possible some kind of timer is expiring?

                              Any help is appreciated.

                              // General settings
                              #define SKETCH_NAME "ThinButton"
                              #define SENSOR_NAME SKETCH_NAME
                              #define SKETCH_VERSION "1.4"
                              
                              #define MY_NODE_ID 37
                              
                              
                              #define MY_BAUD_RATE 115200
                              //#define MY_DEBUG
                              
                              #define IS_NRF51 
                              #define PIR_DETECTION_PIN 3
                              #define SHORT_WAIT 50
                              #define DEBOUNCE_MS 1000
                              
                              volatile bool motion_change=false;
                              
                              #define MY_RADIO_NRF5_ESB
                              
                              #include <MySensors.h>
                              
                              #define SLEEP_MS 1000 * 60 * 60 * 24
                              
                              #define   CHILD_ID_VOLT 1
                              MyMessage msgBattery(CHILD_ID_VOLT, V_VOLTAGE);
                              
                              #define CHILD_ID_BTN 2
                              #define BTN_PIN PIR_DETECTION_PIN
                              MyMessage msgBtn(CHILD_ID_BTN, V_TRIPPED);
                              
                              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() {  //turn-off energy drains prior to sleep
                                turnOffHighFrequencyClock();
                                turnOffRadio();
                                turnOffUarte0();
                              }
                               
                              
                              void activateLpComp() {
                                NRF_LPCOMP->PSEL=4; // monitor AIN0 (i.e. pin P0.02 on nRF52832 PIR Motion Sensor v607).
                                while (!(NRF_LPCOMP->PSEL==4)) {} //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->ANADETECT=0;  //detect CROSS events on PIR detection pin
                                while (NRF_LPCOMP->ANADETECT!=0) {} //wait until confirmed
                                NRF_LPCOMP->INTENSET=B1000;  //Enable interrupt for CROSS event
                                while (!(((NRF_LPCOMP->INTENSET)&B1000)==B1000)) {} //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)==B0100) {} //wait until confirmed
                                }
                              }
                              
                              void resumeLpComp() { //suspend getting interrupts from LPCOMP
                                NRF_LPCOMP->INTENSET=B0100;  //Enable interrupt for UP event
                                while (((NRF_LPCOMP->INTENSET)&B1000)!=B0100) {} //wait until confirmed
                              }
                              // setup
                              void setup() {
                                hwInit();
                                hwPinMode(PIR_DETECTION_PIN,INPUT);
                              
                                disableNfc();  //remove unnecessary energy drains
                                turnOffAdc();  //remove unnecessary energy drains
                                activateLpComp();
                                motion_change=false;
                              }
                              
                              void mySleep(uint32_t ms) {
                                 mySleepPrepare();  //Take steps to reduce drains on battery current prior to sleeping
                                 sleep(ms);
                              }
                              
                              
                              // presentation
                              void presentation() {
                                sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
                              
                                present(CHILD_ID_VOLT, S_MULTIMETER, SENSOR_NAME);
                                wait(SHORT_WAIT);
                                present(CHILD_ID_BTN, S_MOTION, SENSOR_NAME);
                                wait(SHORT_WAIT);
                              }
                              
                              unsigned long lastTripped = millis();
                              
                              // loop
                              void loop() {
                                mySleep(SLEEP_MS);
                                
                                if(motion_change){
                                  unsigned long ms = millis();
                                  long timeDiff = ms - lastTripped; 
                                  
                                  if(timeDiff < 0 || timeDiff > 1000){ 
                                    send(msgBtn.set((uint8_t) 1));
                                  }
                                   
                                  NRF_LPCOMP->EVENTS_CROSS=0;
                                  motion_change=false;
                                  lastTripped = millis();
                                } else {
                                  
                                  send(msgBattery.set(getInternalVoltage(),3));
                                }
                              }
                              
                              float getInternalVoltage(){
                                return ((float)hwCPUVoltage())/1000.0;
                              }
                              
                              
                              #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) {motion_change=true; NRF5_RESET_EVENT(NRF_LPCOMP->EVENTS_CROSS); NRF_LPCOMP->EVENTS_CROSS=0; MY_HW_RTC->CC[0]=(MY_HW_RTC->COUNTER+2);}}
                              
                              NeverDieN Offline
                              NeverDieN Offline
                              NeverDie
                              Hero Member
                              wrote on last edited by NeverDie
                              #1778

                              @ncollins

                              It has been a while. I may be switching to PIC: https://forum.mysensors.org/topic/10666/anyone-ever-look-into-ezbl-aka-easy-booloader-on-a-pic

                              The impression I get is that you just write the new hex file into flash, flip a switch in software, and bang, you switchover to the new firmware without skipping a beat. No need to even reboot.

                              I think anything with the best general solution for OTA updates is a better path than doing OTA firmware bootloader one-offs for each MCU. From what I've gathered, it seems PIC may be the only one with the generalized bootloader support that I'm looking for. I haven't tried PIC before, but I'll be receiving a PIC board on Tuesday to test out this new theory. I'm gravitating toward LoRa anyway, so for that I can't leverage anything from NRF5x anyway. LoRa is the closest thing to bulletproof wireless communications that I've found so far. It just works, with fantastic range and coverage while still fitting within FCC requirements.

                              PICs tend to consume less energy than both atmega's and nRF5x's while sleeping, so there may be some positive trade-offs to be had there as well.

                              I'll miss the tight integration possible with an nRF5x. Maybe someday there will be PICs with integrated LoRa radios? MicroChip makes both separately, so it could conceivably happen. They've already done it with SAM: https://pic-microcontroller.com/microchip-new-ultra-low-power-lora-sip/

                              N 1 Reply Last reply
                              1
                              • NeverDieN NeverDie

                                @ncollins

                                It has been a while. I may be switching to PIC: https://forum.mysensors.org/topic/10666/anyone-ever-look-into-ezbl-aka-easy-booloader-on-a-pic

                                The impression I get is that you just write the new hex file into flash, flip a switch in software, and bang, you switchover to the new firmware without skipping a beat. No need to even reboot.

                                I think anything with the best general solution for OTA updates is a better path than doing OTA firmware bootloader one-offs for each MCU. From what I've gathered, it seems PIC may be the only one with the generalized bootloader support that I'm looking for. I haven't tried PIC before, but I'll be receiving a PIC board on Tuesday to test out this new theory. I'm gravitating toward LoRa anyway, so for that I can't leverage anything from NRF5x anyway. LoRa is the closest thing to bulletproof wireless communications that I've found so far. It just works, with fantastic range and coverage while still fitting within FCC requirements.

                                PICs tend to consume less energy than both atmega's and nRF5x's while sleeping, so there may be some positive trade-offs to be had there as well.

                                I'll miss the tight integration possible with an nRF5x. Maybe someday there will be PICs with integrated LoRa radios? MicroChip makes both separately, so it could conceivably happen. They've already done it with SAM: https://pic-microcontroller.com/microchip-new-ultra-low-power-lora-sip/

                                N Offline
                                N Offline
                                ncollins
                                wrote on last edited by
                                #1779

                                @neverdie Interesting, thanks for the info

                                1 Reply Last reply
                                0
                                • N ncollins

                                  @NeverDie Hoping you can help me with an WTNRF51822-S4AT problem where my stop recognizing interrupt events 2ish days after the last interrupt.

                                  The buttons sleep for 24 hours, then wake up and send battery level. Even though the interrupt stops triggering, they still send battery level.

                                  Possible some kind of timer is expiring?

                                  Any help is appreciated.

                                  // General settings
                                  #define SKETCH_NAME "ThinButton"
                                  #define SENSOR_NAME SKETCH_NAME
                                  #define SKETCH_VERSION "1.4"
                                  
                                  #define MY_NODE_ID 37
                                  
                                  
                                  #define MY_BAUD_RATE 115200
                                  //#define MY_DEBUG
                                  
                                  #define IS_NRF51 
                                  #define PIR_DETECTION_PIN 3
                                  #define SHORT_WAIT 50
                                  #define DEBOUNCE_MS 1000
                                  
                                  volatile bool motion_change=false;
                                  
                                  #define MY_RADIO_NRF5_ESB
                                  
                                  #include <MySensors.h>
                                  
                                  #define SLEEP_MS 1000 * 60 * 60 * 24
                                  
                                  #define   CHILD_ID_VOLT 1
                                  MyMessage msgBattery(CHILD_ID_VOLT, V_VOLTAGE);
                                  
                                  #define CHILD_ID_BTN 2
                                  #define BTN_PIN PIR_DETECTION_PIN
                                  MyMessage msgBtn(CHILD_ID_BTN, V_TRIPPED);
                                  
                                  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() {  //turn-off energy drains prior to sleep
                                    turnOffHighFrequencyClock();
                                    turnOffRadio();
                                    turnOffUarte0();
                                  }
                                   
                                  
                                  void activateLpComp() {
                                    NRF_LPCOMP->PSEL=4; // monitor AIN0 (i.e. pin P0.02 on nRF52832 PIR Motion Sensor v607).
                                    while (!(NRF_LPCOMP->PSEL==4)) {} //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->ANADETECT=0;  //detect CROSS events on PIR detection pin
                                    while (NRF_LPCOMP->ANADETECT!=0) {} //wait until confirmed
                                    NRF_LPCOMP->INTENSET=B1000;  //Enable interrupt for CROSS event
                                    while (!(((NRF_LPCOMP->INTENSET)&B1000)==B1000)) {} //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)==B0100) {} //wait until confirmed
                                    }
                                  }
                                  
                                  void resumeLpComp() { //suspend getting interrupts from LPCOMP
                                    NRF_LPCOMP->INTENSET=B0100;  //Enable interrupt for UP event
                                    while (((NRF_LPCOMP->INTENSET)&B1000)!=B0100) {} //wait until confirmed
                                  }
                                  // setup
                                  void setup() {
                                    hwInit();
                                    hwPinMode(PIR_DETECTION_PIN,INPUT);
                                  
                                    disableNfc();  //remove unnecessary energy drains
                                    turnOffAdc();  //remove unnecessary energy drains
                                    activateLpComp();
                                    motion_change=false;
                                  }
                                  
                                  void mySleep(uint32_t ms) {
                                     mySleepPrepare();  //Take steps to reduce drains on battery current prior to sleeping
                                     sleep(ms);
                                  }
                                  
                                  
                                  // presentation
                                  void presentation() {
                                    sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
                                  
                                    present(CHILD_ID_VOLT, S_MULTIMETER, SENSOR_NAME);
                                    wait(SHORT_WAIT);
                                    present(CHILD_ID_BTN, S_MOTION, SENSOR_NAME);
                                    wait(SHORT_WAIT);
                                  }
                                  
                                  unsigned long lastTripped = millis();
                                  
                                  // loop
                                  void loop() {
                                    mySleep(SLEEP_MS);
                                    
                                    if(motion_change){
                                      unsigned long ms = millis();
                                      long timeDiff = ms - lastTripped; 
                                      
                                      if(timeDiff < 0 || timeDiff > 1000){ 
                                        send(msgBtn.set((uint8_t) 1));
                                      }
                                       
                                      NRF_LPCOMP->EVENTS_CROSS=0;
                                      motion_change=false;
                                      lastTripped = millis();
                                    } else {
                                      
                                      send(msgBattery.set(getInternalVoltage(),3));
                                    }
                                  }
                                  
                                  float getInternalVoltage(){
                                    return ((float)hwCPUVoltage())/1000.0;
                                  }
                                  
                                  
                                  #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) {motion_change=true; NRF5_RESET_EVENT(NRF_LPCOMP->EVENTS_CROSS); NRF_LPCOMP->EVENTS_CROSS=0; MY_HW_RTC->CC[0]=(MY_HW_RTC->COUNTER+2);}}
                                  
                                  W Offline
                                  W Offline
                                  waspie
                                  wrote on last edited by
                                  #1780

                                  @ncollins I had the same problem and sort of "solved" it by having it reboot every 3 hours (or maybe it was 6).

                                  I don't know how to use the nrf5x stuff anywhere near well enough to actually fix it but it seems to work.

                                  N 1 Reply Last reply
                                  0
                                  • W waspie

                                    @ncollins I had the same problem and sort of "solved" it by having it reboot every 3 hours (or maybe it was 6).

                                    I don't know how to use the nrf5x stuff anywhere near well enough to actually fix it but it seems to work.

                                    N Offline
                                    N Offline
                                    ncollins
                                    wrote on last edited by
                                    #1781

                                    @waspie I was actually about to go down that route. Would you mind posting a code snippet for how you're triggering the reboot?

                                    W 1 Reply Last reply
                                    0
                                    • N ncollins

                                      @waspie I was actually about to go down that route. Would you mind posting a code snippet for how you're triggering the reboot?

                                      W Offline
                                      W Offline
                                      waspie
                                      wrote on last edited by waspie
                                      #1782

                                      @ncollins

                                      throw this somewhere in your code:

                                      void reboot() {
                                        wdt_disable();
                                        wdt_enable(WDTO_15MS);
                                        while (1) {}
                                      }
                                      

                                      and then calling the reboot (in the entire loop):

                                      void loop() {
                                      
                                        if (motion_change) {
                                          motionDetected=!motionDetected;
                                          if (motionDetected) {
                                            send(msg.set("1"));  // motion detected
                                          }
                                          else {
                                            digitalWrite(LED_BUILTIN,LOW);  //turn-off LED to signify motion no longer detected
                                            send(msg.set("0"));  // send all-clear to prepare for future detections
                                          }    
                                          
                                          NRF_LPCOMP->EVENTS_CROSS=0;
                                          motion_change=false;
                                        }
                                        else { //must be a scheduled wake-up.  Time to report voltage as a heartbeat.
                                          batteryVoltage=((float)hwCPUVoltage())/1000.0;  //take voltage measurement after transmission to hopefully measure lowest voltage that occurs. 
                                          send(msg_S_MULTIMETER_V_VOLTAGE.set(batteryVoltage,3));  //send battery voltage with 3 decimal places
                                          time = millis();
                                          if (time > 14400000 ) {
                                            reboot();
                                          }
                                        }
                                        mySleep(1200000);  //sleep for 20 minutes
                                      }```
                                      N 2 Replies Last reply
                                      2
                                      • W waspie

                                        @ncollins

                                        throw this somewhere in your code:

                                        void reboot() {
                                          wdt_disable();
                                          wdt_enable(WDTO_15MS);
                                          while (1) {}
                                        }
                                        

                                        and then calling the reboot (in the entire loop):

                                        void loop() {
                                        
                                          if (motion_change) {
                                            motionDetected=!motionDetected;
                                            if (motionDetected) {
                                              send(msg.set("1"));  // motion detected
                                            }
                                            else {
                                              digitalWrite(LED_BUILTIN,LOW);  //turn-off LED to signify motion no longer detected
                                              send(msg.set("0"));  // send all-clear to prepare for future detections
                                            }    
                                            
                                            NRF_LPCOMP->EVENTS_CROSS=0;
                                            motion_change=false;
                                          }
                                          else { //must be a scheduled wake-up.  Time to report voltage as a heartbeat.
                                            batteryVoltage=((float)hwCPUVoltage())/1000.0;  //take voltage measurement after transmission to hopefully measure lowest voltage that occurs. 
                                            send(msg_S_MULTIMETER_V_VOLTAGE.set(batteryVoltage,3));  //send battery voltage with 3 decimal places
                                            time = millis();
                                            if (time > 14400000 ) {
                                              reboot();
                                            }
                                          }
                                          mySleep(1200000);  //sleep for 20 minutes
                                        }```
                                        N Offline
                                        N Offline
                                        ncollins
                                        wrote on last edited by
                                        #1783

                                        @waspie appreciate it, thank you

                                        1 Reply Last reply
                                        2
                                        • Sergio RiusS Offline
                                          Sergio RiusS Offline
                                          Sergio Rius
                                          wrote on last edited by
                                          #1784

                                          @NeverDie Interesting. What have pulled you from nrf52 towards PICs?
                                          Can you post a link on the board you ordered, (or one like that)? Thanks.

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


                                          17

                                          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