IBS
/
WSN_Coordinator
Wsn co ordinator
Fork of WSN_Coordinator by
Receiver.cpp@5:2f12cc3b6acb, 2016-06-07 (annotated)
- Committer:
- SIT2016
- Date:
- Tue Jun 07 06:11:45 2016 +0000
- Revision:
- 5:2f12cc3b6acb
- Parent:
- 4:b3a70cbb7c81
- Child:
- 6:7a052af82e18
added serial plotting
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" |
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; |
SIT2016 | 5:2f12cc3b6acb | 19 | char pot1Val, pot2Val; |
janhavi | 3:208abcd4751d | 20 | |
janhavi | 4:b3a70cbb7c81 | 21 | //specifying address same as transmitter for pipe0 and pipe1 |
janhavi | 4:b3a70cbb7c81 | 22 | long long RxAddress_PIPE1 = 0xE2E2E2E2E2; |
janhavi | 4:b3a70cbb7c81 | 23 | long long RxAddress_PIPE0 = 0xC2C2C2C2C2; |
janhavi | 4:b3a70cbb7c81 | 24 | |
ganeshgore | 2:9f401852272c | 25 | my_nrf24l01p.powerUp(); |
ganeshgore | 2:9f401852272c | 26 | my_nrf24l01p.setRfFrequency(2410); |
janhavi | 4:b3a70cbb7c81 | 27 | |
janhavi | 4:b3a70cbb7c81 | 28 | //set rx address with default address and for specified pipe |
janhavi | 4:b3a70cbb7c81 | 29 | my_nrf24l01p.setRxAddress(RxAddress_PIPE1, DEFAULT_NRF24L01P_ADDRESS_WIDTH, NRF24L01P_PIPE_P1); |
janhavi | 4:b3a70cbb7c81 | 30 | my_nrf24l01p.setRxAddress(RxAddress_PIPE0, DEFAULT_NRF24L01P_ADDRESS_WIDTH, NRF24L01P_PIPE_P0); |
janhavi | 4:b3a70cbb7c81 | 31 | |
janhavi | 3:208abcd4751d | 32 | |
ganeshgore | 2:9f401852272c | 33 | // Display the (default) setup of the nRF24L01+ chip |
ganeshgore | 2:9f401852272c | 34 | pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() ); |
ganeshgore | 2:9f401852272c | 35 | pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() ); |
ganeshgore | 2:9f401852272c | 36 | pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() ); |
janhavi | 4:b3a70cbb7c81 | 37 | |
janhavi | 4:b3a70cbb7c81 | 38 | //display rx address for both pipes |
janhavi | 4:b3a70cbb7c81 | 39 | pc.printf( "nRF24L01+ RX Address - PIPE0 : 0x%010llX\r\n", my_nrf24l01p.getRxAddress(NRF24L01P_PIPE_P0) ); |
janhavi | 4:b3a70cbb7c81 | 40 | pc.printf( "nRF24L01+ RX Address - PIPE1 : 0x%010llX\r\n", my_nrf24l01p.getRxAddress(NRF24L01P_PIPE_P1) ); |
janhavi | 3:208abcd4751d | 41 | |
janhavi | 4:b3a70cbb7c81 | 42 | pc.printf( "Wireless Sensor Network - Multiceiver\r\n" ); |
ganeshgore | 2:9f401852272c | 43 | |
janhavi | 4:b3a70cbb7c81 | 44 | RxDataCnt_PIPE0 = 1; |
janhavi | 4:b3a70cbb7c81 | 45 | RxDataCnt_PIPE1 = 1; |
janhavi | 4:b3a70cbb7c81 | 46 | |
janhavi | 4:b3a70cbb7c81 | 47 | //set transfer size explicitly for both pipes |
janhavi | 4:b3a70cbb7c81 | 48 | my_nrf24l01p.setTransferSize(RxDataCnt_PIPE1, NRF24L01P_PIPE_P1); |
janhavi | 4:b3a70cbb7c81 | 49 | my_nrf24l01p.setTransferSize(RxDataCnt_PIPE0, NRF24L01P_PIPE_P0); |
ganeshgore | 2:9f401852272c | 50 | |
ganeshgore | 2:9f401852272c | 51 | my_nrf24l01p.setReceiveMode(); |
ganeshgore | 2:9f401852272c | 52 | my_nrf24l01p.enable(); |
janhavi | 3:208abcd4751d | 53 | |
ganeshgore | 2:9f401852272c | 54 | while (1) { |
janhavi | 4:b3a70cbb7c81 | 55 | |
janhavi | 4:b3a70cbb7c81 | 56 | //check if data is available in pipe0 |
janhavi | 4:b3a70cbb7c81 | 57 | if ( my_nrf24l01p.readable(NRF24L01P_PIPE_P0) ) { |
janhavi | 3:208abcd4751d | 58 | |
ganeshgore | 2:9f401852272c | 59 | // ...read the data into the receive buffer |
janhavi | 4:b3a70cbb7c81 | 60 | temp = my_nrf24l01p.read( NRF24L01P_PIPE_P0, count, RxDataCnt_PIPE0 ); |
SIT2016 | 5:2f12cc3b6acb | 61 | |
SIT2016 | 5:2f12cc3b6acb | 62 | pot1Val = count[0]; |
janhavi | 3:208abcd4751d | 63 | |
SIT2016 | 5:2f12cc3b6acb | 64 | //pc.printf("Received: %d bytes from PIPE0; POT=%d\r\n",temp, count[0]); |
janhavi | 3:208abcd4751d | 65 | |
ganeshgore | 2:9f401852272c | 66 | // Toggle LED2 (to help debug nRF24L01+ -> Host communication) |
ganeshgore | 2:9f401852272c | 67 | GreenLED = !GreenLED; |
ganeshgore | 2:9f401852272c | 68 | } |
janhavi | 4:b3a70cbb7c81 | 69 | |
janhavi | 4:b3a70cbb7c81 | 70 | //check if data is there in pipe1 |
janhavi | 4:b3a70cbb7c81 | 71 | if ( my_nrf24l01p.readable(NRF24L01P_PIPE_P1) ) { |
janhavi | 4:b3a70cbb7c81 | 72 | |
janhavi | 4:b3a70cbb7c81 | 73 | // ...read the data into the receive buffer |
janhavi | 4:b3a70cbb7c81 | 74 | temp = my_nrf24l01p.read( NRF24L01P_PIPE_P1, count, RxDataCnt_PIPE1 ); |
SIT2016 | 5:2f12cc3b6acb | 75 | |
SIT2016 | 5:2f12cc3b6acb | 76 | pot2Val = count[0]; |
janhavi | 4:b3a70cbb7c81 | 77 | |
SIT2016 | 5:2f12cc3b6acb | 78 | //pc.printf("Received: %d bytes from PIPE1; POT=%d\r\n",temp, count[0]); |
janhavi | 4:b3a70cbb7c81 | 79 | |
janhavi | 4:b3a70cbb7c81 | 80 | // Toggle LED2 (to help debug nRF24L01+ -> Host communication) |
janhavi | 4:b3a70cbb7c81 | 81 | BlueLED = !BlueLED; |
janhavi | 4:b3a70cbb7c81 | 82 | } |
SIT2016 | 5:2f12cc3b6acb | 83 | wait_ms(100); |
SIT2016 | 5:2f12cc3b6acb | 84 | pc.printf("$%d %d;", pot1Val, pot2Val); |
ganeshgore | 2:9f401852272c | 85 | } |
janhavi | 3:208abcd4751d | 86 | } |