in d mix

Dependencies:   xtoff2 RF24Network mbed

Fork of RF24Network_Receive by Akash Vibhute

Committer:
akashvibhute
Date:
Mon Jul 06 03:17:33 2015 +0000
Revision:
0:3982c0e9eda1
Child:
1:5be48a9550c3
First mbed-arduino working program!; mbed is able to receive data from arduino nodes 0 or 1 depending on address set

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 0:3982c0e9eda1 3 #include <nRF24L01P_Maniacbug.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 nrf_IRQ PB_0
akashvibhute 0:3982c0e9eda1 10 #define spi_SCK D3
akashvibhute 0:3982c0e9eda1 11 #define spi_MOSI D4
akashvibhute 0:3982c0e9eda1 12 #define spi_MISO D5
akashvibhute 0:3982c0e9eda1 13
akashvibhute 0:3982c0e9eda1 14 //RF24 radio(D11, D12, D13, D10, D9);
akashvibhute 0:3982c0e9eda1 15 RF24 radio(spi_MOSI, spi_MISO, spi_SCK, nrf_CSN, nrf_CE);
akashvibhute 0:3982c0e9eda1 16
akashvibhute 0:3982c0e9eda1 17 // Network uses that radio
akashvibhute 0:3982c0e9eda1 18 RF24Network network(radio);
akashvibhute 0:3982c0e9eda1 19
akashvibhute 0:3982c0e9eda1 20 // Address of our node
akashvibhute 0:3982c0e9eda1 21 const uint16_t this_node = 0;
akashvibhute 0:3982c0e9eda1 22
akashvibhute 0:3982c0e9eda1 23 // Address of the other node
akashvibhute 0:3982c0e9eda1 24 const uint16_t other_node = 1;
akashvibhute 0:3982c0e9eda1 25
akashvibhute 0:3982c0e9eda1 26 // How often to send 'hello world to the other unit
akashvibhute 0:3982c0e9eda1 27 const unsigned long interval = 100; //ms
akashvibhute 0:3982c0e9eda1 28
akashvibhute 0:3982c0e9eda1 29 // When did we last send?
akashvibhute 0:3982c0e9eda1 30 unsigned long last_sent;
akashvibhute 0:3982c0e9eda1 31
akashvibhute 0:3982c0e9eda1 32 // How many have we sent already
akashvibhute 0:3982c0e9eda1 33 unsigned long packets_sent;
akashvibhute 0:3982c0e9eda1 34
akashvibhute 0:3982c0e9eda1 35 // Structure of our payload
akashvibhute 0:3982c0e9eda1 36 struct payload_t
akashvibhute 0:3982c0e9eda1 37 {
akashvibhute 0:3982c0e9eda1 38 unsigned long ms;
akashvibhute 0:3982c0e9eda1 39 unsigned long counter;
akashvibhute 0:3982c0e9eda1 40
akashvibhute 0:3982c0e9eda1 41 float vector_4d[4];
akashvibhute 0:3982c0e9eda1 42 };
akashvibhute 0:3982c0e9eda1 43
akashvibhute 0:3982c0e9eda1 44
akashvibhute 0:3982c0e9eda1 45 int main()
akashvibhute 0:3982c0e9eda1 46 {
akashvibhute 0:3982c0e9eda1 47 pc.baud(921600);
akashvibhute 0:3982c0e9eda1 48 wait_ms(1000);
akashvibhute 0:3982c0e9eda1 49
akashvibhute 0:3982c0e9eda1 50
akashvibhute 0:3982c0e9eda1 51
akashvibhute 0:3982c0e9eda1 52 pc.printf("mBed RF24 network node - Rx only\n");
akashvibhute 0:3982c0e9eda1 53 radio.begin();
akashvibhute 0:3982c0e9eda1 54 network.begin(/*channel*/ 90, /*node address*/ this_node);
akashvibhute 0:3982c0e9eda1 55 wait_ms(2000);
akashvibhute 0:3982c0e9eda1 56
akashvibhute 0:3982c0e9eda1 57 while(1)
akashvibhute 0:3982c0e9eda1 58 {
akashvibhute 0:3982c0e9eda1 59 // Pump the network regularly
akashvibhute 0:3982c0e9eda1 60 network.update();
akashvibhute 0:3982c0e9eda1 61
akashvibhute 0:3982c0e9eda1 62 // Is there anything ready for us?
akashvibhute 0:3982c0e9eda1 63 while ( network.available() )
akashvibhute 0:3982c0e9eda1 64 {
akashvibhute 0:3982c0e9eda1 65 // If so, grab it and print it out
akashvibhute 0:3982c0e9eda1 66 RF24NetworkHeader header_rx;
akashvibhute 0:3982c0e9eda1 67 payload_t payload_rx;
akashvibhute 0:3982c0e9eda1 68 network.read(header_rx,&payload_rx,sizeof(payload_rx));
akashvibhute 0:3982c0e9eda1 69 pc.printf("Received packet # %d at %d ms, message: V4 %f, %f, %f, %f \n",payload_rx.counter,payload_rx.ms, payload_rx.vector_4d[0],payload_rx.vector_4d[1],payload_rx.vector_4d[2],payload_rx.vector_4d[3]);
akashvibhute 0:3982c0e9eda1 70 }
akashvibhute 0:3982c0e9eda1 71 }
akashvibhute 0:3982c0e9eda1 72
akashvibhute 0:3982c0e9eda1 73 }