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.5k 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
    #828

    Interestingly enough, it turns out all I need to do is transmit one packet, and afterward just leave the radio in TXIDLE mode. That's because, as indicated in the datasheet, it transmits a carrier wave of one's (or any pattern you program) after the packet, expecting that another packet will be sent soon. This is illustrated in Figure 37 of the DS.

    1 Reply Last reply
    0
    • NeverDieN Offline
      NeverDieN Offline
      NeverDie
      Hero Member
      wrote on last edited by NeverDie
      #829

      So, I've got the transmit side of this problem figured out. Next up: the receiver side, which already works using the MCU.
      The next step will be to see whether I can setup timed events from the RTC which can be used to trigger the PPI to measure the RSSI without waking up the MCU. Also, I'll need some way for the PPI to evaluate the magnitude of the RSSI without involving the MCU. Ideally it would also trigger a Rx sequence if the RSSI is above threshold and wake the MCU if something gets received. Not sure how much of this will be possible, but that's the wish list.

      I'd say the energy consumption is already pretty good after switching to the RSSI paradigm, but if this succeeds, then it may cut what remains of the energy consumption roughly in half. At that point, I think we will have wrung just about every possible bit of efficiency out of this radio, with the remaining to-do's as mostly mop-up and maybe some fine tuning (e.g. to better mitigate against false positives on the RSSI threshhold trigger).

      1 Reply Last reply
      1
      • NeverDieN Offline
        NeverDieN Offline
        NeverDie
        Hero Member
        wrote on last edited by NeverDie
        #830

        So, I figure the way to get started is to do something "easy", like maybe use the PPI to blink an LED.

        We want the lower power RTC, not the system clock. We want to use the RTC TICK event, so that the mpu can be powered down while the PPI is running.

        So, because I want a timer event every 100ms, that means the prescaler should be 3276.

        1 Reply Last reply
        0
        • NeverDieN Offline
          NeverDieN Offline
          NeverDie
          Hero Member
          wrote on last edited by NeverDie
          #831

          So, just starting on this, where I'm at is:

          #include <nrf.h>
          #include <MySensors.h>
          
          
          #define LED_PIN 18
          
          bool toggle=false;  //track whether or not to toggle the LED pin
          
          void setup() {
            NRF_CLOCK->LFCLKSRC=1;  //use the crystal oscillator.
            NRF_CLOCK->TASKS_LFCLKSTART=1;  //start the crystal oscillator clock
            while (!(NRF_CLOCK->EVENTS_LFCLKSTARTED)) {}  //busy-wait until the clock is confirmed started.
          
            NRF_RTC1->TASKS_STOP=1;  //stop the RTC so that we can set the prescaler
            NRF_RTC1->PRESCALER=3276;  //once per 100ms
            NRF_RTC1->TASKS_START=1;  //start the RTC so that we can start getting TICK events
          
            hwPinMode(LED_PIN,OUTPUT_H0H1);  //establish P0.18 as the LED pin.
          }
          
          void loop() {
            if (NRF_RTC1->EVENTS_TICK) {
              toggle=!toggle;
              digitalWrite(LED_PIN,toggle);
            }
          }
          

          Unfortunately, this does not work because (NRF_RTC1->EVENTS_TICK) always reads as zero. Not sure why(?).

          NeverDieN 1 Reply Last reply
          0
          • NeverDieN NeverDie

            This whole topic has been brewing in the back of my mind for a couple years now:
            https://forum.mysensors.org/topic/1788/nrf51822-as-an-all-in-one
            and
            https://forum.mysensors.org/topic/3836/anyone-besides-me-looking-into-long-range-bluetooth-for-their-wireless-nodes

            With the nRF52840, it looks as though the moment has finally arrived to tie it all together and give it a try. :)

            I just have no idea where to even begin though. Just order the nRF52840 preview DK? Is it fairly quick to get something up and running, or is it a fairly steep learning curve?

            JokgiJ Offline
            JokgiJ Offline
            Jokgi
            wrote on last edited by
            #832

            @NeverDie you will need long range capabilities on both sides of the link. So two preview kits work great. Long range is supported by SDK 14 and the current softdevice.

            NeverDieN 1 Reply Last reply
            0
            • scalzS scalz

              @NeverDie
              nrf52832 is definitely better than nrf24l01. if i'm not wrong, 4db can double range in theory.
              For range, an important point is the antenna, as you already know.
              Chip antenna can be ok, depending on the environment and usecase, but can't compete with a rfm69. These antennas are not for long range, so the adafruit board. How to miniaturize antennas without loosing performance..

              JokgiJ Offline
              JokgiJ Offline
              Jokgi
              wrote on last edited by
              #833

              @scalz the nRF52832 has a hotter receiver. ( better sensitivity.) at 1 mb/ s then the nRF24l series. Overall link Budget is better. 840 even better with a 8dB output.

              1 Reply Last reply
              0
              • scalzS Offline
                scalzS Offline
                scalz
                Hardware Contributor
                wrote on last edited by scalz
                #834

                @Jokgi
                of course I agree !
                that's why in the past i preferred rfm69 modules (better range of course, but more power hungry). 832 being better than nrf24, i'm now using it. And I also like the 840dk (neat package) :+1:
                That said, if i remember well, nrf52832 is not fully BLE5 long range compatible as 840 is.

                1 Reply Last reply
                0
                • JokgiJ Jokgi

                  @NeverDie you will need long range capabilities on both sides of the link. So two preview kits work great. Long range is supported by SDK 14 and the current softdevice.

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

                  @Jokgi said in nRF5 Bluetooth action!:

                  @NeverDie you will need long range capabilities on both sides of the link. So two preview kits work great. Long range is supported by SDK 14 and the current softdevice.

                  I'm not disagreeing, but presently modules for it (other than the preview DK) aren't yet available. Meanwhile, hopefully nearly all of what's being learned here about the nRF52832 will be of direct relevance. For instance: PPI.

                  1 Reply Last reply
                  0
                  • NeverDieN NeverDie

                    So, just starting on this, where I'm at is:

                    #include <nrf.h>
                    #include <MySensors.h>
                    
                    
                    #define LED_PIN 18
                    
                    bool toggle=false;  //track whether or not to toggle the LED pin
                    
                    void setup() {
                      NRF_CLOCK->LFCLKSRC=1;  //use the crystal oscillator.
                      NRF_CLOCK->TASKS_LFCLKSTART=1;  //start the crystal oscillator clock
                      while (!(NRF_CLOCK->EVENTS_LFCLKSTARTED)) {}  //busy-wait until the clock is confirmed started.
                    
                      NRF_RTC1->TASKS_STOP=1;  //stop the RTC so that we can set the prescaler
                      NRF_RTC1->PRESCALER=3276;  //once per 100ms
                      NRF_RTC1->TASKS_START=1;  //start the RTC so that we can start getting TICK events
                    
                      hwPinMode(LED_PIN,OUTPUT_H0H1);  //establish P0.18 as the LED pin.
                    }
                    
                    void loop() {
                      if (NRF_RTC1->EVENTS_TICK) {
                        toggle=!toggle;
                        digitalWrite(LED_PIN,toggle);
                      }
                    }
                    

                    Unfortunately, this does not work because (NRF_RTC1->EVENTS_TICK) always reads as zero. Not sure why(?).

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

                    @NeverDie said in nRF5 Bluetooth action!:

                    Unfortunately, this does not work because (NRF_RTC1->EVENTS_TICK) always reads as zero. Not sure why(?).

                    It should be working, but it isn't. Nor do I see a way to check it with an oscilliscope. So, my current theory is that it gets set but cleared so quickly that it can't be read by the MCU. So, the next step will be to assume that it is, in fact, working, and to use it as a PPI trigger, which is what this is all building toward anyway.

                    On the other hand, perhaps there's an easy way to have the EVENTS_TICK set an interrupt bit, which would persist until it was cleared? Hmmm. No, not quite, but there is INTENSET, which will set an interrupt on an EVENT_TICK. That will do. Exactly which interrupt gets triggered though? Figure 46 shows that an IRQ signal is sent to NVIC ( the Nested Vectored Interrupt Controller). According to the table in sectoin 7.3, the NVIC has 37 interrupt vectors. According to section 15.8:

                    A peripheral only occupies one interrupt, and the interrupt number follows the peripheral ID. For example, the
                    peripheral with ID=4 is connected to interrupt number 4 in the Nested Vectored Interrupt Controller (NVIC).

                    So, based on that, we need to know the ID number for the RTC, and then we'll know which interrupt number to track. According to Table 10, the Peripheral ID for the RTC is 11 (well, at least it is for the RTC0, so I will recode to use RTC0 instead of RTC1).

                    Now, according to Table 10, the memory location that corresponds to Peripheral ID 11 is 0x4000B000. Therefore, it is this memory location we need to examine to know if a TICK interrupt has occured.

                    1 Reply Last reply
                    0
                    • NeverDieN Offline
                      NeverDieN Offline
                      NeverDie
                      Hero Member
                      wrote on last edited by NeverDie
                      #837

                      Close, but no cigar. What I found out is that if I set the TICK interrupt with:

                            NRF_RTC0->INTENSET=1;  //set the TICK interrupt bit
                      

                      then at the following memory addresses, the value stored there immediately becomes 1:
                      4000B300
                      4000B304
                      4000B308

                      and if I clear the TICK interrupt with:

                            NRF_RTC0->INTENCLR=1;  //clear the TICK interrupt bit
                      

                      then the values at those same memory addresses immediately becomes zero. I can toggle back and forth as much as I want, and this is always true.

                      However, none of this is telling me whether the TICK interrupt has actually triggered. Where do I find that?

                      Based on the current pre-scaler, COUNTER increments once every TICK (i.e. once every 100ms). However, is there an actual TICK flag somewhere that goes high at those times and then low again after getting cleared? Or, is it only accessible indirectly by using PPI?

                      1 Reply Last reply
                      0
                      • NeverDieN Offline
                        NeverDieN Offline
                        NeverDie
                        Hero Member
                        wrote on last edited by NeverDie
                        #838

                        OK, I came up with a simple equivalent. Basically, every time COUNTER is incremented, I reset it to zero. It then effectively acts much the way a TICK should. For whatever reason, once EVENTS_TICK goes high, it just stays high forever. So, it doesn't seem very useful per se, though maybe there's a way to clear it that I haven't yet found.

                        1 Reply Last reply
                        0
                        • NeverDieN Offline
                          NeverDieN Offline
                          NeverDie
                          Hero Member
                          wrote on last edited by NeverDie
                          #839

                          Strangely enough, the overflow is the same: once it goes HIGH, it stays that way:
                          https://pastebin.com/vypuVJeh

                          So, I would think there must be some way (?) to clear them.

                          1 Reply Last reply
                          0
                          • NeverDieN Offline
                            NeverDieN Offline
                            NeverDie
                            Hero Member
                            wrote on last edited by NeverDie
                            #840

                            I found the answer. Unlike EVENTS in other peripherals, which are read-only, the EVENTS in RTC are RW. So, the way you clear the TICK and OVRFLW events is just by setting them to zero manually:
                            e.g.

                            NRF_RTC0->EVENTS_TICK=0;
                            

                            LOL. Of course, the DS never mentions this.

                            In any case, with that change, it can now work properly:
                            https://pastebin.com/nHWAGFkd

                            1 Reply Last reply
                            0
                            • NeverDieN Offline
                              NeverDieN Offline
                              NeverDie
                              Hero Member
                              wrote on last edited by NeverDie
                              #841

                              However, it does raise the question: if I were to use EVENTS_TICK to trigger some PPI actions, how could PPI also be used to set EVENTS_TICK back to zero so that those actions can be repeated on the next TICK? I haven't yet found an PPI TASKS that can directly manipulate, or even just clear, a particular memory location.

                              1 Reply Last reply
                              0
                              • NeverDieN Offline
                                NeverDieN Offline
                                NeverDie
                                Hero Member
                                wrote on last edited by NeverDie
                                #842

                                Since there are no apparent shortcuts pertaining to the RTC, it looks as though all non-MCU manipulations will have to happen via PPI.

                                I don't see how to clear a TICK using PPI, so I think the simplest thing would be clearing the counter back to zero if it hits one.

                                If there's no way to do this basic thing, then I see no way to have a "listen mode" equivalent for the nRF52832 that runs via PPI.

                                So, adapting what @d00616 wrote earlier, maybe the PPI code to do that would be:

                                  #define CHANNEL (1)
                                  NRF_PPI->CH[CHANNEL].EEP = (uint32_t)&NRF_RTC0->COUNTER;  //when COUNTER goes from zero to one.
                                  NRF_PPI->CH[CHANNEL].TEP = (uint32_t)&NRF_RTC0->TASKS_CLEAR;  //clear COUNTER back to zero.
                                  NRF_PPI->CHENSET = (1 << CHANNEL) ;
                                

                                Well, it does compile, but it doesn't work. :( I think it doesn't work because COUNTER is not an event.

                                Unfortunately, changing COUNTER to EVENTS_TICK fails also:

                                  NRF_PPI->CH[0].EEP = (uint32_t)&NRF_RTC0->EVENTS_TICK;  //when TICK occurs.
                                  NRF_PPI->CH[0].TEP = (uint32_t)&NRF_RTC0->TASKS_CLEAR;  //clear COUNTER back to zero.
                                  NRF_PPI->CHENSET=1;   //Enable Channel 0.
                                

                                Unfortunately, the PPI Example code from Nordic's SDK doesn't look even remotely similar to what we're doing here.

                                Anyhow, the last thing I tried was this:

                                  NRF_RTC0->INTENSET=1;  //Allows TICK to create an interrupt.
                                  NRF_PPI->CH[0].EEP = (uint32_t)&NRF_RTC0->EVENTS_TICK;  //when TICK occurs.
                                  NRF_PPI->CH[0].TEP = (uint32_t)&NRF_RTC0->TASKS_CLEAR;  //clear COUNTER back to zero.
                                  NRF_PPI->CHENSET=1; //enable Channel 0.
                                

                                hoping that it might make a difference, but it still fails. Why? What is wrong with it?

                                1 Reply Last reply
                                0
                                • U Offline
                                  U Offline
                                  Uhrheber
                                  wrote on last edited by
                                  #843

                                  @NeverDie said in nRF5 Bluetooth action!:

                                  EVENTS_TICK

                                  From the datasheet:

                                  15.6 Events
                                  Events are used to notify peripherals and the CPU about events that have happened, for example, a state
                                  change in a peripheral. A peripheral may generate multiple events with each event having a separate
                                  register in that peripheral’s event register group.
                                  An event is generated when the peripheral itself toggles the corresponding event signal, and the event
                                  register is updated to reflect that the event has been generated. See Figure 10: Tasks, events, shortcuts,
                                  and interrupts on page 68. An event register is only cleared when firmware writes a '0' to it.
                                  Events can be generated by the peripheral even when the event register is set to '1'.
                                  

                                  Maybe I don't get the problem here, but the way I see it, you have to actively write a '0' to the event register to clear it, but in fact it shouldn't matter, because the timer can nevertheless generate an event.

                                  NeverDieN 1 Reply Last reply
                                  1
                                  • U Uhrheber

                                    @NeverDie said in nRF5 Bluetooth action!:

                                    EVENTS_TICK

                                    From the datasheet:

                                    15.6 Events
                                    Events are used to notify peripherals and the CPU about events that have happened, for example, a state
                                    change in a peripheral. A peripheral may generate multiple events with each event having a separate
                                    register in that peripheral’s event register group.
                                    An event is generated when the peripheral itself toggles the corresponding event signal, and the event
                                    register is updated to reflect that the event has been generated. See Figure 10: Tasks, events, shortcuts,
                                    and interrupts on page 68. An event register is only cleared when firmware writes a '0' to it.
                                    Events can be generated by the peripheral even when the event register is set to '1'.
                                    

                                    Maybe I don't get the problem here, but the way I see it, you have to actively write a '0' to the event register to clear it, but in fact it shouldn't matter, because the timer can nevertheless generate an event.

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

                                    @Uhrheber said in nRF5 Bluetooth action!:

                                    you have to actively write a '0' to the event register to clear it

                                    This is right. I later confirmed it (see above), but thank you for the passage in the datasheet. I could have sworn that somewhere the DS said that events were read-only, but the passage you quoted contradicts that recollection. So, thank you again.

                                    Any thoughts on the PPI question (directly above your post)?

                                    1 Reply Last reply
                                    0
                                    • U Offline
                                      U Offline
                                      Uhrheber
                                      wrote on last edited by
                                      #845

                                      So, you want to shut the CPU down, leaving only RTC and PPI running, and generate a wakeup event every 100ms, did I get that right?
                                      I didn't dig that far into the datasheet, and also I don't have any board for testing (yet).

                                      Also, I didn't check whether the debugger will survive a power down/up cycle.
                                      Does it?

                                      NeverDieN 2 Replies Last reply
                                      0
                                      • U Uhrheber

                                        So, you want to shut the CPU down, leaving only RTC and PPI running, and generate a wakeup event every 100ms, did I get that right?
                                        I didn't dig that far into the datasheet, and also I don't have any board for testing (yet).

                                        Also, I didn't check whether the debugger will survive a power down/up cycle.
                                        Does it?

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

                                        @Uhrheber said in nRF5 Bluetooth action!:

                                        So, you want to shut the CPU down, leaving only RTC and PPI running, and generate a wakeup event every 100ms, did I get that right?

                                        Yes. I hope to do more than only just that using the PPI while the CPU sleeps, but that does seem like the first step.

                                        1 Reply Last reply
                                        0
                                        • U Uhrheber

                                          So, you want to shut the CPU down, leaving only RTC and PPI running, and generate a wakeup event every 100ms, did I get that right?
                                          I didn't dig that far into the datasheet, and also I don't have any board for testing (yet).

                                          Also, I didn't check whether the debugger will survive a power down/up cycle.
                                          Does it?

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

                                          @Uhrheber said in nRF5 Bluetooth action!:

                                          Also, I didn't check whether the debugger will survive a power down/up cycle.
                                          Does it?

                                          Don't know. I haven't started using the debugger yet.

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


                                          15

                                          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