/** * 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 "../../lib/usart/src/usart.h" #include #include Mrf24j mrf; void handle_rx(); void handle_tx(); int main() { usart::init(1000000); 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); mrf.turbo(); sei(); while(1) { //printf("txxxing...\n\r"); //mrf.send16(0x4201, "abcd"); _delay_ms(5000); } } 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("%x", 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\n\r"); } else { printf("TX failed after %i retries\n\n\r", mrf.get_txinfo()->retries); } }