nRF5 action!


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    Yeah, MySensors can definitely do it. Nice work @d00616 !
    Thanks.

    It turns out that with RadioHead, I am almost able to send packets from an nRF24L01 to an nRF5 module: it's just that the packets arrive as garbage. So, the packet and/or frame formatting must be different, but indeed the network ID's are matching or else I wouldn't be receiving anything at all.

    The ID's are reversed between nRF5 and nRF24. Look into the code how to reverse the ID's.

    @NeverDie said in nRF5 Bluetooth action!:

    I found the smoking gun in the radiohead documentation. Turns out RadioHead does indeed use a different packet format for the nRF5 that is "NOT compatible with the one used by RH_NRF24 and the nRF24L01 product specification, mainly because the nRF24 only supports 6 bits of message length."

    You have to choose the correct number of bits for length, S0 and S1. I have played a while to find out the correct configuration. When ACK is enabled you have to do a lot of timing work.

    @Terrence said in nRF5 Bluetooth action!:

    @NeverDie Ya, that really sucks. It would have been great to mix and match.

    At the moment I have no opinion to the "GPL or commercial" license of Readiohead. So I have no plans to port my Code .

    The Nordic SDK has an ESB library supporting the nRF24 mode. IMHO Starting with SDK 13 the license is more Open Source friendly.


  • Hero Member

    I'm realizing I can live with it. It just means I need to add a separate nRF24 gateway if I want to use nRF24's. I'm already adding separate gateways to support RFM69's and LoRa's, so, actually, it's no big deal.

    Meanwhile, I've found that the RadioHead and the MySensors libraries are at least minimally compatible. So, presently I'm using RadioHead for my low power transmissions, but I'm using the sleep(...) function from MySensors to sleep the nRF52 and wake it up. 🙂

    The only weirdness I'm noticing is that immediately after sending the very first packet in this configuration, there's a mysterious several second delay that occurs before the code continues. However, after the initial hiccup, everything appears to run exactly as fast as it should. I have no clue as to what is causing that initial delay though. It doesn't happen if I don't #include the MySensors.h file.



  • I was playing with sleep tonight and found the following problem.
    when using sleep as below it always returns a figure 252 ms bigger than the sleep figure.
    ie sleep 10000 always returns 10251
    ie sleep 3000 always returns 3251.
    I know the nrf51822 has a 32khz rtc so why is this?

      oldmillis = hwMillis();
      hwSleep(10000);
      newmillis = hwMillis();
      Serial.println(newmillis - oldmillis);
    


  • Seems it may have something to do with this in the code.

    // Calculate sleep time
    		// 8 Hz -> max 582.542 hours sleep.
    		MY_HW_RTC->PRESCALER = 4095;
    		// Set compare register to 1/125ms + 2 to garantee event triggering
    		MY_HW_RTC->CC[0] = (ms / 125) + 2;```


  • MY_HW_RTC->CC[0] = (ms / 125) + 2;

    It seems the +2 above is adding 250ms.
    Why is it done like this???


  • Hero Member

    What more can be done to reduce current consumption on an nRF52832 when the MySensors "sleep" function is being used with RTC wakeup. I've measured a 300mv drop on a 10F capacitor over a 12 hour time period. Of that 300mv, perhaps 20mv was lost due to self-discharge of the supercap. So, that still leaves 280mv of loss due to the nRF52832 . That is too high a rate of loss.



  • @NeverDie
    Seeing Your sketch would help?


  • Contest Winner

    @rmtucker said in nRF5 Bluetooth action!:

    MY_HW_RTC->CC[0] = (ms / 125) + 2;

    It seems the +2 above is adding 250ms.
    Why is it done like this???

    A minimum of two ticks are required to be sure the CC[0] is triggered.

    What accuracy is your requirement? I can add more code here to dynamical change the pre scaler plus a check if ms/125>=2



  • @d00616
    My initial thoughts were how the nrf51822 could be used for energy meters (counting pulses and the gap between them),But unlike the arduino's which can not run timers when in sleep mode,The nrf5 can of course do this.
    So the nrf5 would be able to report watts and usage while still using sleep mode.
    But seeing the inaccuracy of the timer has put the brakes on that.
    Yes being able to change the prescaler dynamically would help a great deal as 125ms / 582.542 hours is not really useful for most applications with a 250ms overrun.



  • Just wondering what the prescaler etc would have to be set to for ms accuracy and how long before overflow.(aint got my maths head on today)😊


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    What more can be done to reduce current consumption on an nRF52832 when the MySensors "sleep" function is being used with RTC wakeup. I've measured a 300mv drop on a 10F capacitor over a 12 hour time period. Of that 300mv, perhaps 20mv was lost due to self-discharge of the supercap. So, that still leaves 280mv of loss due to the nRF52832 . That is too high a rate of loss.

    Wh = 0.5 * 10F * 280mV = 0.392 Wh = 0.0326667 W
    I=0.0326667/2.56V = 12.76mA

    Looks like the node is most time fully active.


  • Contest Winner

    @rmtucker said in nRF5 Bluetooth action!:

    @d00616
    My initial thoughts were how the nrf51822 could be used for energy meters (counting pulses and the gap between them),But unlike the arduino's which can not run timers when in sleep mode,The nrf5 can of course do this.
    So the nrf5 would be able to report watts and usage while still using sleep mode.

    If you have the idea to store the results into the EEPROM like storage the nRF5, then read the hints about this: https://github.com/d00616/arduino-NVM/#nvramh

    The virtual EEPROM, the radio or debugging output are adding latency to the main loop. You will see more timing errors in long term run when you trust the sleep() time.

    The nRF5 can help you to count without adding latency by the cpu. You can use a timer in counter mode which TASK_COUNT and TASKS_CAPTURE[0] are triggered by PPI. Then you can compare the hwMillis() with the last seen CC[0] content and do precise calculation of events.

    With nRF52 there is an unused RTC wich can trigger TASKS_CAPTURE[0] at a specific time. One RTC is used for millis() in arduino-nrf5 and one RTC is used for sleep.

    But seeing the inaccuracy of the timer has put the brakes on that.
    Yes being able to change the prescaler dynamically would help a great deal as 125ms / 582.542 hours is not really useful for most applications with a 250ms overrun.

    I will change this.


  • Hero Member

    @rmtucker
    Here it is, though it's rather messy. Nonetheless, all it does is measure the supercap and solar panel voltages, send them, then sleep for 12 hours. Then repeats:

    // nrf51_client.pde
    // -*- mode: C++ -*-
    // Example sketch showing how to create a simple messageing client
    // with the RH_NRF51 class. RH_NRF51 class does not provide for addressing or
    // reliability, so you should only use RH_NRF51 if you do not need the higher
    // level messaging abilities.
    // It is designed to work with the other example nrf51_server.
    // Tested on RedBearLabs nRF51822 and BLE Nano kit, built with Arduino 1.6.4.
    // See http://redbearlab.com/getting-started-nrf51822/
    // for how to set up your Arduino build environment
    // Also tested with Sparkfun nRF52832 breakout board, witth Arduino 1.6.13 and
    // Sparkfun nRF52 boards manager 0.2.3
    #include <RH_NRF51.h>
    #include <MySensors.h>
    
    
    unsigned long SLEEP_TIME = 43200000; // 12 hour sleep time between measurements (in milliseconds)
    //unsigned long SLEEP_TIME = 3600000; // 1 hour sleep time between measurements (in milliseconds)
    //unsigned long SLEEP_TIME = 300000; // 5 minute sleep time between measurements (in milliseconds)
    //unsigned long SLEEP_TIME = 1000; // 1 second sleep time between measurements (in milliseconds)
    #define SUPERCAP_PIN A2  //input pin for reading the supercap's voltage
    #define SOLAR_PANEL_PIN A4  //input pin for reading the solar panel's voltage
    #define LDO_ENABLE_PIN 8  //D8 (P0.19) is output pin for enabling (HIGH) or disabling (LOW) the LDO
    #define NUM_MEASUREMENTS_TO_AVERAGE 3  //number of measurements to collect and then average
    #define MAX_MEASUREMENTS 10 //Maximum number of voltage measurements before returning a result.
    
    // Singleton instance of the radio driver
    RH_NRF51 nrf51;
    uint8_t data[10];
    
    uint16_t batteryVoltage() {
      uint16_t lastRawVoltage, newRawVoltage;
      //uint16_t counter=0;
      //lastRawVoltage = hwCPUVoltage();  //throw away the first voltage measurement
      newRawVoltage = hwCPUVoltage();
    
        
      return newRawVoltage; 
    }
    
    
    
    
    uint16_t readRawVoltageOnPin(uint8_t thePin) {
      uint16_t lastRawVoltage, newRawVoltage;
      uint16_t counter=0;
      lastRawVoltage = analogRead(thePin);
      newRawVoltage = analogRead(thePin);
      while (((newRawVoltage != lastRawVoltage)) && (counter<MAX_MEASUREMENTS)) {  //measure until two consecutive measurements match
        lastRawVoltage=newRawVoltage;
        newRawVoltage=analogRead(thePin);
        counter++;
      }
      uint32_t sumOfMeasurements=0;
      for (int i=0;i<NUM_MEASUREMENTS_TO_AVERAGE;i++) {
        sumOfMeasurements=sumOfMeasurements+analogRead(thePin);
      }
        
      return (sumOfMeasurements/NUM_MEASUREMENTS_TO_AVERAGE); 
    }
    
    void myBaro()
    {
    
      uint32_t superCapVoltage=0;
      uint32_t solarPanelVoltage=0;
      uint32_t superCapRawVoltage=0;
      uint32_t solarPanelRawVoltage=0;
    
      digitalWrite(LDO_ENABLE_PIN, LOW);  //disconnect solar panel
      superCapRawVoltage = readRawVoltageOnPin(SUPERCAP_PIN);
      
      superCapVoltage = (3048*(((superCapRawVoltage)*3127)/4095))/1591;
      //Serial.print("SuperCap voltage=");
      //Serial.println(superCapVoltage);
    
      //send(msg1_S_BARO_P.set(superCapVoltage));  //superCap's raw voltage
    //  wait(500);
    
    //  wait(500);
      //delayMicroseconds(1000);  //wait for voltage to adjust after LDO disabled.  Necessary???
      
      solarPanelRawVoltage=readRawVoltageOnPin(SOLAR_PANEL_PIN);
      digitalWrite(LDO_ENABLE_PIN, HIGH);  //re-connect solar panel
      solarPanelVoltage=(5500*(((solarPanelRawVoltage)*3181)/4095))/1289;
      //Serial.print("Solar Panel Voltage=");
      //Serial.println(solarPanelVoltage);
      //superCapVoltage=1234;
    
      data[0]= (superCapVoltage/1000)+'0';
      data[1]= ((superCapVoltage%1000)/100)+'0';
      data[2]= ((superCapVoltage%100)/10)+'0';
      data[3]= (superCapVoltage%10)+'0';
      data[4]=',';
      data[5]= (solarPanelVoltage/1000)+'0';
      data[6]= ((solarPanelVoltage%1000)/100)+'0';
      data[7]= ((solarPanelVoltage%100)/10)+'0';
      data[8]= (solarPanelVoltage%10)+'0';
      data[9]='\0';
      nrf51.send(data, sizeof(data));
      nrf51.waitPacketSent();
    }
    
    
    void setup() 
    {
      pinMode(LDO_ENABLE_PIN, OUTPUT);  // Enable/Disable pin for the LDO
      digitalWrite(LDO_ENABLE_PIN, HIGH);  //enable the LDO.
    
      analogReadResolution(12);  //use 12-bit ADC resolution
      pinMode(SUPERCAP_PIN,INPUT);  //Supercap voltage measurement pin
      pinMode(SOLAR_PANEL_PIN,INPUT);  //Solar panel voltage measurement pin
      
      //delay(1000); // Wait for serial port etc to be ready
      Serial.begin(250000);
      //while (!Serial) 
        ; // wait for serial port to connect. 
      if (!nrf51.init())
        Serial.println("init failed");
      // Defaults after init are 2.402 GHz (channel 123), 2Mbps, 0dBm
      if (!nrf51.setChannel(123))
        Serial.println("setChannel failed");
      if (!nrf51.setRF(RH_NRF51::DataRate2Mbps, RH_NRF51::TransmitPower4dBm))
        Serial.println("setRF failed"); 
      
      // AES encryption can be enabled by setting the same key in the sender and receiver
    //  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
    //                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
    //  nrf51.setEncryptionKey(key);
    
    //  nrf51.printRegisters();
      Serial.println("Setup of nr51 client completed.");
      Serial.println("Sending to nrf51_server...");
      Serial.flush();
    }
    
    uint32_t sentCounter=0;
    uint32_t replyCounter=0;
    
    void loop()
    {
      //uint16_t theBatteryVoltage;
      //theBatteryVoltage=batteryVoltage();
      //theBatteryVoltage=batteryVoltage();
     // Serial.print("Battery voltage = ");
      //Serial.print(theBatteryVoltage);
      //Serial.println(" millivolts.");
      
      // Send a message to nrf51_server
      //uint8_t data[] = "Hello World!";
    /*
      data[0]= (theBatteryVoltage/1000)+'0';
      data[1]= ((theBatteryVoltage%1000)/100)+'0';
      data[2]= ((theBatteryVoltage%100)/10)+'0';
      data[3]= (theBatteryVoltage%10)+'0';
      data[4]='\0';
      nrf51.send(data, sizeof(data));
      sentCounter++;
      nrf51.waitPacketSent();
    
     */
      myBaro();
    
      /*
      // Now wait for a reply
      uint8_t buf[RH_NRF51_MAX_MESSAGE_LEN];
      uint8_t len = sizeof(buf);
    
      if (nrf51.waitAvailableTimeout(500))
      { 
        // Should be a reply message for us now   
        if (nrf51.recv(buf, &len))
        {
          Serial.print("got reply: ");
          Serial.println((char*)buf);
          replyCounter++;
        }
        else
        {
          Serial.println("recv failed");
        }
      }
      else
      {
        Serial.println("No reply, is nrf51_server running?");
      }
      Serial.print("sentCounter="); 
      Serial.print(sentCounter);
      Serial.print(", replyCounter=");
      Serial.println(replyCounter);
      Serial.flush();
      */
     
      sleep(SLEEP_TIME); // Sleeps for 12 hours in deep sleep
    }
    

    Using Termite to timestamp the output received, what I got was:

    2017/08/25 17:04:13: got request: 2684,0085
    
    2017/08/26 05:04:12: got request: 2396,0076
    

    You can ignore the solar panel measurements, because I disconnected it so as to not interfere.

    On the bright side, it woke up and reported within 1 second of when it was supposed to, after a 12 hour sleep.


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    Here it is, though it's rather messy. Nonetheless, all it does is measure the supercap and solar panel voltages, send them, then sleep for 12 hours. Then repeats:

    RadioHead sets the radio into the Idle state. The radio isn't powered off. There is no call in RadioHead to power off the radio.



  • @NeverDie
    So your sketch only wakes up every 12hours.
    What current is it drawing using the radiohead library vs mysensors for an equivalent 12 hour sleep because in past discussions with you i remember you saying 5-6uA while sleeping,is this still correct?
    I dont see much advantage to the radiohead library if only sending at 12hour intervals.


  • Hero Member

    @rmtucker said in nRF5 Bluetooth action!:

    @NeverDie
    So your sketch only wakes up every 12hours.
    What current is it drawing using the radiohead library vs mysensors for an equivalent 12 hour sleep because in past discussions with you i remember you saying 5-6uA while sleeping,is this still correct?
    I dont see much advantage to the radiohead library if only sending at 12hour intervals.

    The 6ua was measured with it in deep sleep, where it relied on an external interrupt to wakeup. This measurement was intended to see what it would be if it woke-up using the RTC. So, the 12 hour interval is artificial, for measurement purposes.

    @d00616
    I had wrongly assumed that the "sleep(...)" command would sleep the radio. Thanks for pointing out my error. How/when is it that Mysensors puts the radio to sleep? Does it just happen automatically at the end of every sending/receiving?


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    I had wrongly assumed that the "sleep(...)" command would sleep the radio. Thanks for pointing out my error. How/when is it that Mysensors puts the radio to sleep? Does it just happen automatically at the end of every sending/receiving?

    We are both not 100% correct 😉 The hwSleep() function doesn't disable the radio, but the sleep() function does it, when MY_SENSOR_NETWORK is defined.

    After Sleep transportReInitialise() is called. Then you have to initialize RadioHead again.


  • Hero Member

    @d00616 said in nRF5 Bluetooth action!:

    After Sleep transportReInitialise() is called. Then you have to initialize RadioHead again.

    So, even with RAM retention active while sleeping, each time the radio is awoken, it needs to be re-initialized?


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    So, even with RAM retention active while sleeping, each time the radio is awoken, it needs to be re-initialized?

    The Radio has to be initialized after power down. This doesn't depend on RAM retention.


  • Hero Member

    According to Table 39 of the mRF52832 datasheet, there is only one radio state resembling sleep, and that is the DISABLED radio state where "No operations are going on inside the radio and the power consumption is at a minimum."

    Apparently the radio is disabled through register TASKS_DISABLE, offset 0x010, Disable RADIO, as indicated by Table 41 register overview.


  • Hero Member

    But how exactly does one read or write to these registers? It looks like a quite different arrangement than writing to registers for an nRF24 or an RFM69 or a LoRa chip.


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    But how exactly does one read or write to these registers? It looks like a quite different arrangement than writing to registers for an nRF24 or an RFM69 or a LoRa chip.

    You have to include nrf.h. To disable the radio, you can do this:

    https://github.com/mysensors/MySensors/blob/development/drivers/NRF5/Radio_ESB.cpp#L264

    If your transmitting power is 0dbm, then "TX only run current PRF = 0dBm" with 11.6 mA is near the calculated current, when the radio stays in TX mode after sending the data.


  • Hero Member

    @d00616
    Will this block of code guarantee that the radio is disabled?

      Serial.println("Testing whether radio is disabled...");
      Serial.print("NRF_RADIO->EVENTS_DISABLED=");
      Serial.println(NRF_RADIO->EVENTS_DISABLED);
      while (!(NRF_RADIO->EVENTS_DISABLED)) {
        Serial.print("NRF_RADIO->EVENTS_DISABLED=");
        Serial.println(NRF_RADIO->EVENTS_DISABLED);
        NRF_RADIO->TASKS_DISABLE = 1;  //sleep the radio
      }
      Serial.println("Radio disabled.");
    

  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    Will this block of code guarantee that the radio is disabled?

    This one is better:

    if (NRF_RADIO->STATE != RADIO_STATE_STATE_Disabled) {
    	NRF_RADIO->TASKS_DISABLE = 1;
    }

  • Contest Winner

    @rmtucker said in nRF5 Bluetooth action!:

    Yes being able to change the prescaler dynamically would help a great deal as 125ms / 582.542 hours is not really useful for most applications with a 250ms overrun.

    The sleep() function is now more precise for sleeping <512s:

    https://github.com/mysensors/MySensors/pull/909

    The PR is waiting for merge.


  • Hero Member

    @d00616
    That works. Thanks!

    What's the best way to awaken the radio after sleeping it though? I've tried:

        NRF_RADIO->TASKS_START  = 1;  //awaken the radio
    

    and

        NRF_RADIO->TASKS_TXEN  = 1;  //awaken the radio
    

    and neither seems to have an effect. The radio stays disabled.


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    What's the best way to awaken the radio after sleeping it though? I've tried:

    This depends on the implementation. Sorry, at the moment I have not time to look into the RadioHead code in that detail. You can try to initialize the library again.


  • Contest Winner

    @NeverDie Here is a snippet to dump all registers, hope it's help to analyze whats going wrong with RadioHead:

    Serial.print("NRF_RADIO->EVENTS_READY  ");
    Serial.println(NRF_RADIO->EVENTS_READY, HEX);
    Serial.print("NRF_RADIO->EVENTS_ADDRESS  ");
    Serial.println(NRF_RADIO->EVENTS_ADDRESS, HEX);
    Serial.print("NRF_RADIO->EVENTS_PAYLOAD  ");
    Serial.println(NRF_RADIO->EVENTS_PAYLOAD, HEX);
    Serial.print("NRF_RADIO->EVENTS_END  ");
    Serial.println(NRF_RADIO->EVENTS_END, HEX);
    Serial.print("NRF_RADIO->EVENTS_DISABLED  ");
    Serial.println(NRF_RADIO->EVENTS_DISABLED, HEX);
    Serial.print("NRF_RADIO->EVENTS_DEVMATCH  ");
    Serial.println(NRF_RADIO->EVENTS_DEVMATCH, HEX);
    Serial.print("NRF_RADIO->EVENTS_DEVMISS  ");
    Serial.println(NRF_RADIO->EVENTS_DEVMISS, HEX);
    Serial.print("NRF_RADIO->EVENTS_RSSIEND  ");
    Serial.println(NRF_RADIO->EVENTS_RSSIEND, HEX);
    Serial.print("NRF_RADIO->EVENTS_BCMATCH  ");
    Serial.println(NRF_RADIO->EVENTS_BCMATCH, HEX);
    Serial.print("NRF_RADIO->CRCSTATUS  ");
    Serial.println(NRF_RADIO->CRCSTATUS, HEX);
    Serial.print("NRF_RADIO->RXMATCH  ");
    Serial.println(NRF_RADIO->RXMATCH, HEX);
    Serial.print("NRF_RADIO->RXCRC  ");
    Serial.println(NRF_RADIO->RXCRC, HEX);
    Serial.print("NRF_RADIO->DAI  ");
    Serial.println(NRF_RADIO->DAI, HEX);
    Serial.print("NRF_RADIO->PACKETPTR  ");
    Serial.println(NRF_RADIO->PACKETPTR, HEX);
    Serial.print("NRF_RADIO->FREQUENCY  ");
    Serial.println(NRF_RADIO->FREQUENCY, HEX);
    Serial.print("NRF_RADIO->TXPOWER  ");
    Serial.println(NRF_RADIO->TXPOWER, HEX);
    Serial.print("NRF_RADIO->MODE  ");
    Serial.println(NRF_RADIO->MODE, HEX);
    Serial.print("NRF_RADIO->PCNF0  ");
    Serial.println(NRF_RADIO->PCNF0, HEX);
    Serial.print("NRF_RADIO->PCNF1  ");
    Serial.println(NRF_RADIO->PCNF1, HEX);
    Serial.print("NRF_RADIO->BASE0  ");
    Serial.println(NRF_RADIO->BASE0, HEX);
    Serial.print("NRF_RADIO->BASE1  ");
    Serial.println(NRF_RADIO->BASE1, HEX);
    Serial.print("NRF_RADIO->PREFIX0  ");
    Serial.println(NRF_RADIO->PREFIX0, HEX);
    Serial.print("NRF_RADIO->PREFIX1  ");
    Serial.println(NRF_RADIO->PREFIX1, HEX);
    Serial.print("NRF_RADIO->TXADDRESS  ");
    Serial.println(NRF_RADIO->TXADDRESS, HEX);
    Serial.print("NRF_RADIO->RXADDRESSES  ");
    Serial.println(NRF_RADIO->RXADDRESSES, HEX);
    Serial.print("NRF_RADIO->CRCCNF  ");
    Serial.println(NRF_RADIO->CRCCNF, HEX);
    Serial.print("NRF_RADIO->SHORTS  ");
    Serial.println(NRF_RADIO->SHORTS, HEX);
    

  • Hero Member

    @d00616
    I did a bit more poking around, and I've confirmed that there's no need to re-enable the radio before transmitting. Apparently doing the transmission and returning to disabled mode happens automatically. In fact, I think this is the expected behavior, as indicated by Figure 35 of the datasheet.


  • Hero Member

    So, under this theory, the only time when the radio is not disabled is when it is actively transmitting or receiving. There's no need to manually disable it, because that appears to happen automatically anyway.


  • Hero Member

    So, to move forward with this, I took a super-stripped down nRF52832, and loaded it with a super stripped down sketch that never initializes the radio and pretty much just jumps directly into a long RTC 12 hour slumber using the MySensors sleep routine. Measuring the current drawn while in that slumber using a uCurrent Gold, I'm reading about 9.3ua. So, to confirm that, I'm running the same stripped down setup from a 10F supercap, and I'll see at what rate the supercap voltage drops with time, and whether that appears to agree or not with these initial measurements.

    Hopefully the current draw will remain low, and there will be no surprises. In that case, I'll add stuff back in until I find the culprit that was previously causing the higher current draw.



  • @NeverDie
    I can not understand why you are drawing 9.4uA in the first place?.
    My nrf51822 seems to consistently only draw 4-5uA with no strip down of software when in mysensors sleep mode.
    Fair enough i have not got your measurement equipment but i don,t see it being that far away.
    The data sheets seem to point to under 5uA.


  • Hero Member

    @rmtucker said in nRF5 Bluetooth action!:

    I can not understand why you are drawing 9.4uA in the first place?.

    Yes, it is puzzling. I don't have a good answer as to why it measures so high. Maybe the crystal oscillator? What else is there that might be causing it?


  • Hero Member

    After this initial run completes, I'll try reprogramming it to use the internal resonnator instead and see if that makes any difference.


  • Hero Member

    Indeed, reprogramming the Ebyte nRF52832 to use the internal oscillator dropped the sleep current consumption down to 5.4ua. 🙂

    I wonder whether physically removing the crystal oscillator would result in additional savings, or if that's as low as it goes?

    I also wonder whether the datasheet cheats a bit by not counting the current consumed by the external crystal oscillator when that's being used? Otherwise, I don't see how Nordic can claim a <2ua sleep current for the nRF52832.



  • @NeverDie

    Stranger still my 4-5uA is using the external crystal??.


  • Hero Member

    I have to amend what I just said, because I took a measurement short-cut that in retrospect I shouldn't have: namely, I did the measurements on two different modules.

    I went back and changed the 5.4ua module using the RC internal oscillator to use the external crystal oscillator, and it measures about the same.

    So... The difference I was reading was a difference in the way the two modules measure. I'm not sure why one reads higher than the other, except perhaps that I didn't clean the solder flux off the higher reading module, and I did clean off the solder flux on the lower reading module.

    I'll try cleaning the solder flux off the higher reading module and see if that drops the current consumed.


  • Hero Member

    I cleaned off the solder flux and... no real difference. Go figure. Maybe it's just random variation among the Ebyte Modules? I guess I'll have to wire up more of them and see how they all compare.


  • Hardware Contributor

    @NeverDie did you select the option with internal crystal ? 1s accuracy after 12h like you said before sounds more like a precise external crystal than an internal one.


  • Hero Member

    @Nca78 said in nRF5 Bluetooth action!:

    @NeverDie did you select the option with internal crystal ? 1s accuracy after 12h like you said before sounds more like a precise external crystal than an internal one.

    Up until today I was using just the external crystal on the Ebyte nRF52832's. It was only for comparison purposes of current consumption that today I switched to the internal resonator. It's about the same current consumption. Maybe if I now remove the external crystal, it will save some current? I just don't know.


  • Contest Winner

    @rmtucker said in nRF5 Bluetooth action!:

    I can not understand why you are drawing 9.4uA in the first place?.
    My nrf51822 seems to consistently only draw 4-5uA with no strip down of software when in mysensors sleep mode.

    While developing the nRF5 port, I had no chance to measure the current of the nRF52 accurate. With my original nRF51 dev kit I I have a sleeping current matching the data sheet.

    Now I can measure currents in the µA range. With all nRF52 I have, I measured sleeping currents around 10µA. This is to much. We have to see 2-3µA. I have no original nRF52832 dev kit to compare. The reason of this sleeping current can be either an error in the layout or there is a component which is not required in active state while sleeping.

    At the moment I have no time to analyse this. There is a bug in the radio code, which I have to fix. When transport debug is disabled no packages are received. In my opinion this has more priority.


  • Contest Winner

    @NeverDie Just my two cents. Leakage current through non ideal capacitors can be 1-10uA.


  • Hero Member

    @NeverDie said in nRF5 Bluetooth action!:

    So, to move forward with this, I took a super-stripped down nRF52832, and loaded it with a super stripped down sketch that never initializes the radio and pretty much just jumps directly into a long RTC 12 hour slumber using the MySensors sleep routine. Measuring the current drawn while in that slumber using a uCurrent Gold, I'm reading about 9.3ua. So, to confirm that, I'm running the same stripped down setup from a 10F supercap, and I'll see at what rate the supercap voltage drops with time, and whether that appears to agree or not with these initial measurements.

    Hopefully the current draw will remain low, and there will be no surprises. In that case, I'll add stuff back in until I find the culprit that was previously causing the higher current draw.

    It turns out that the culprit was the mere act of using pinmode to designate a pin as an input pin, even if it's not connected to anything. Then, during sleep, the current consumption is an order of magnitude higher. This is quite different behavior than on, say, an Arduino pro mini, where the input pins are high impedance and there's neglible current draw.

    Not sure what to do about it though. Any ideas?


  • Hero Member

    The same sort of thing happens if pinmode is used to designate a pin as an output pin--again, even if nothing is connected to it.

    This is a potential show stopper. This module is useless to me if I can't connect it to anything.

    As a workaround, is there some way to designate a pin as undefined again after having used pinmode to define it as either an input pin or an output pin?


  • Hero Member

    Well, setting the pinmode to OUTPUT and then digitalwriting it to LOW seems to help considerably--at least when it's not connected to anything.

    [Edit: Setting it to HIGH also helps similarly.]


  • Hero Member

    Anyhow, I'm relieved that the radio isn't the source of these power drain problems. This pinmode stuff is a bummer, but it looks like I can at least partially work around it.


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    Well, setting the pinmode to OUTPUT and then digitalwriting it to LOW seems to help considerably--at least when it's not connected to anything.
    [Edit: Setting it to HIGH also helps similarly.]

    Thank's. I check this after I fixed the Radio.

    Actually, I have this board running. I measure a voltage of 0.13mV=6,6µA at the shunt with a simple sleep sketch. When I switch two pins into INPUT_PULLUP, then I measure 0.15mV==7,5µA.

    When I switch on the LED then I measure 12.75mV == 0,6375mA, One pin in OUTPUT_H1H0 mode. With LED off I measure 0.15mV==7,5µA.

    My MCU is nRF52832 QFAAB0 1615AX

    P.S.: I have no documentation about the board. When I measure the boards current, then I have an shunt factor of 22,5. I think calculating with 20 is ok.


  • Hero Member


  • Hardware Contributor

    in that case, you need to set it as a floating input i think, like it's generally at reset.
    In datasheet, section 20 (p111), is explained how works the GPIO. You have a Bit for disconnecting it. See the PIN_CNF[n] registers. For instance, p.140, you can see how it looks for the P0.10, and the Bit 1.
    This should do the job..


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    Thanks! I just now ordered one of your boards so that in the future we can share a common platform for comparing numbers.

    Ok. I have measured my Ebyte with the same sketch and in the µA range of my VC165 multimeter. Sleep current is 9.9µA with two ports in INPUT_PULLUP and one Port in OUTPUT_H0H1 mode. (b.t.w. this module costs actually 3,82€)

    @scalz said in nRF5 Bluetooth action!:

    in that case, you need to set it as a floating input i think, like it's generally at reset.
    In datasheet, section 20 (p111), is explained how works the GPIO. You have a Bit for disconnecting it. See the PIN_CNF[n] registers. For instance, p.140, you can see how it looks for the P0.10, and the Bit 1.
    This should do the job..

    Should I add a DISCONNECTED mode to hwPinMode()?


  • Hero Member

    @d00616 said in nRF5 Bluetooth action!:

    Sleep current is 9.9µA with two ports in INPUT_PULLUP and one Port in OUTPUT_H0H1 mode....

    Ah, maybe that's part of the difference. I was doing just:

    pinMode(ALPHA_PIN, INPUT)
    pinMode(BETA_PIN, OUTPUT)
    

    because that's how I would have done it on an Arduino. Should we instead always use INPUT_PULLUP and OUTPUT_H0H1 instead?



  • @NeverDie
    Should be

    hwPinMode(DIGITAL_INPUT_SENSOR, INPUT_PULLUP);
    

    According to NRF5 platform


  • Hero Member

    Thanks! Somehow didn't remember that.

    So, as suggested by @scalz what is some example code that can be used to "disconnect" the pin later?



  • @NeverDie
    He has not added that facility yet,i think he asked you if you wanted it adding to the code?


  • Hero Member

    @rmtucker said in nRF5 Bluetooth action!:

    if you wanted it adding to the code?

    Definitely!


  • Hardware Contributor

    for unused pins, it should be floating, not pullup. set the pin register you need to 0x02.
    Something like that
    NRF_GPIO->PIN_CNF[ulPin] = 0x02;
    that will put pin in same state like it's on reset. Everything disabled/default, floating, with disconnect bit set.
    (see datasheet gpio).

    @d00616 said in nRF5 Bluetooth action!:

    Should I add a DISCONNECTED mode to hwPinMode()?

    make sense to have it for input too.. i agree :simple_smile:


  • Hero Member

    Maybe add:
    OUTPUT_D0D1 -> Disconnected 0, Disconnected 1
    or similar to your list as another easy way to effectuate the disconnect?


  • Hero Member

    It finally makes sense now as to why there were all those "disconnected" choices among the various OUTPUT options. In my case, for controlling whether the solar panel is connected or disconnected, choosing OUTPUT_S0D1 works perfectly. 🙂

    So, I suppose another way to disconnect an input pin would be to redefine it as an OUTPUT pin with a disconnect state, and then immediately put it into the disconnected state.



  • @d00616 said in nRF5 Bluetooth action!:

    @rmtucker said in nRF5 Bluetooth action!:

    Yes being able to change the prescaler dynamically would help a great deal as 125ms / 582.542 hours is not really useful for most applications with a 250ms overrun.

    The sleep() function is now more precise for sleeping <512s:

    https://github.com/mysensors/MySensors/pull/909

    The PR is waiting for merge.

    Hmm just tried the latest commit and it is giving me 306ms for sleep(10000).
    Something not quite right.


  • Hero Member

    @rmtucker
    How are you measuring how long it's sleeping?



  • @NeverDie said in nRF5 Bluetooth action!:

    @rmtucker
    How are you measuring how long it's sleeping?

    Just using hwMillis() before and after sleep and subtracting one from the other.
    It was just reading + 250ms until @d00616 commited some changes a few hours ago.



  • something wrong in here:-

    // Calculate sleep time and prescaler
    		if (ms<512000) {
    			// prescaler 0, 30.517 μs resolution -> max 512 s sleep
    			MY_HW_RTC->PRESCALER =  0;
    			// Set compare register to 1/30.517 µs to garantee event triggering
    			// A minimum of 2 ticks must be guaranteed
    			// (1000/32768)<<12 == 125
    			MY_HW_RTC->CC[0] = max((ms<<12 / 125), 2);
    		} else {
    			// 8 Hz -> max 582.542 hours sleep.
    			MY_HW_RTC->PRESCALER = 4095;
    			// Set compare register to 1/125ms
    			// A minimum of 2 ticks must be guaranteed
    			MY_HW_RTC->CC[0] = max((ms / 125), 2);
    		}
    

  • Hero Member

    @rmtucker said in nRF5 Bluetooth action!:

    @NeverDie said in nRF5 Bluetooth action!:

    @rmtucker
    How are you measuring how long it's sleeping?

    Just using hwMillis() before and after sleep and subtracting one from the other.
    It was just reading + 250ms until @d00616 commited some changes a few hours ago.

    I thought so. The point being: doesn't millis stop when you're deep sleeping? Well, at least on an Arduino it does. Not sure what it does on the nRF5.



  • @NeverDie
    No the nrf5 has a rtc.(Real time Counter)
    It can even keep time while sleeping.(just found this out myself!).
    That is a great leap forward on the arduino.



  • Try it just print the time out then put it to sleep for a minute then print the time out again.



  • The problem must be this line but i don't speak nrf5.😦

    			// (1000/32768)<<12 == 125
    			MY_HW_RTC->CC[0] = max((ms<<12 / 125), 2);```


  • The only other thing it could be is the deletion of this line in the commit.

    
    nrf5_rtc_event_triggered = false 
    


  • @d00616

    MY_HW_RTC->CC[0] = max((ms<<12 / 125), 2);

    Should be:-

    MY_HW_RTC->CC[0] = max(((ms << 12) / 125), 2));



  • @d00616

    Just checked and it now returns 10002 for a sleep(10000).
    Much better after the above alteration.


  • Hero Member

    Epilog: I made the changes so that just prior to taking a measurement the sense pin is hwPinMode'd to an input pin, and then immediately after the measurement I disconnect it. Seems to be working, and without the usurious power drain I was experiencing previously. 🙂



  • @NeverDie said in nRF5 Bluetooth action!:

    Epilog: I made the changes so that just prior to taking a measurement the sense pin is hwPinMode'd to an input pin, and then immediately after the measurement I disconnect it. Seems to be working, and without the usurious power drain I was experiencing previously. 🙂

    Good news
    So what is the current usage now when sleeping?


  • Hero Member

    @rmtucker said in nRF5 Bluetooth action!:

    @NeverDie said in nRF5 Bluetooth action!:

    Epilog: I made the changes so that just prior to taking a measurement the sense pin is hwPinMode'd to an input pin, and then immediately after the measurement I disconnect it. Seems to be working, and without the usurious power drain I was experiencing previously. 🙂

    Good news
    So what is the current usage now when sleeping?

    About 6ua on this particular Ebyte nRF52832. I'm pretty sure it would be higher on my other Ebyte nRF52832, though I haven't measured it again. Haven't tested any additional ones as of yet.


  • Mod

    @rmtucker very nice work, thanks for locating the problem.

    It occurs because 12/125 will be evaluated before the bit shift. http://en.cppreference.com/w/c/language/operator_precedence for details.


  • Contest Winner

    @rmtucker said in nRF5 Bluetooth action!:

    MY_HW_RTC->CC[0] = max((ms<<12 / 125), 2);
    Should be:-
    MY_HW_RTC->CC[0] = max(((ms << 12) / 125), 2));

    Thank you. This was the result of merging some commits. I haven't seen I reversed that change. I had tested the code before merging some commits into one.

    Actually I check the result of sleep(511999) and sleep(512001). When it's finished I fix that in MySensors.


  • Contest Winner

    @scalz said in nRF5 Bluetooth action!:

    @d00616 said in nRF5 Bluetooth action!:

    Should I add a DISCONNECTED mode to hwPinMode()?

    make sense to have it for input too.. i agree

    What's the best name for this mode? DISCONNECTED or INPUT_DISCONNECTED. I prefer the first variant.

    I have to play a little bit with the port modes. Maybe it saves some current when the serial port pins are put into the disconnected mode while sleeping.


  • Contest Winner

    @d00616 said in nRF5 Bluetooth action!:

    Actually I check the result of sleep(511999) and sleep(512001). When it's finished I fix that in MySensors.

    Is fixed in development branch.
    https://github.com/mysensors/MySensors/pull/917


  • Hardware Contributor

    @d00616 said in nRF5 Bluetooth action!:

    @scalz said in nRF5 Bluetooth action!:

    @d00616 said in nRF5 Bluetooth action!:

    Should I add a DISCONNECTED mode to hwPinMode()?

    make sense to have it for input too.. i agree

    What's the best name for this mode? DISCONNECTED or INPUT_DISCONNECTED. I prefer the first variant.

    I have to play a little bit with the port modes. Maybe it saves some current when the serial port pins are put into the disconnected mode while sleeping.

    agree too for the first one should be enough :simple_smile:
    yes, for lower power consumption, better disconnect pins which are not needed.
    it's the same for a simple 328p though (setting the right pin states).


  • Hero Member

    As a follow-up to rmtucker's line of inquiry, what is currently the shortest deep sleep that's supported? Is it one millisecond, or something else?



  • @NeverDie
    Theoretically it is 2 clock ticks at 32768khz so 0.000061035secs i think.
    But how long it takes to go into sleep mode and come out of sleep mode i am not sure.
    But of course the sleep function only allows millis.


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    As a follow-up to rmtucker's line of inquiry, what is currently the shortest deep sleep that's supported? Is it one millisecond, or something else?

    Why do you need this type of short sleeps?

    Sleep is for battery powered devices. A device that wakes up more than 1000 times in the second might be hard to drive with a battery.

    @rmtucker said in nRF5 Bluetooth action!:

    @NeverDie
    Theoretically it is 2 clock ticks at 32768khz so 0.000061035secs i think.

    This is correct.

    But how long it takes to go into sleep mode and come out of sleep mode i am not sure.

    It's simple to evaluate with micros() before and after a sleep().


  • Hero Member

    I haven't yet upgraded to the current version, so maybe this is moot (?), but the following code in a loop:

      digitalWrite(TEST_PIN,HIGH);
      sleep(100); // Sleeps for 100ms
      digitalWrite(TEST_PIN,LOW);
      sleep(100); // Sleeps for 100ms 
    

    holds the TEST_PIN first HIGH for 250ms and then LOW for 250ms. That means 150ms of sleep overhead, which seems like a lot.

    I measured the length of time the TEST_PIN is HIGH or LOW using an oscilloscope. Ran it on an Ebyte nRF52832.


  • Hero Member

    Nevermind. I just now upgraded to the current versions, and it seems to be fixed.


  • Hero Member

    So, with the current libraries and an Ebyte nRF52832 that's using its external crystal oscillator, I'm now measuring the sleep overhead as being 260us. I expect that may be even less if using the internal 32768Hz resonator.


  • Hero Member

    I tried measuring the sleep overhead with the Ebyte nRF52832 running on its internal resonator, and surprisingly it wasn't that much faster: it appears to be about 220us.

    Here's the test script:

    #include <MySensors.h>
    
    #define TEST_PIN 19  // (P0.19) 
    
    void setup() 
    {
      hwPinMode(TEST_PIN, OUTPUT_H0H1);  
      digitalWrite(TEST_PIN, LOW);  
    }
    
    void loop() {
      digitalWrite(TEST_PIN,HIGH);
      sleep(1); // Sleeps for 1ms
      digitalWrite(TEST_PIN,LOW);
      sleep(1); // Sleeps for 1ms  
    }
    

    Here's the scope capture:
    0_1504148461469_NewFile1.jpg

    Of course, this assumes (?) that the mcu sleeps for exactly 1ms, and during the extra 220us it is either ramping down or ramping up.

    BTW, I don't anticipate sleeping for a mere 1ms at a time. However, to get a good measurement of the overhead using the oscilliscope I had to set the sleep period that low.

    I can, however, well imagine having a use for sleep periods lasting 100ms.


  • Hero Member

    Anyhow, it's not academic, as the plan is to approximate the "listen-mode" of an RFM69, but using the nRF52832. For that to be power efficient, I need the mcu to wake-up and fall-asleep very, very fast. For comparison, an atmega328p can wake-up in 3.8usec.

    On page of the nRF52832 datasheet, it advertises:

    Fast wake-up using 64 MHz internal oscillator

    However, I'm not sure how to set that up. There's no menu check-box for that on the Arduino IDE tools menu like there is for the 32768Hz internal resonator. On the other hand, I'm not sure that it matters, because apparently the 64Mhz external crystal, which is what's slowing down the wake-up, is required to operate the radio.


  • Hero Member

    Here's the current drain through a 1-ohm resistor:
    0_1504182375553_NewFile2.jpg
    i.e. 1mv=1ma.

    As you can see, there's a rather long tail before it finally falls asleep.

    Here is the same, but superimposed onto the TEST_PIN capture:
    0_1504182439451_NewFile3.jpg


  • Hero Member

    Good news. It appears that DCDC is already implemented on the Ebyte nRF52832 and working automatically!

    Just for grins, I decided to measure the Tx time and current draw from sending a 13 byte payload in a packet, and I was happily surprised to see how low the current draw was:
    0_1504186181522_NewFile4.jpg

    The yellow trace marks the start and stop of the packet transmission process from a software point of view, but the blue trace measures the current (as before 1mv=1ma). As you can see, the transmission current never seems to rise above 2.5ma. The only (?) explanation I can think of is that DCDC must be working. Right? Tx power is set to be 4dbm.

    It would be great if someone else would confirm/refute the measurement.


  • Hardware Contributor

    @NeverDie said in nRF5 Bluetooth action!:

    It would be great if someone else would confirm/refute the measurement.

    I don't think it's possible, from the datasheet peak current is 7.7mA at +4dB with DCDC enabled with 3V power supply.
    Current gain from 3V=>1.7V DCDC conversion is already included in this measurement so you should not be able to go lower.

    How did you make your measurement across the resistor ?


  • Hero Member

    @Nca78
    You're right. It didn't ring true, so I setup some different capture hardware, and this time the image is a lot crisper:
    0_1504198507583_NewFile5.jpg
    This time I powered it from a 3.3v supercap and with the 1 ohm resistor soldered securely onto a PCB, with the o-scope leads on either side of it.

    So, sadly, it doesn't look DCDC after all, because on this capture the peak is exceeding 20ma. 😞

    It's interesting how lengthy (and energy intensive) the phase is that's just prior to the transmission itself. I presume that's mainly just the PLL coming up to speed? It looks as though the actual current expended in the prelude exceeds that of the actual Tx proper!

    I'm guessing that in the earlier scope capture, the probe must have slipped into 10x mode, because the shape is similar, just proportionately reduced by roughly that factor.


  • Hero Member

    BTW, I assembled my third board now, and it sleeps at about 9.9ua. The first one sleeps at about 6ua, and the second at about 9ua. It would be interesting to know why the first board is so much less, but it seems that about 9-10ua is the more typical number. That also seems to agree with @d00616 's measurements.


  • Hero Member

    Interestingly enough, you can put the radio into receive mode and then sleep the mcu with the radio still in receive mode. Here's a screenshot of current consumption while receiving, where I alternate between leaving the mcu active or sleeping it (each for duration of 500ms). In-between, I sleep everything (both radio and mcu) for 1 second:
    0_1504213277663_NewFile7.jpg


  • Hero Member

    Here's the mode that I'm most interested in: Putting the radio into Rx for about 1ms per 100ms interval to listen for remote commands. The rest of the time everthing (both radio and mcu) are in deep sleep waiting for the RTC to wake them up.

    Here's a close-up of the current drawn during that roughly 1ms interval:
    0_1504214970391_NewFile8.jpg

    I ran this just now, and my solar setup can easily handle this load during the daytime, even from deep indoors far from the windows. This was the scenario that really stressed the RFM69+atmega328p combo when I tried doing it using the RFM69's listen mode. I'll see tonight how the 10F supercap handles the load without any solar assist. 🙂

    Because of the nRF52839's 2Mbps datarate, I can probably cut the listen window down substantially from 1ms to much less (much less than would be possible with an RFM69, due to its maximum of 300kbps datarate), but for ease of programming I'm starting with this.


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    Here's the mode that I'm most interested in: Putting the radio into Rx for about 1ms per 100ms interval to listen for remote commands. The rest of the time everthing (both radio and mcu) are in deep sleep waiting for the RTC to wake them up.

    When you take a look into the PPI section, you are able to let the CPU sleep until a radio packet is received. With PPI, the listen mode can be activated and deactivated without CPU interaction.

    The nRF5 MCUs are able to to a lot of things without waking up the CPU. That's a really cool feature.


  • Hero Member

    @d00616 said in nRF5 Bluetooth action!:

    @NeverDie said in nRF5 Bluetooth action!:

    Here's the mode that I'm most interested in: Putting the radio into Rx for about 1ms per 100ms interval to listen for remote commands. The rest of the time everthing (both radio and mcu) are in deep sleep waiting for the RTC to wake them up.

    When you take a look into the PPI section, you are able to let the CPU sleep until a radio packet is received. With PPI, the listen mode can be activated and deactivated without CPU interaction.

    The nRF5 MCUs are able to to a lot of things without waking up the CPU. That's a really cool feature.

    Sounds like it has potential. Any demo code for this? The datasheet seems a bit sketchy.


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    @d00616 said in nRF5 Bluetooth action!:

    @NeverDie said in nRF5 Bluetooth action!:

    Here's the mode that I'm most interested in: Putting the radio into Rx for about 1ms per 100ms interval to listen for remote commands. The rest of the time everthing (both radio and mcu) are in deep sleep waiting for the RTC to wake them up.

    When you take a look into the PPI section, you are able to let the CPU sleep until a radio packet is received. With PPI, the listen mode can be activated and deactivated without CPU interaction.
    The nRF5 MCUs are able to to a lot of things without waking up the CPU. That's a really cool feature.

    Sounds like it has potential. Any demo code for this? The datasheet seems a bit sketchy.

    These are some snippets of the radio code. There are fully useable PPI and some predefined. For fully useable PPI into the EEP register, you put the address of an EVENT register and in the TEP register, you put the pointer to an TASK register.

       /** Configure PPI (Programmable peripheral interconnect) */
        // Start timer on END event
        NRF_PPI->CH[NRF5_ESB_PPI_TIMER_START].EEP = (uint32_t)&NRF_RADIO->EVENTS_END;
        NRF_PPI->CH[NRF5_ESB_PPI_TIMER_START].TEP = (uint32_t)&NRF5_RADIO_TIMER->TASKS_START;
        // Disable Radio after CC[0]
        NRF_PPI->CH[NRF5_ESB_PPI_TIMER_RADIO_DISABLE].EEP = (uint32_t)&NRF5_RADIO_TIMER->EVENTS_COMPARE[0];
        NRF_PPI->CH[NRF5_ESB_PPI_TIMER_RADIO_DISABLE].TEP = (uint32_t)&NRF_RADIO->TASKS_DISABLE;
        ...
        // Set PPI
         NRF_PPI->CHENSET = NRF5_ESB_PPI_BITS;
        ...
      // Clear PPI
        NRF_PPI->CHENCLR = NRF5_ESB_PPI_BITS;
    

    Then you have to enable or disable the register. It could be necessary to reset the events. You can use the NRF_RESET_EVENT macro to do this job.

     NRF_RESET_EVENT(NRF5_RADIO_TIMER->EVENTS_COMPARE[0]);

  • Hero Member

    I have a brute force version of "listen mode" working using just the libraries, but I have to re-initialize the radio after each cycle because it appears to lose its settings every time I sleep it.

    Anyway, finding a way to add DCDC mode to these modules will probably have the biggest near-term impact on current consumption. That said, I'm sure plenty of energy savings can also be found by honing the code.


  • Hero Member

    Actually, even just sleeping the MCU with a simple command like:

    sleep(100);
    

    is apparently enough to require a re-init of the radio afterward. Not sure why that would be.


  • Hero Member

    Comparing Figures 169 and 170 in the nRF52832 datasheet, it looks as though simply adding two inductors in series between DCC and DEC4 should be all that's needed to provide the needed hardware support for DC/DC. Looks as though the 10uH inductor also needs to be able to support a minimum of 50ma, according to the BOM (Table 145).

    So, is it as simple as that together with enabling register DCDCEN? Or, is there anything more to it?


  • Hardware Contributor

    Yes. This is like that. I use 2 inductors (better) in serie. Why more complicated 😉


  • Contest Winner

    @NeverDie said in nRF5 Bluetooth action!:

    Actually, even just sleeping the MCU with a simple command like:
    sleep(100);

    is apparently enough to require a re-init of the radio afterward. Not sure why that would be.

    sleep() deinitializes the transport with transportDisable(). This results in power down the radio.

    At the moment I review the ESB code. I think the nRF5 is 12-13µs after an nRF24 in RX mode and 432µs before an nRF24 in TX. This can result in unstable connections when debug messages are disabled.


Log in to reply
 

Suggested Topics

  • 8
  • 90
  • 1
  • 3
  • 44
  • 5

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts