/** * 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 "../../src/driver.h" #include #include Mrf24j mrf; int i = 0; void handle_rx(); void handle_tx(); int main() { mrf.reset(); mrf.init(); time_sleep(1); mrf.set_pan(0xcafe); // This is _our_ address mrf.address16_write(0x4201); mrf.handlers(&handle_rx, &handle_tx); printf("Pan id: %x\n\r", mrf.get_pan()); //mrf.enable_wake(); //mrf.set_bufferPHY(true); //mrf.turbo(); //mrf.set_power(0b1100000); //mrf.sleep(); printf("Started\n\r"); char tmp[20]; while(1) { printf("txxxing... %i\n\r", i++); //mrf.wake(); sprintf(tmp,"Received %i\n\r", i); mrf.send_str(0x4202, tmp); time_sleep(2); } } void handle_rx() { printf("received a packet %i bytes long\n\r", mrf.get_rxinfo()->frame_length); if(mrf.get_bufferPHY()){ printf("Packet data (PHY Payload):\n\r"); for (int i = 0; i < mrf.get_rxinfo()->frame_length; i++) { printf("%i", mrf.get_rxbuf()[i]); } } // printf("\r\nASCII data (relevant data):\n\r"); // for (int i = 0; i < mrf.rx_datalength(); i++) { // usart::put(mrf.get_rxinfo()->rx_data[i]); // } printf("\r\nLQI/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 %i\n\r", i); } else { printf("TX failed after %i retries\n\n\r", mrf.get_txinfo()->retries); } printf("Sleeping\n\r"); //mrf.sleep(); }