receiver code for wireless mouse

Dependencies:   USBDevice mbed nRF24L01P

Fork of kl25Z_nRF_RX by Ganesh Gore

Committer:
ganeshgore
Date:
Mon Jun 01 05:15:30 2015 +0000
Revision:
2:9f401852272c
Child:
3:725a4d2e9026
Initial Receiver Commit

Who changed what in which revision?

UserRevisionLine numberNew 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
ganeshgore 2:9f401852272c 6 nRF24L01P my_nrf24l01p(PTD6, PTE3, PTE2, PTB8, PTB9, PTD0); // mosi, miso, sck, csn, ce, irq
ganeshgore 2:9f401852272c 7 DigitalOut GreenLED(LED2);
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 }