Eduvance SIT2017
/
kl25Z_nRF_RX
Basic NRF Receiver on IOT shield.
Fork of kl25Z_nRF_RX by
Receiver.cpp@3:f3e27d1b37ad, 2016-06-04 (annotated)
- Committer:
- SIT2016
- Date:
- Sat Jun 04 05:35:08 2016 +0000
- Revision:
- 3:f3e27d1b37ad
- Parent:
- 2:9f401852272c
Basic NRF Reciever
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ganeshgore | 2:9f401852272c | 1 | #include "mbed.h" |
ganeshgore | 2:9f401852272c | 2 | #include "nRF24L01P.h" |
ganeshgore | 2:9f401852272c | 3 | |
ganeshgore | 2:9f401852272c | 4 | Serial pc(USBTX, USBRX); // tx, rx |
ganeshgore | 2:9f401852272c | 5 | |
SIT2016 | 3:f3e27d1b37ad | 6 | nRF24L01P my_nrf24l01p(PTD2, PTD3, PTD1, PTD0, PTD5, PTD4); // mosi, miso, sck, csn, ce, irq |
SIT2016 | 3:f3e27d1b37ad | 7 | DigitalOut GreenLED(PTA12); |
ganeshgore | 2:9f401852272c | 8 | |
ganeshgore | 2:9f401852272c | 9 | |
ganeshgore | 2:9f401852272c | 10 | int main() { |
ganeshgore | 2:9f401852272c | 11 | |
ganeshgore | 2:9f401852272c | 12 | char count[2]; |
ganeshgore | 2:9f401852272c | 13 | char RxDataCnt; |
ganeshgore | 2:9f401852272c | 14 | char temp; |
ganeshgore | 2:9f401852272c | 15 | |
ganeshgore | 2:9f401852272c | 16 | my_nrf24l01p.powerUp(); |
ganeshgore | 2:9f401852272c | 17 | my_nrf24l01p.setRfFrequency(2410); |
ganeshgore | 2:9f401852272c | 18 | |
ganeshgore | 2:9f401852272c | 19 | // Display the (default) setup of the nRF24L01+ chip |
ganeshgore | 2:9f401852272c | 20 | pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() ); |
ganeshgore | 2:9f401852272c | 21 | pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() ); |
ganeshgore | 2:9f401852272c | 22 | pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() ); |
ganeshgore | 2:9f401852272c | 23 | pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() ); |
ganeshgore | 2:9f401852272c | 24 | pc.printf( "nRF24L01+ RX Address : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() ); |
ganeshgore | 2:9f401852272c | 25 | |
ganeshgore | 2:9f401852272c | 26 | pc.printf( "Simple 2 Byte Receiver\r\n" ); |
ganeshgore | 2:9f401852272c | 27 | |
ganeshgore | 2:9f401852272c | 28 | RxDataCnt = 2; |
ganeshgore | 2:9f401852272c | 29 | my_nrf24l01p.setTransferSize( RxDataCnt ); |
ganeshgore | 2:9f401852272c | 30 | |
ganeshgore | 2:9f401852272c | 31 | my_nrf24l01p.setReceiveMode(); |
ganeshgore | 2:9f401852272c | 32 | my_nrf24l01p.enable(); |
ganeshgore | 2:9f401852272c | 33 | |
ganeshgore | 2:9f401852272c | 34 | while (1) { |
ganeshgore | 2:9f401852272c | 35 | |
ganeshgore | 2:9f401852272c | 36 | // If we've received anything in the nRF24L01+... |
ganeshgore | 2:9f401852272c | 37 | if ( my_nrf24l01p.readable() ) { |
ganeshgore | 2:9f401852272c | 38 | |
ganeshgore | 2:9f401852272c | 39 | // ...read the data into the receive buffer |
ganeshgore | 2:9f401852272c | 40 | temp = my_nrf24l01p.read( NRF24L01P_PIPE_P0, count, RxDataCnt ); |
ganeshgore | 2:9f401852272c | 41 | |
ganeshgore | 2:9f401852272c | 42 | |
ganeshgore | 2:9f401852272c | 43 | pc.printf( "Cnt %d = %d %d\r\n",temp,count[0],count[1]); |
ganeshgore | 2:9f401852272c | 44 | |
ganeshgore | 2:9f401852272c | 45 | |
ganeshgore | 2:9f401852272c | 46 | // Toggle LED2 (to help debug nRF24L01+ -> Host communication) |
ganeshgore | 2:9f401852272c | 47 | GreenLED = !GreenLED; |
ganeshgore | 2:9f401852272c | 48 | wait_ms(10); |
ganeshgore | 2:9f401852272c | 49 | } |
ganeshgore | 2:9f401852272c | 50 | } |
ganeshgore | 2:9f401852272c | 51 | } |