Node on PIPE0 for Wireless sensor network over NRF.

Dependencies:   mbed nRF24L01P

Fork of WSN_Coordinator by Eduvance SIT2017

Committer:
janhavi
Date:
Mon Jun 06 10:57:33 2016 +0000
Revision:
4:b3a70cbb7c81
Parent:
3:208abcd4751d
Single Receiver for multiple sensors connected to different transmitters. Uses NRF logical pipes for communication over same RF channel.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
janhavi 4:b3a70cbb7c81 1 /*****Multiceiver wireless network*****/
janhavi 4:b3a70cbb7c81 2
ganeshgore 2:9f401852272c 3 #include "mbed.h"
ganeshgore 2:9f401852272c 4 #include "nRF24L01P.h"
janhavi 3:208abcd4751d 5
ganeshgore 2:9f401852272c 6 Serial pc(USBTX, USBRX); // tx, rx
janhavi 3:208abcd4751d 7
janhavi 3:208abcd4751d 8 nRF24L01P my_nrf24l01p(PTD2, PTD3, PTD1, PTD0, PTD5, PTD4); // mosi, miso, sck, csn, ce, irq
janhavi 4:b3a70cbb7c81 9
janhavi 4:b3a70cbb7c81 10 //blue for pipe1 and green for pipe0
janhavi 4:b3a70cbb7c81 11 DigitalOut GreenLED(PTA12);
janhavi 4:b3a70cbb7c81 12 DigitalOut BlueLED(PTC8);
janhavi 3:208abcd4751d 13
ganeshgore 2:9f401852272c 14 int main() {
ganeshgore 2:9f401852272c 15
janhavi 4:b3a70cbb7c81 16 char count[1];
janhavi 4:b3a70cbb7c81 17 char RxDataCnt_PIPE0, RxDataCnt_PIPE1;
ganeshgore 2:9f401852272c 18 char temp;
janhavi 3:208abcd4751d 19
janhavi 4:b3a70cbb7c81 20 //specifying address same as transmitter for pipe0 and pipe1
janhavi 4:b3a70cbb7c81 21 long long RxAddress_PIPE1 = 0xE2E2E2E2E2;
janhavi 4:b3a70cbb7c81 22 long long RxAddress_PIPE0 = 0xC2C2C2C2C2;
janhavi 4:b3a70cbb7c81 23
ganeshgore 2:9f401852272c 24 my_nrf24l01p.powerUp();
ganeshgore 2:9f401852272c 25 my_nrf24l01p.setRfFrequency(2410);
janhavi 4:b3a70cbb7c81 26
janhavi 4:b3a70cbb7c81 27 //set rx address with default address and for specified pipe
janhavi 4:b3a70cbb7c81 28 my_nrf24l01p.setRxAddress(RxAddress_PIPE1, DEFAULT_NRF24L01P_ADDRESS_WIDTH, NRF24L01P_PIPE_P1);
janhavi 4:b3a70cbb7c81 29 my_nrf24l01p.setRxAddress(RxAddress_PIPE0, DEFAULT_NRF24L01P_ADDRESS_WIDTH, NRF24L01P_PIPE_P0);
janhavi 4:b3a70cbb7c81 30
janhavi 3:208abcd4751d 31
ganeshgore 2:9f401852272c 32 // Display the (default) setup of the nRF24L01+ chip
ganeshgore 2:9f401852272c 33 pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() );
ganeshgore 2:9f401852272c 34 pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() );
ganeshgore 2:9f401852272c 35 pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() );
janhavi 4:b3a70cbb7c81 36
janhavi 4:b3a70cbb7c81 37 //display rx address for both pipes
janhavi 4:b3a70cbb7c81 38 pc.printf( "nRF24L01+ RX Address - PIPE0 : 0x%010llX\r\n", my_nrf24l01p.getRxAddress(NRF24L01P_PIPE_P0) );
janhavi 4:b3a70cbb7c81 39 pc.printf( "nRF24L01+ RX Address - PIPE1 : 0x%010llX\r\n", my_nrf24l01p.getRxAddress(NRF24L01P_PIPE_P1) );
janhavi 3:208abcd4751d 40
janhavi 4:b3a70cbb7c81 41 pc.printf( "Wireless Sensor Network - Multiceiver\r\n" );
ganeshgore 2:9f401852272c 42
janhavi 4:b3a70cbb7c81 43 RxDataCnt_PIPE0 = 1;
janhavi 4:b3a70cbb7c81 44 RxDataCnt_PIPE1 = 1;
janhavi 4:b3a70cbb7c81 45
janhavi 4:b3a70cbb7c81 46 //set transfer size explicitly for both pipes
janhavi 4:b3a70cbb7c81 47 my_nrf24l01p.setTransferSize(RxDataCnt_PIPE1, NRF24L01P_PIPE_P1);
janhavi 4:b3a70cbb7c81 48 my_nrf24l01p.setTransferSize(RxDataCnt_PIPE0, NRF24L01P_PIPE_P0);
ganeshgore 2:9f401852272c 49
ganeshgore 2:9f401852272c 50 my_nrf24l01p.setReceiveMode();
ganeshgore 2:9f401852272c 51 my_nrf24l01p.enable();
janhavi 3:208abcd4751d 52
ganeshgore 2:9f401852272c 53 while (1) {
janhavi 4:b3a70cbb7c81 54
janhavi 4:b3a70cbb7c81 55 //check if data is available in pipe0
janhavi 4:b3a70cbb7c81 56 if ( my_nrf24l01p.readable(NRF24L01P_PIPE_P0) ) {
janhavi 3:208abcd4751d 57
ganeshgore 2:9f401852272c 58 // ...read the data into the receive buffer
janhavi 4:b3a70cbb7c81 59 temp = my_nrf24l01p.read( NRF24L01P_PIPE_P0, count, RxDataCnt_PIPE0 );
janhavi 3:208abcd4751d 60
janhavi 4:b3a70cbb7c81 61 pc.printf("Received: %d bytes from PIPE0; POT=%d\r\n",temp, count[0]);
janhavi 3:208abcd4751d 62
ganeshgore 2:9f401852272c 63 // Toggle LED2 (to help debug nRF24L01+ -> Host communication)
ganeshgore 2:9f401852272c 64 GreenLED = !GreenLED;
ganeshgore 2:9f401852272c 65 wait_ms(10);
ganeshgore 2:9f401852272c 66 }
janhavi 4:b3a70cbb7c81 67
janhavi 4:b3a70cbb7c81 68 //check if data is there in pipe1
janhavi 4:b3a70cbb7c81 69 if ( my_nrf24l01p.readable(NRF24L01P_PIPE_P1) ) {
janhavi 4:b3a70cbb7c81 70
janhavi 4:b3a70cbb7c81 71 // ...read the data into the receive buffer
janhavi 4:b3a70cbb7c81 72 temp = my_nrf24l01p.read( NRF24L01P_PIPE_P1, count, RxDataCnt_PIPE1 );
janhavi 4:b3a70cbb7c81 73
janhavi 4:b3a70cbb7c81 74 pc.printf("Received: %d bytes from PIPE1; POT=%d\r\n",temp, count[0]);
janhavi 4:b3a70cbb7c81 75
janhavi 4:b3a70cbb7c81 76 // Toggle LED2 (to help debug nRF24L01+ -> Host communication)
janhavi 4:b3a70cbb7c81 77 BlueLED = !BlueLED;
janhavi 4:b3a70cbb7c81 78 wait_ms(10);
janhavi 4:b3a70cbb7c81 79 }
ganeshgore 2:9f401852272c 80 }
janhavi 3:208abcd4751d 81 }