This example shows how to send data packet.
#if defined(__PIC32MX__)
#include <WProgram.h>
#else
#include <Arduino.h>
#endif
#if defined(__AVR__) || defined(CORE_TEENSY)
#include <MsTimer2.h>
#elif defined(__SAM3X8E__)
#include <DueTimer.h>
#endif
#include <stddef.h>
#include <stdint.h>
#define USER_TIMER_PERIOD 5000
#define TR_RESET_PIN 6
#define TR_SS_PIN 10
void setup();
void loop();
void rxHandler();
void txHandler(uint8_t packetId, uint8_t packetResult);
#if defined(__PIC32MX__)
uint32_t msTimerCallback(uint32_t currentTime);
#else
void msTimerCallback();
#endif
typedef struct {
uint8_t *txBuffer;
uint8_t packetId;
volatile uint16_t timer;
volatile bool timerAck;
const char testBuffer[12] = {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!'};
void setup() {
pinMode(13, OUTPUT);
Serial.begin(9600);
while (!Serial) {
}
iqrf.
begin(rxHandler, txHandler);
case iqrfTr.types::TR_52D:
Serial.println("[IQRF] Module type: TR-52D");
break;
case iqrfTr.types::TR_72D:
Serial.println("[IQRF] Module type: TR-72D");
break;
default:
Serial.println("[IQRF] Module type: UNKNOWN");
break;
}
#if defined(__AVR__) || defined(CORE_TEENSY)
MsTimer2::set(1, msTimerCallback);
MsTimer2::start();
#elif defined(__SAM3X8E__)
Timer6.attachInterrupt(msTimerCallback).start(1000);
#elif defined(__PIC32MX__)
attachCoreTimerService(msTimerCallback);
#endif
appVars.
timer = USER_TIMER_PERIOD;
}
void loop() {
appVars.
txBuffer = (uint8_t *) malloc(
sizeof(testBuffer));
memcpy(appVars.
txBuffer, (uint8_t *) & testBuffer,
sizeof(testBuffer));
}
}
}
#if defined(__PIC32MX__)
uint32_t msTimerCallback(uint32_t currentTime) {
if ((--appVars.
timer) == 0) {
appVars.
timer = USER_TIMER_PERIOD;
}
}
return(currentTime + CORE_TICK_RATE);
}
#else
void msTimerCallback() {
if ((--appVars.
timer) == 0) {
appVars.
timer = USER_TIMER_PERIOD;
}
}
}
#endif
void rxHandler() {
Serial.print("[IQRF] Receive done: ");
Serial.println();
}
void txHandler(uint8_t packetId, uint8_t packetResult) {
Serial.println("[IQRF] Send done");
}