Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of kl25Z_nRF_RX by
Receiver.cpp
00001 #include "mbed.h" 00002 #include "nRF24L01P.h" 00003 00004 Serial pc(USBTX, USBRX); // tx, rx 00005 00006 nRF24L01P my_nrf24l01p(PTD2, PTD3, PTD1, PTD0, PTD5, PTD4); // mosi, miso, sck, csn, ce, irq 00007 DigitalOut GreenLED(LED2); 00008 PwmOut RedLed(LED1); 00009 00010 int main() { 00011 00012 char count[2]; 00013 char RxDataCnt; 00014 char temp; 00015 00016 float ldr_val, pot_val; 00017 00018 my_nrf24l01p.powerUp(); 00019 my_nrf24l01p.setRfFrequency(2410); 00020 00021 // Display the (default) setup of the nRF24L01+ chip 00022 pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() ); 00023 pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() ); 00024 pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() ); 00025 pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() ); 00026 pc.printf( "nRF24L01+ RX Address : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() ); 00027 00028 pc.printf( "Simple 2 Byte Receiver\r\n" ); 00029 00030 RxDataCnt = 2; 00031 my_nrf24l01p.setTransferSize( RxDataCnt ); 00032 00033 my_nrf24l01p.setReceiveMode(); 00034 my_nrf24l01p.enable(); 00035 00036 while (1) { 00037 00038 // If we've received anything in the nRF24L01+... 00039 if ( my_nrf24l01p.readable() ) { 00040 00041 // ...read the data into the receive buffer 00042 temp = my_nrf24l01p.read( NRF24L01P_PIPE_P0, count, RxDataCnt ); 00043 00044 ldr_val = count[0]/255.0; 00045 pot_val = count[1]/255.0; 00046 00047 //change according to need here; Im printing on serial terminal 00048 pc.printf("Received: %d bytes ;LDR=%.3f, POT=%.3f\r\n",temp,ldr_val, pot_val); 00049 00050 // Toggle LED2 (to help debug nRF24L01+ -> Host communication) 00051 GreenLED = !GreenLED; 00052 wait_ms(10); 00053 } 00054 } 00055 }
Generated on Mon Jul 18 2022 03:27:01 by
1.7.2
