test

Dependencies:   mbed nRF24L01P

Fork of nRF24L01P_Hello_World by Owen Edwards

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Receiver.cpp Source File

Receiver.cpp

00001 #include "mbed.h"
00002 #include "nRF24L01P.h"
00003 
00004 Serial pc(USBTX, USBRX); // tx, rx
00005 
00006 nRF24L01P my_nrf24l01p(PTD6, PTE3, PTE2, PTB8, PTB9, PTD0);    // mosi, miso, sck, csn, ce, irq
00007 DigitalOut GreenLED(LED2);
00008 
00009 
00010 int main() {
00011     
00012     char count[2];
00013     char RxDataCnt;
00014     char temp;
00015 
00016     my_nrf24l01p.powerUp();
00017     my_nrf24l01p.setRfFrequency(2410);
00018 
00019     // Display the (default) setup of the nRF24L01+ chip
00020     pc.printf( "nRF24L01+ Frequency    : %d MHz\r\n",  my_nrf24l01p.getRfFrequency() );
00021     pc.printf( "nRF24L01+ Output power : %d dBm\r\n",  my_nrf24l01p.getRfOutputPower() );
00022     pc.printf( "nRF24L01+ Data Rate    : %d kbps\r\n", my_nrf24l01p.getAirDataRate() );
00023     pc.printf( "nRF24L01+ TX Address   : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() );
00024     pc.printf( "nRF24L01+ RX Address   : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() );
00025 
00026     pc.printf( "Simple 2 Byte Receiver\r\n" );
00027     
00028     RxDataCnt = 2;
00029     my_nrf24l01p.setTransferSize( RxDataCnt );
00030     
00031     my_nrf24l01p.setReceiveMode();
00032     my_nrf24l01p.enable();
00033 
00034     while (1) {
00035 
00036         // If we've received anything in the nRF24L01+...
00037         if ( my_nrf24l01p.readable() ) {
00038 
00039             // ...read the data into the receive buffer
00040             temp = my_nrf24l01p.read( NRF24L01P_PIPE_P0, count, RxDataCnt );
00041 
00042 
00043             pc.printf( "Cnt %d = %d %d\r\n",temp,count[0],count[1]);
00044 
00045 
00046             // Toggle LED2 (to help debug nRF24L01+ -> Host communication)
00047             GreenLED = !GreenLED;
00048             wait_ms(10);
00049         }
00050     }
00051 }