![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Wsn co ordinator
Fork of WSN_Coordinator by
Receiver.cpp@6:7a052af82e18, 2016-07-12 (annotated)
- Committer:
- akashlal
- Date:
- Tue Jul 12 15:49:20 2016 +0000
- Revision:
- 6:7a052af82e18
- Parent:
- 5:2f12cc3b6acb
na
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
janhavi | 4:b3a70cbb7c81 | 1 | /*****Multiceiver wireless network*****/ |
janhavi | 4:b3a70cbb7c81 | 2 | |
ganeshgore | 2:9f401852272c | 3 | #include "mbed.h" |
akashlal | 6:7a052af82e18 | 4 | #include "nRF24L01P.h" //Including nRF library |
ganeshgore | 2:9f401852272c | 5 | Serial pc(USBTX, USBRX); // tx, rx |
janhavi | 3:208abcd4751d | 6 | nRF24L01P my_nrf24l01p(PTD2, PTD3, PTD1, PTD0, PTD5, PTD4); // mosi, miso, sck, csn, ce, irq |
akashlal | 6:7a052af82e18 | 7 | DigitalOut GreenLED(PTA12); //For pipe 0 |
akashlal | 6:7a052af82e18 | 8 | DigitalOut BlueLED(PTC8); //For pipe 1 |
ganeshgore | 2:9f401852272c | 9 | int main() { |
ganeshgore | 2:9f401852272c | 10 | |
akashlal | 6:7a052af82e18 | 11 | char count[1]; //1 byte array |
akashlal | 6:7a052af82e18 | 12 | char RxDataCnt_PIPE0, RxDataCnt_PIPE1; //character for receiver pipe addresses |
akashlal | 6:7a052af82e18 | 13 | char temp; //temporary variable |
akashlal | 6:7a052af82e18 | 14 | char pot1Val, pot2Val; //Variables to be received and plotted |
janhavi | 3:208abcd4751d | 15 | |
janhavi | 4:b3a70cbb7c81 | 16 | //specifying address same as transmitter for pipe0 and pipe1 |
janhavi | 4:b3a70cbb7c81 | 17 | long long RxAddress_PIPE1 = 0xE2E2E2E2E2; |
janhavi | 4:b3a70cbb7c81 | 18 | long long RxAddress_PIPE0 = 0xC2C2C2C2C2; |
janhavi | 4:b3a70cbb7c81 | 19 | |
akashlal | 6:7a052af82e18 | 20 | my_nrf24l01p.powerUp(); //Powering up nrf chip |
akashlal | 6:7a052af82e18 | 21 | my_nrf24l01p.setRfFrequency(2405); //Setting RF frequency, same for tx and rx |
janhavi | 4:b3a70cbb7c81 | 22 | |
janhavi | 4:b3a70cbb7c81 | 23 | //set rx address with default address and for specified pipe |
janhavi | 4:b3a70cbb7c81 | 24 | my_nrf24l01p.setRxAddress(RxAddress_PIPE1, DEFAULT_NRF24L01P_ADDRESS_WIDTH, NRF24L01P_PIPE_P1); |
janhavi | 4:b3a70cbb7c81 | 25 | my_nrf24l01p.setRxAddress(RxAddress_PIPE0, DEFAULT_NRF24L01P_ADDRESS_WIDTH, NRF24L01P_PIPE_P0); |
janhavi | 4:b3a70cbb7c81 | 26 | |
janhavi | 3:208abcd4751d | 27 | |
ganeshgore | 2:9f401852272c | 28 | // Display the (default) setup of the nRF24L01+ chip |
ganeshgore | 2:9f401852272c | 29 | pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() ); |
ganeshgore | 2:9f401852272c | 30 | pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() ); |
ganeshgore | 2:9f401852272c | 31 | pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() ); |
janhavi | 4:b3a70cbb7c81 | 32 | |
janhavi | 4:b3a70cbb7c81 | 33 | //display rx address for both pipes |
janhavi | 4:b3a70cbb7c81 | 34 | pc.printf( "nRF24L01+ RX Address - PIPE0 : 0x%010llX\r\n", my_nrf24l01p.getRxAddress(NRF24L01P_PIPE_P0) ); |
janhavi | 4:b3a70cbb7c81 | 35 | pc.printf( "nRF24L01+ RX Address - PIPE1 : 0x%010llX\r\n", my_nrf24l01p.getRxAddress(NRF24L01P_PIPE_P1) ); |
janhavi | 3:208abcd4751d | 36 | |
janhavi | 4:b3a70cbb7c81 | 37 | pc.printf( "Wireless Sensor Network - Multiceiver\r\n" ); |
ganeshgore | 2:9f401852272c | 38 | |
janhavi | 4:b3a70cbb7c81 | 39 | RxDataCnt_PIPE0 = 1; |
janhavi | 4:b3a70cbb7c81 | 40 | RxDataCnt_PIPE1 = 1; |
janhavi | 4:b3a70cbb7c81 | 41 | |
janhavi | 4:b3a70cbb7c81 | 42 | //set transfer size explicitly for both pipes |
janhavi | 4:b3a70cbb7c81 | 43 | my_nrf24l01p.setTransferSize(RxDataCnt_PIPE1, NRF24L01P_PIPE_P1); |
janhavi | 4:b3a70cbb7c81 | 44 | my_nrf24l01p.setTransferSize(RxDataCnt_PIPE0, NRF24L01P_PIPE_P0); |
ganeshgore | 2:9f401852272c | 45 | |
ganeshgore | 2:9f401852272c | 46 | my_nrf24l01p.setReceiveMode(); |
ganeshgore | 2:9f401852272c | 47 | my_nrf24l01p.enable(); |
janhavi | 3:208abcd4751d | 48 | |
ganeshgore | 2:9f401852272c | 49 | while (1) { |
janhavi | 4:b3a70cbb7c81 | 50 | //check if data is available in pipe0 |
janhavi | 4:b3a70cbb7c81 | 51 | if ( my_nrf24l01p.readable(NRF24L01P_PIPE_P0) ) { |
ganeshgore | 2:9f401852272c | 52 | // ...read the data into the receive buffer |
janhavi | 4:b3a70cbb7c81 | 53 | temp = my_nrf24l01p.read( NRF24L01P_PIPE_P0, count, RxDataCnt_PIPE0 ); |
SIT2016 | 5:2f12cc3b6acb | 54 | pot1Val = count[0]; |
SIT2016 | 5:2f12cc3b6acb | 55 | //pc.printf("Received: %d bytes from PIPE0; POT=%d\r\n",temp, count[0]); |
ganeshgore | 2:9f401852272c | 56 | // Toggle LED2 (to help debug nRF24L01+ -> Host communication) |
ganeshgore | 2:9f401852272c | 57 | GreenLED = !GreenLED; |
ganeshgore | 2:9f401852272c | 58 | } |
janhavi | 4:b3a70cbb7c81 | 59 | //check if data is there in pipe1 |
janhavi | 4:b3a70cbb7c81 | 60 | if ( my_nrf24l01p.readable(NRF24L01P_PIPE_P1) ) { |
janhavi | 4:b3a70cbb7c81 | 61 | // ...read the data into the receive buffer |
janhavi | 4:b3a70cbb7c81 | 62 | temp = my_nrf24l01p.read( NRF24L01P_PIPE_P1, count, RxDataCnt_PIPE1 ); |
SIT2016 | 5:2f12cc3b6acb | 63 | pot2Val = count[0]; |
SIT2016 | 5:2f12cc3b6acb | 64 | //pc.printf("Received: %d bytes from PIPE1; POT=%d\r\n",temp, count[0]); |
janhavi | 4:b3a70cbb7c81 | 65 | // Toggle LED2 (to help debug nRF24L01+ -> Host communication) |
janhavi | 4:b3a70cbb7c81 | 66 | BlueLED = !BlueLED; |
janhavi | 4:b3a70cbb7c81 | 67 | } |
SIT2016 | 5:2f12cc3b6acb | 68 | wait_ms(100); |
SIT2016 | 5:2f12cc3b6acb | 69 | pc.printf("$%d %d;", pot1Val, pot2Val); |
ganeshgore | 2:9f401852272c | 70 | } |
janhavi | 3:208abcd4751d | 71 | } |