Author Topic: Wake not working  (Read 87 times)

weroflu

  • RFduino Newbie
  • *
  • Posts: 1
  • 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: 859
  • 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 »