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 testuC by
main.cpp
00001 #include "mbed.h" 00002 #include "nRF24L01P.h" 00003 #define IWDG_START 0x0000CCCC 00004 #define IWDG_WRITE_ACCESS 0x00005555 00005 #define IWDG_PR_PR_0 7 00006 #define IWDG_RELOAD 512*100 00007 #define IWDG_REFRESH 0xAAAA 00008 Serial pc(USBTX, USBRX); // tx, rx 00009 00010 nRF24L01P my_nrf24l01p(D4,D5,D3,D10,D8,D9); // mosi, miso, sck, csn, ce, irq 00011 00012 00013 int main() 00014 { 00015 // 00016 // pLATHALTER FÜR ANSHCALTEN ÜBER GPIO 00017 // 00018 00019 // The nRF24L01+ supports transfers from 1 to 32 bytes, but Sparkfun's 00020 // "Nordic Serial Interface Board" (http://www.sparkfun.com/products/9019) 00021 // only handles 4 byte transfers in the ATMega code. 00022 #define TRANSFER_SIZE 2 00023 00024 char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE]; 00025 int txDataCnt = 0; 00026 int rxDataCnt = 0; 00027 00028 my_nrf24l01p.powerUp(); 00029 my_nrf24l01p.setAirDataRate(250); 00030 my_nrf24l01p.setTxAddress(0xE7E7E7E7E1,5); 00031 my_nrf24l01p.setRxAddress(0xE7E7E7E7E7,5,0); 00032 // Display the (default) setup of the nRF24L01+ chip 00033 pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() ); 00034 pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() ); 00035 pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() ); 00036 pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() ); 00037 pc.printf( "nRF24L01+ RX Address : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() ); 00038 00039 pc.printf( "Type keys to test transfers:\r\n (transfers are grouped into %d characters)\r\n", TRANSFER_SIZE ); 00040 00041 my_nrf24l01p.setTransferSize( TRANSFER_SIZE ); 00042 00043 my_nrf24l01p.setTransmitMode(); 00044 my_nrf24l01p.enable(); 00045 txData[1] = 2; 00046 txData[0] = 23; 00047 txDataCnt =1; 00048 IWDG->KR=IWDG_START; 00049 IWDG->KR=IWDG_WRITE_ACCESS; 00050 IWDG->PR=IWDG_PR_PR_0; 00051 IWDG->RLR=IWDG_RELOAD; 00052 while(IWDG->SR) { 00053 wait(0.1); 00054 } 00055 my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt ); 00056 wait(1); 00057 IWDG->KR=IWDG_REFRESH; /* (6) */ 00058 pc.printf("go to sleep"); 00059 deepsleep(); 00060 while (1) { 00061 00062 /* 00063 // If we've received anything over the host serial link... 00064 if ( pc.readable() ) { 00065 00066 // ...add it to the transmit buffer 00067 txData[txDataCnt++] = pc.getc(); 00068 00069 // If the transmit buffer is full 00070 if ( txDataCnt >= sizeof( txData ) ) { 00071 00072 // Send the transmitbuffer via the nRF24L01+ 00073 my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt ); 00074 00075 txDataCnt = 0; 00076 } 00077 00078 // Toggle LED1 (to help debug Host -> nRF24L01+ communication) 00079 // myled1 = !myled1; 00080 } 00081 00082 // If we've received anything in the nRF24L01+... 00083 if ( my_nrf24l01p.readable() ) { 00084 00085 // ...read the data into the receive buffer 00086 rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, rxData, sizeof( rxData ) ); 00087 00088 // Display the receive buffer contents via the host serial link 00089 for ( int i = 0; rxDataCnt > 0; rxDataCnt--, i++ ) { 00090 00091 pc.putc( rxData[i] ); 00092 } 00093 00094 // Toggle LED2 (to help debug nRF24L01+ -> Host communication) 00095 //myled2 = !myled2; 00096 } 00097 */ 00098 } 00099 }
Generated on Tue Jul 19 2022 15:01:47 by
1.7.2
