2011-03-13 19:28:44 +00:00
|
|
|
/**
|
2011-03-13 19:49:07 +00:00
|
|
|
* Example code for using a microchip mrf24j40 module to receive only
|
2011-03-13 19:28:44 +00:00
|
|
|
* packets using plain 802.15.4
|
|
|
|
* Requirements: 3 pins for spi, 3 pins for reset, chip select and interrupt
|
|
|
|
* notifications
|
|
|
|
* This example file is considered to be in the public domain
|
|
|
|
* Originally written by Karl Palsson, karlp@tweak.net.au, March 2011
|
|
|
|
*/
|
|
|
|
#include <SPI.h>
|
|
|
|
#include <mrf24j.h>
|
|
|
|
|
|
|
|
const int pin_reset = 6;
|
2011-12-17 06:33:54 +00:00
|
|
|
const int pin_cs = 10; // default CS pin on ATMEGA8
|
|
|
|
const int pin_interrupt = 2; // default interrupt pin on ATMEGA8
|
2011-03-13 19:28:44 +00:00
|
|
|
|
|
|
|
Mrf24j mrf(pin_reset, pin_cs, pin_interrupt);
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(9600);
|
|
|
|
|
|
|
|
mrf.set_pan(0xcafe);
|
|
|
|
// This is _our_ address
|
|
|
|
mrf.address16_write(0x6001);
|
2011-03-13 19:49:07 +00:00
|
|
|
mrf.set_channel(12);
|
2011-03-13 19:28:44 +00:00
|
|
|
|
|
|
|
// uncomment if you want to receive any packet on this channel
|
|
|
|
// mrf.set_promiscuous(true);
|
|
|
|
|
2011-12-17 06:33:54 +00:00
|
|
|
attachInterrupt(0, interrupt_routine, CHANGE); // interrupt 0 equivalent to pin 2 on ATMEGA8
|
|
|
|
interrupts();
|
2011-03-13 19:28:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void interrupt_routine() {
|
2011-12-17 06:33:54 +00:00
|
|
|
mrf.interrupt_handler();
|
2011-03-13 19:28:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2011-12-17 06:33:54 +00:00
|
|
|
mrf.check_flags(&handle_rx, &handle_tx);
|
|
|
|
}
|
2011-03-13 19:28:44 +00:00
|
|
|
|
2011-12-17 06:33:54 +00:00
|
|
|
void handle_rx() {
|
|
|
|
Serial.print("received a packet ");Serial.print(mrf.get_rxinfo()->frame_length, DEC);Serial.println(" bytes long");
|
|
|
|
|
|
|
|
Serial.println("Packet data:");
|
|
|
|
for (int i = 0; i < mrf.rx_datalength(); i++) {
|
|
|
|
Serial.write(mrf.get_rxinfo()->rx_data[i]);
|
2011-03-13 19:28:44 +00:00
|
|
|
}
|
2011-12-17 06:33:54 +00:00
|
|
|
|
|
|
|
Serial.print("\r\nLQI/RSSI=");
|
|
|
|
Serial.print(mrf.get_rxinfo()->lqi, DEC);
|
|
|
|
Serial.print("/");
|
|
|
|
Serial.println(mrf.get_rxinfo()->rssi, DEC);
|
2011-03-13 19:28:44 +00:00
|
|
|
}
|
2011-12-17 06:33:54 +00:00
|
|
|
|
|
|
|
void handle_tx() {
|
|
|
|
// code to transmit, nothing to do
|
|
|
|
}
|