Author Topic: Wake not working  (Read 288 times)

weroflu

  • RFduino Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Wake not working
« on: September 25, 2017, 01:18:00 AM »
I'm trying to implement Off and Wake functions sent from android bluetooth.

Everything in the following code works except for wake. When I put the rfduino to sleep with off it just disconnects from the bluetooth connection and that's the end.

Code: [Select]
#include <SPI.h>
#include <RFduinoBLE.h>

//#define SS    6u
//#define MOSI  4u
//#define MISO  3u
//#define SCK   5u
#define WK 2u


void setup() {
  // set the slaveSelectPin as an output:
  pinMode(SS, OUTPUT);
  pinMode(WK, INPUT);
  RFduino_pinWake(WK, HIGH);
   
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setFrequency(10000000);
 
  Serial.begin(9600);

  RFduinoBLE.advertisementInterval = 250;
  RFduinoBLE.deviceName = "rfduino"; 
  RFduinoBLE.txPowerLevel = -20;
 
  RFduinoBLE.begin();

//set zero crossing mode for each channel
  for (int i = 0; i < 6; i++)
  {
  SetMode(i,1);
  delay(100);
  }

}

void loop() {
 
RFduino_ULPDelay(INFINITE); 
 
if (RFduino_pinWoke(WK)) {
  Serial.println("wake");
  RFduino_resetPinWake(WK);
  }
 
}

int WriteGain(byte channel, byte value) {
  byte cmd = (channel * 32) + 16 + 2; //Command byte  A2 A1 A0 R/w R2 R1 R0 0
 
  // take the SS pin low to select the chip:
  digitalWrite(SS,LOW);
  //  send in the channel and value via SPI:
  SPI.transfer(cmd);
  SPI.transfer(value);
  // take the SS pin high to de-select the chip:
  digitalWrite(SS,HIGH);
}

int SetMode(byte channel, byte value) {
  byte cmd = (channel * 32) + 16 + 6; //Command byte  A2 A1 A0 R/w R2 R1 R0 0  Channel, 16=write, 6=Mode, write 0 for immediate, 1 for zero crossing
 
  // take the SS pin low to select the chip:
  digitalWrite(SS,LOW);
  //  send in the channel and value via SPI:
  SPI.transfer(cmd);
  SPI.transfer(value);
  // take the SS pin high to de-select the chip:
  digitalWrite(SS,HIGH);
}

int DisplayGain(byte channel) {
 
  byte cmd = (channel * 32) + 2; //Command byte  A2 A1 A0 R/w R2 R1 R0 0
 
  // take the SS pin low to select the chip:
  digitalWrite(SS,LOW);
  //  send in the channel and value via SPI:
  SPI.transfer(cmd);
  byte gain = SPI.transfer(0);
  // take the SS pin high to de-select the chip:
  digitalWrite(SS,HIGH);

  Serial.print(" Channel ");
  Serial.print(channel);
  Serial.print(" gain = ");
  Serial.print(gain);
 
  Serial.println();
   
}


void RFduinoBLE_onConnect()
{Serial.println("connected");
}

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

void RFduinoBLE_onReceive(char *data, int len)
{
 
String gString;
String chString;
String rString;

  for (int i=0;i<len;i++)
  {rString+=data[i];}
 
 chString = rString.substring(0,1);
 byte channel = byte(chString.toInt() - 1);
 
 gString = rString.substring(1,3);
 byte gain = byte(gString.toInt());

 
switch (rString.toInt()) {

case 999: //reset
{
 delay(400);
 RFduino_systemReset();
}
 break;

case 998: //off
{
 Serial.println("off");
 delay(200);
 RFduino_systemOff();
}
 break;

case 997: //wake
{
 Serial.println("wake");
 delay(200);
 digitalWrite(WK,HIGH);
}
 break;
 
default: //normal gain update
{
 WriteGain(channel,gain);
 delay(100);
 DisplayGain(channel);
}
break;
}

}


tolson

  • Global Moderator
  • *****
  • Posts: 870
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: Wake not working
« Reply #1 on: September 25, 2017, 01:43:26 PM »
For RFduino you may have to implement Lazarus.

http://forum.rfduino.com/index.php?topic=801.0

Actually, your problem may be that you are turning the RFduino OFF while you are in an interrupt callback. So the callback never gets a chance to unblock interrupts to be looking for new interrupts, so it never sees the pinwoke interrupt. See if you can scheme a method to set a flag that tells the loop to turn off system. And then it should start up from there.
« Last Edit: September 25, 2017, 01:50:35 PM by tolson »

weroflu

  • RFduino Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Wake not working
« Reply #2 on: October 24, 2017, 12:30:58 AM »
What is the difference between ulp mode and systemoff mode?

I'm working on an audio application. In ulp mode there is still a little bit of noise, but not with systemoff

weroflu

  • RFduino Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Wake not working
« Reply #3 on: October 25, 2017, 11:53:49 PM »
I am wondering if the docs for systemoff() are correct. Does it actually go into  the same low power state as ulpdelay(infinite) would do in loop?  ... where the bluetooth connection is still active

What I think is happening is it's turning off, then I lose connection, and since I have no physical buttons connected there is no way to trigger it waking up again. No, there are more problems because as soon as systemoff() executes I cannot even run any debug code, nothing nada zilch.

Though I did just try setting a 10 second delay timer after systemoff() and then issued systemreset but that didn't work either.

It would be nice to find a programmatic solution, but for my application all I really need is a physical on/off switch for the rfduino and my problems are solved.


tolson

  • Global Moderator
  • *****
  • Posts: 870
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: Wake not working
« Reply #4 on: October 26, 2017, 08:39:37 AM »
systemOFF is OFF. Everything is turned off. It only monitors an input pin as a wakeup interrupt which can turn things back on.

ULP Delay turns some thing off, lowers clock usage, monitors radio if used.

Exactly what it is doing will have to be answered by RFdigital. It would be nice to have those exact details in the documentation.
« Last Edit: October 26, 2017, 09:01:02 AM by tolson »

weroflu

  • RFduino Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Wake not working
« Reply #5 on: October 26, 2017, 08:55:39 AM »
ahhh thanks very much, that's what i suspected. so i think the thing to do is go ahead and just make a physical on off power switch for the rfduino, which will solve my noise problems.

tolson

  • Global Moderator
  • *****
  • Posts: 870
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: Wake not working
« Reply #6 on: October 26, 2017, 09:02:25 AM »
How will that be different from systemOFF. You had said you have no noise when using that.

weroflu

  • RFduino Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Wake not working
« Reply #7 on: October 26, 2017, 09:25:14 AM »
correct, no functional difference at all, except i would like a way to turn it back on. I could just unhook/rehook the main power supply and that would do it, but it seems more ergonomic to have a dedicated on/off for the rfduino.

Or if I used systemoff i'd still need a physical button to trigger its wakeup... at least I think that's the case. So button or on/off switch either one is fine. Space is very tight as is so I'll need to do a new board run no matter what.

 

anything