As I try to streamline radio communications, I've added conditional compiles to leave out code needed or not needed for development vs. fast running.
I tried removing the nodeId element from the Payload struct and got rather strange behavior.
// constants for specifying mode in which program is to run
#define CAL (0) // run sketch in calibration mode
#define DEV (1) // debug data included in packets over radio
#define RUN (2) // only essential data in packets over radio
#define RUN_MODE (RUN) // CAL, DEV or RUN
// Set up structure for radio packet payload.
// Both sides must have exact same structure to send from and receive into.
#if (RUN_MODE == RUN)
typedef struct
{
float theta; // [rad], shaft angle
float batV; // [V], wireless sensor battery voltage
boolean TDC; // true when TDC has been reached, otherwise false
} Payload;
#else // must be CAL or DEV
typedef struct
{
int nodeId; // store this nodeId
unsigned long remTime_ms; // [ms], elapsed time
float theta; // [rad], shaft angle
float X; // [g], acceleration in X direction
float Y; // [g], acceleration in Y direction
float batV; // [V], wireless sensor battery voltage
boolean TDC; // true when TDC has been reached, otherwise false
} Payload;
Payload RFDataPktToSend;
#endif
When I try to run this, the code hangs up while reading the accelerometer (over SPI) with no error message. In loop(), it just never makes it past the first read of the accelerometer (as evidenced by a Serial.print on either side of the read. Only the first one prints then nothing.)
Serial.println("About to read IMU..."); // debug
X_Raw = myIMU.readFloatAccelX();
Serial.println("Read X from IMU..."); // debug
If I change to RUN_MODE (DEV), it runs fine.
FYI, this is the send (though it never gets there):
radio.send(GATEWAYID, (const void*)(&RFDataPktToSend), sizeof(RFDataPktToSend));
1) I just want to confirm that NodeId does not need to be in the struct for the radio to function, right?
2) From experimentation, it seems that the Payload struct must start with an int or a long. Otherwise the sketch will not run. Any reason that you know of for this? I mean, an int or a float are both just 4 bytes of binary data. What does it care? Hmm...
Any ideas?