/** * Example code for using a microchip mrf24j40 module to send and receive * 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 */ #define F_CPU 8000000UL #include "../../src/mrf24j.h" #include #include Mrf24j mrf; void handle_rx(); void handle_tx(); int main() { mrf.reset(); mrf.init(); mrf.set_pan(0xcafe); mrf.set_bufferPHY(true); // This is _our_ address mrf.address16_write(0x4202); mrf.handlers(&handle_rx, &handle_tx); printf("Pan id: %x\n\r", mrf.get_pan()); //mrf.turbo(); printf("Started"); while(1) { printf("Hello\n\r"); time_sleep(2); } } void handle_rx() { printf("------------------------------------------------------\n\r"); printf("received a packet %i bytes long\n\r", mrf.get_rxinfo()->frame_length); if(mrf.get_bufferPHY()){ printf("Packet data (PHY Payload): "); for (int i = 0; i < mrf.get_rxinfo()->frame_length; i++) { printf("%x", mrf.get_rxbuf()[i]); } } printf("\r\nASCII data (relevant data): "); for (int i = 0; i < mrf.rx_datalength(); i++) { putchar(mrf.get_rxinfo()->rx_data[i]); } printf("LQI/RSSI="); printf("%i/%i\n\r", mrf.get_rxinfo()->lqi, mrf.get_rxinfo()->rssi); } void handle_tx() { if (mrf.get_txinfo()->tx_ok) { printf("TX went ok, got ack\n\r"); } else { printf("TX failed after %i retries\n\n\r", mrf.get_txinfo()->retries); } }