Example RF24Network receive program. Tested on Nucleo 411.

Dependencies:   RF24 RF24Network mbed

Committer:
akashvibhute
Date:
Thu Nov 05 06:32:20 2015 +0000
Revision:
3:e9c4d66da50c
Parent:
2:608cf8c5c55e
updated library 05/nov/2015

Who changed what in which revision?

UserRevisionLine numberNew contents of line
akashvibhute 0:3982c0e9eda1 1 #include "mbed.h"
akashvibhute 0:3982c0e9eda1 2 #include <RF24Network.h>
akashvibhute 2:608cf8c5c55e 3 #include <RF24.h>
akashvibhute 0:3982c0e9eda1 4
akashvibhute 0:3982c0e9eda1 5 Serial pc(USBTX, USBRX);
akashvibhute 0:3982c0e9eda1 6
akashvibhute 0:3982c0e9eda1 7 #define nrf_CE D9
akashvibhute 0:3982c0e9eda1 8 #define nrf_CSN D10
akashvibhute 0:3982c0e9eda1 9 #define spi_SCK D3
akashvibhute 0:3982c0e9eda1 10 #define spi_MOSI D4
akashvibhute 0:3982c0e9eda1 11 #define spi_MISO D5
akashvibhute 0:3982c0e9eda1 12
akashvibhute 3:e9c4d66da50c 13
akashvibhute 3:e9c4d66da50c 14 RF24 radio(spi_MOSI, spi_MISO, spi_SCK, nrf_CE, nrf_CSN );
akashvibhute 0:3982c0e9eda1 15
akashvibhute 0:3982c0e9eda1 16 // Network uses that radio
akashvibhute 0:3982c0e9eda1 17 RF24Network network(radio);
akashvibhute 0:3982c0e9eda1 18
akashvibhute 0:3982c0e9eda1 19 // Address of our node
akashvibhute 3:e9c4d66da50c 20 const uint16_t this_node = 00;
akashvibhute 0:3982c0e9eda1 21
akashvibhute 0:3982c0e9eda1 22 // Address of the other node
akashvibhute 3:e9c4d66da50c 23 const uint16_t other_node = 01;
akashvibhute 0:3982c0e9eda1 24
akashvibhute 0:3982c0e9eda1 25 // When did we last send?
akashvibhute 0:3982c0e9eda1 26 unsigned long last_sent;
akashvibhute 0:3982c0e9eda1 27
akashvibhute 0:3982c0e9eda1 28 // How many have we sent already
akashvibhute 0:3982c0e9eda1 29 unsigned long packets_sent;
akashvibhute 0:3982c0e9eda1 30
akashvibhute 0:3982c0e9eda1 31 // Structure of our payload
akashvibhute 2:608cf8c5c55e 32 struct payload_t
akashvibhute 0:3982c0e9eda1 33 {
akashvibhute 2:608cf8c5c55e 34 unsigned long ms;
akashvibhute 2:608cf8c5c55e 35 unsigned long counter;
akashvibhute 0:3982c0e9eda1 36 };
akashvibhute 0:3982c0e9eda1 37
akashvibhute 0:3982c0e9eda1 38
akashvibhute 2:608cf8c5c55e 39 int main()
akashvibhute 0:3982c0e9eda1 40 {
akashvibhute 0:3982c0e9eda1 41 pc.baud(921600);
akashvibhute 0:3982c0e9eda1 42 wait_ms(1000);
akashvibhute 2:608cf8c5c55e 43
akashvibhute 2:608cf8c5c55e 44 pc.printf("mBed RF24Network node\n");
akashvibhute 0:3982c0e9eda1 45 radio.begin();
akashvibhute 0:3982c0e9eda1 46 network.begin(/*channel*/ 90, /*node address*/ this_node);
akashvibhute 0:3982c0e9eda1 47 wait_ms(2000);
akashvibhute 2:608cf8c5c55e 48
akashvibhute 2:608cf8c5c55e 49 while(1)
akashvibhute 0:3982c0e9eda1 50 {
akashvibhute 0:3982c0e9eda1 51 // Pump the network regularly
akashvibhute 0:3982c0e9eda1 52 network.update();
akashvibhute 2:608cf8c5c55e 53
akashvibhute 0:3982c0e9eda1 54 // Is there anything ready for us?
akashvibhute 2:608cf8c5c55e 55 while ( network.available() )
akashvibhute 0:3982c0e9eda1 56 {
akashvibhute 0:3982c0e9eda1 57 // If so, grab it and print it out
akashvibhute 0:3982c0e9eda1 58 RF24NetworkHeader header_rx;
akashvibhute 0:3982c0e9eda1 59 payload_t payload_rx;
akashvibhute 0:3982c0e9eda1 60 network.read(header_rx,&payload_rx,sizeof(payload_rx));
akashvibhute 3:e9c4d66da50c 61 pc.printf("Received packet # %d at %d ms\n",payload_rx.counter,payload_rx.ms);
akashvibhute 0:3982c0e9eda1 62 }
akashvibhute 1:5be48a9550c3 63
akashvibhute 0:3982c0e9eda1 64 }
akashvibhute 2:608cf8c5c55e 65
akashvibhute 0:3982c0e9eda1 66 }