0

I am trying to send ECG data using RFduino. I am using two RFduino modules. The transmitter module is using the device code while the receiver is using the host code. I have common baud rate between the two modules which is 250k. I have an issue with the first data that comes to the receiver . Always a question mark is displayed in the beginning as shown in the figure below:

question mark issue

I do not want this question mark to appear at the beginning because it is making issues in the analysis side.

Codes:

device:

/*
This sketch demonstrates how to send structured data from a Device
to a Host in a Gazell network.

Written by (VLorz) Victor Lorenzo.

You are free to use this code.
*/

#include <RFduinoGZLL.h>
#include "myStruct.h"


/* This instance will be sent over GZLL */
static my_struct_t  theStruct;

/* And this variable is for timing */
static long PrevTime;

/* It would be nice to know if the host received the packet */
static bool   Acked;
static int    AckedCount;


void setup()
{
  // Initialize the structure to a known state;
  //theStruct.OneByte = 1;
  //theStruct.OneDWord = 0x02030405;
  theStruct.ECG = 0x0000;
  //theStruct.Count = 0;
  Serial.begin(250000);
  //pinMode(3, INPUT); // Setup for leads off detection LO +
  //pinMode(2, INPUT); // Setup for leads off detection LO -
  Serial.println("CLEARDATA"); //clears up 

  Serial.println("RESETTIMER"); //resets timer to 0
  // start the GZLL stack;
  Serial.print( F("GZLL init...") );
  Serial.println( RFduinoGZLL.begin( DEVICE0 ) );

  Serial.println( F("Running") );

  /* Force the first xmit */
  PrevTime = millis() - 1001;
  Acked = false;
}


void loop()
{
  long  Now;

  Now = millis();

  if (4 <= Now - PrevTime) {
    Acked = false;

    // This is simply for making something change;
    theStruct.Count++;
    theStruct.ECG  = analogRead(2);
    // So we send the struct to the host;
    RFduinoGZLL.sendToHost( (char*)&theStruct, sizeof(theStruct) );

    PrevTime = Now;
  }

  if (Acked) {
    Acked = false;
    //Serial.print( "Ack received for Count = " );
    //Serial.println( AckedCount );
    Serial.println(theStruct.ECG );
  }
}


void RFduinoGZLL_onReceive(device_t device, int rssi, char *data, int len)
{
  // What we expect here is the host sending the value in the Count field from 
  // the structure we have sent;
  if (len == 1)
    AckedCount = (uint8_t)*data;
  else
    AckedCount = -1;

  Acked = true;
}

The host:

/*
This sketch demonstrates how to send structured data from a Device
to a Host in a Gazell network.

Written by (VLorz) Victor Lorenzo.
You are free to use this code.
*/

#include <RFduinoGZLL.h>
#include "myStruct.h"

/* This instance will be filled with data received over GZLL */
static my_struct_t  theReceivedStruct;

/* It would be nice to know if the host received the packet */
static bool   DataReady;

void setup()
{
  Serial.flush();
  Serial.begin(250000);

  // start the GZLL stack;
 // Serial.print( F("GZLL init...") );
  Serial.println( RFduinoGZLL.begin( HOST ) );
  //Serial.println( F("Running") );

  DataReady = false;
}


void loop()
{
  if (DataReady) {
    //Serial.println( "Data received!!!" );
    //Serial.print( F("OneWord=") );
    Serial.println( theReceivedStruct.ECG, DEC );
    //Serial.print( F("Count=") );
    //Serial.println( theReceivedStruct.Count );
   // Serial.println( "" );
    DataReady = false;
  }
}

void RFduinoGZLL_onReceive(device_t device, int rssi, char *data, int len)
{
  //
  // IMPORTANT!!! This function runs under interrupt context!!!
  //

  if (DataReady) {
    // Do not overwrite our buffer;
    return;
  }

  if (len != sizeof(theReceivedStruct)) {
    // Ignore packets with wrong length!!!
    return;
  }

  // Copy the data to our structure buffer;
  for (char* lpDest = (char*)&theReceivedStruct; len > 0; len--) {
    *lpDest = *data;
    lpDest++;
    data++;
  }

  // ...and signal the application the data is ready
  DataReady = true;

  RFduinoGZLL.sendToDevice( device, theReceivedStruct.Count );
}
  • Can you include the output with all of the debugging un-commented on the host? – Craig May 7 '18 at 20:53
  • @Craig what do you mean .? To remove the comments of serial commands in the setup() or loop ?? – Ahmed K Moustafa May 8 '18 at 21:34
  • Yes. uncomment the Serial.print and Serial.println lines in both setup() and loop(). That extra output will be useful in debugging the problem. – Craig May 8 '18 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.