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.
main.cpp
00001 #include "mbed.h" 00002 #include "nRF24L01P.h" 00003 00004 PinName nrfMOSI = SPI_MOSI; 00005 PinName nrfMISO = SPI_MISO; 00006 PinName nrfSCK = SPI_SCK; 00007 PinName nrfCSN = SPI_CS; 00008 PinName nrfCE = D7; 00009 PinName nrfIRQ = NC; 00010 00011 Serial pc(USBTX, USBRX); 00012 nRF24L01P my_nrf24l01p(nrfMOSI, nrfMISO, nrfSCK, nrfCSN, nrfCE, nrfIRQ); 00013 00014 int main() 00015 { 00016 const size_t TRANSFER_SIZE = 4; 00017 const size_t RECEIVER_SIZE = 4; 00018 00019 char txData[TRANSFER_SIZE], rxData[RECEIVER_SIZE]; 00020 int txDataCnt = 0; 00021 int rxDataCnt = 0; 00022 00023 // Display the (default) setup of the nRF24L01+ chip 00024 pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() ); 00025 pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() ); 00026 pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() ); 00027 pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() ); 00028 pc.printf( "nRF24L01+ RX Address : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() ); 00029 00030 pc.printf( "Type keys to test transfers:\r\n (transfers are grouped into %d characters)\r\n", TRANSFER_SIZE ); 00031 00032 my_nrf24l01p.setTransferSize( TRANSFER_SIZE ); 00033 00034 my_nrf24l01p.setReceiveMode(); 00035 my_nrf24l01p.enable(); 00036 00037 while (1) { 00038 00039 // If we've received anything over the host serial link... 00040 if ( pc.readable() ) { 00041 00042 // ...add it to the transmit buffer 00043 txData[txDataCnt++] = pc.getc(); 00044 00045 // If the transmit buffer is full 00046 if ( txDataCnt >= sizeof( txData ) ) { 00047 00048 // Send the transmitbuffer via the nRF24L01+ 00049 my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt ); 00050 00051 txDataCnt = 0; 00052 } 00053 } 00054 00055 // If we've received anything in the nRF24L01+... 00056 if ( my_nrf24l01p.readable() ) { 00057 00058 // ...read the data into the receive buffer 00059 rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, rxData, sizeof( rxData ) ); 00060 00061 // Display the receive buffer contents via the host serial link 00062 for ( int i = 0; rxDataCnt > 0; rxDataCnt--, i++ ) { 00063 00064 pc.putc( rxData[i] ); 00065 } 00066 } 00067 } 00068 }
Generated on Wed Jul 13 2022 21:22:33 by
1.7.2