Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - anton

Pages: [1]
1
As described in http://forum.rfduino.com/index.php?topic=801.0 we can use Lazarus Library to wake from ULPDelay(INFINITE) in loop(). In case we have two Pins - Lazarus 31 and a real one (let say buttonA=5), Lazarus wake up is only possible, if pin 5 is LOW. But if we hold the button pressed (signal is HIGH), Lazarus doesn't work.
There was also a commed in the first example:

Quote
  // Note if using RGB shield where buttons pullup and resistors pulldown OK. But
  // if you run without the board installed then better have pulldowns on CPU board.
  // Also PinWake will lock up if buttons get stuck on. So make sure input trigger
  // signals always return to normal. 

Why can't we reset after pinWoke on pin 5 in a way, that pinWoke on pin 31 (Lazarus pin) is possible, even during pin 5 remains HIGH?

See below the example I modified to produce the situation. Just press buttonA on RGB shield an hold on. ariseLazurus(); won't wake the ULPDelay(INFINITE) until we release buttonA.

Code: [Select]
/*
*
*  http://forum.rfduino.com/index.php?topic=801.0
*
*/

#include <RFduinoBLE.h>
#include "SPI.h"
#include "SD.h"

#define LazarusPin 31

#define SERIAL

// ISR red mark
const int ButtonA_pin = 5;
int start_time=0;
int end_time=0;
int state = HIGH;

int btnA_ISR(uint32_t ulPin)
{
    end_time = millis();

#ifdef SERIAL
    Serial.print("ISR ");
    Serial.print(ulPin);
    Serial.println(" called");
#endif
    return 1;  // 0 don't exit RFduino_ULPDelay, 1 exit RFduino_ULPDelay
}

void setup() {
  Serial.begin(9600);
 
  pinMode(6, OUTPUT);
 
  RFduinoBLE.deviceName = "BLE_LZRS";
  RFduinoBLE.advertisementData = "Lazurus Test";
  RFduinoBLE.begin();

  pinMode(ButtonA_pin, INPUT);
  RFduino_pinWakeCallback(ButtonA_pin, HIGH, btnA_ISR);
//  RFduino_pinWakeCallback(ButtonA_pin, LOW, btnA_ISR);

  delay(1500);
  Serial.print("setup(): Default: ");
  printL();
  pinMode(LazarusPin,INPUT_PULLDOWN);
  Serial.print("setup(): pinMode to input pulldown: ");
  printL();
  NRF_GPIO->PIN_CNF[LazarusPin] =
      (GPIO_PIN_CNF_PULL_Pulldown<<GPIO_PIN_CNF_PULL_Pos);
  Serial.print("setup(): pulldown ");
  printL(); 

// As long as pinWake is included in the ariseLazarus function... not needed here.
// Uncomment if you wish to see.
//  RFduino_pinWake(LazarusPin,HIGH);
//  Serial.print("setup(): post pinWake HIGH: ");
//  printL();
}

void loop() {
  int diff = 0;

  Serial.println("main loop() going to sleep forever");
  RFduinoBLE_ULPDelay(INFINITE);
  if(lazarusArising()){
    Serial.println("Lazarus has awakened!");
    printL();
    Serial.println("");
    delay(5000); //just waste some time
    Serial.println("Lazarus exit!");
  }
  if (RFduino_pinWoke(ButtonA_pin)) {
    RFduino_resetPinWake(ButtonA_pin);
    RFduino_pinWakeCallback(ButtonA_pin, DISABLE, NULL);
    if (state == LOW) {
      RFduino_pinWakeCallback(ButtonA_pin, HIGH, btnA_ISR);
    } else {
      RFduino_pinWakeCallback(ButtonA_pin, LOW, btnA_ISR);
    }
    state = HIGH - state;
    RFduino_resetPinWake(ButtonA_pin);

    Serial.println("ButtonA has awakened!");
    printL();
    Serial.println("");
   
    delay(5000); //just waste some time
   
    diff = end_time - start_time;
    start_time = end_time;
   
    Serial.print("Differenz [ms]: ");
    Serial.println(diff);   
  }
 
  // Do whatever you have to do while are alive again!
  delay(100); //just waste some time
 
}

bool lazarusArising(){
  if(RFduino_pinWoke(LazarusPin)){
Serial.print("pinWoke Test: ");
printL();
    RFduino_resetPinWake(LazarusPin);
Serial.print("resetPinWake: ");
printL();
    return HIGH;
  }
  return LOW;
}

void ariseLazurus(){
  Serial.print("\n\nAttempting to Wake Lazarus from Infinite Sleep!  \n ");
 Serial.print("arise entry: ");
 printL();

// NOTE: SENSE and Connect not really needed. Just PULL and call to pinWake!
// Uncomment the extra PIN_CNF lines here and below to see..
    NRF_GPIO->PIN_CNF[LazarusPin] =
//        (GPIO_PIN_CNF_INPUT_Connect<<GPIO_PIN_CNF_INPUT_Pos) |
//        (GPIO_PIN_CNF_SENSE_High<<GPIO_PIN_CNF_SENSE_Pos) |
        (GPIO_PIN_CNF_PULL_Pullup<<GPIO_PIN_CNF_PULL_Pos);
 Serial.print("arise post pullup: ");
 printL();

  RFduino_pinWake(LazarusPin,HIGH);
  Serial.print("arise post pinWake: ");
 printL();

    NRF_GPIO->PIN_CNF[LazarusPin] =
//        (GPIO_PIN_CNF_INPUT_Connect<<GPIO_PIN_CNF_INPUT_Pos) |     
//        (GPIO_PIN_CNF_SENSE_High<<GPIO_PIN_CNF_SENSE_Pos) |
        (GPIO_PIN_CNF_PULL_Pulldown<<GPIO_PIN_CNF_PULL_Pos);
 Serial.print("arise post pulldown pre-exiting: ");
 printL();
}

void printL(){
  Serial.print("Lazarus PIN CNF: ");
   printVal(NRF_GPIO->PIN_CNF[LazarusPin]);
   Serial.println("");
}
void printVal(uint32_t val){
 printf("%02x %02x %02x %02x\n",val>>24 & 0xFF,val>>16&0xFF,val>>8&0xFF,val&0xFF);
}

void RFduinoBLE_onConnect() {
  Serial.println("Connected");
//  ariseLazurus();
}

void RFduinoBLE_onReceive(char *data, int len) {
  Serial.println("Received");
  ariseLazurus();
}

void RFduinoBLE_onDisconnect() {
  Serial.println("Disconnected");
}


I have an use case where a signal on a real pin changes to HIGH and remains for some seconds. I would like to receive and handle BLE commands during this time. I appreciate any suggestions, how to solve the issue!

Pages: [1]