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_TX by
Transmitter.cpp@1:c5c9925140b7, 2016-06-04 (annotated)
- Committer:
- SIT2016
- Date:
- Sat Jun 04 05:34:31 2016 +0000
- Revision:
- 1:c5c9925140b7
- Parent:
- 0:19a03658bf70
Basic NRF Transmitter on IOT shield.
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| ganeshgore | 0:19a03658bf70 | 1 | #include "mbed.h" | 
| ganeshgore | 0:19a03658bf70 | 2 | #include "nRF24L01P.h" | 
| ganeshgore | 0:19a03658bf70 | 3 | |
| ganeshgore | 0:19a03658bf70 | 4 | Serial pc(USBTX, USBRX); // tx, rx | 
| ganeshgore | 0:19a03658bf70 | 5 | |
| SIT2016 | 1:c5c9925140b7 | 6 | nRF24L01P my_nrf24l01p(PTD2, PTD3, PTD1, PTD0, PTD5, PTD4); // mosi, miso, sck, csn, ce, irq | 
| SIT2016 | 1:c5c9925140b7 | 7 | DigitalOut RedLED(PTA5); | 
| ganeshgore | 0:19a03658bf70 | 8 | |
| ganeshgore | 0:19a03658bf70 | 9 | int main() | 
| ganeshgore | 0:19a03658bf70 | 10 | { | 
| ganeshgore | 0:19a03658bf70 | 11 | char count[2]; | 
| ganeshgore | 0:19a03658bf70 | 12 | char TxDataCnt; | 
| ganeshgore | 0:19a03658bf70 | 13 | char temp; | 
| ganeshgore | 0:19a03658bf70 | 14 | |
| ganeshgore | 0:19a03658bf70 | 15 | |
| ganeshgore | 0:19a03658bf70 | 16 | my_nrf24l01p.powerUp(); | 
| ganeshgore | 0:19a03658bf70 | 17 | my_nrf24l01p.setRfFrequency(2410); | 
| ganeshgore | 0:19a03658bf70 | 18 | |
| ganeshgore | 0:19a03658bf70 | 19 | // Display the (default) setup of the nRF24L01+ chip | 
| ganeshgore | 0:19a03658bf70 | 20 | pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() ); | 
| ganeshgore | 0:19a03658bf70 | 21 | pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() ); | 
| ganeshgore | 0:19a03658bf70 | 22 | pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() ); | 
| ganeshgore | 0:19a03658bf70 | 23 | pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() ); | 
| ganeshgore | 0:19a03658bf70 | 24 | pc.printf( "nRF24L01+ RX Address : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() ); | 
| ganeshgore | 0:19a03658bf70 | 25 | |
| ganeshgore | 0:19a03658bf70 | 26 | pc.printf( "Simple Transmitter (0 - 9 Counter) \r\n"); | 
| ganeshgore | 0:19a03658bf70 | 27 | |
| ganeshgore | 0:19a03658bf70 | 28 | TxDataCnt = 2; | 
| ganeshgore | 0:19a03658bf70 | 29 | my_nrf24l01p.setTransferSize(TxDataCnt); | 
| ganeshgore | 0:19a03658bf70 | 30 | |
| ganeshgore | 0:19a03658bf70 | 31 | my_nrf24l01p.enable(); | 
| ganeshgore | 0:19a03658bf70 | 32 | |
| ganeshgore | 0:19a03658bf70 | 33 | count[0] = 0x01; | 
| ganeshgore | 0:19a03658bf70 | 34 | count[1] = 0x01; | 
| ganeshgore | 0:19a03658bf70 | 35 | |
| ganeshgore | 0:19a03658bf70 | 36 | while (1) { | 
| ganeshgore | 0:19a03658bf70 | 37 | |
| ganeshgore | 0:19a03658bf70 | 38 | // Send the Transmit buffer via the nRF24L01+ | 
| ganeshgore | 0:19a03658bf70 | 39 | temp = my_nrf24l01p.write( NRF24L01P_PIPE_P0,count, TxDataCnt ); | 
| ganeshgore | 0:19a03658bf70 | 40 | |
| ganeshgore | 0:19a03658bf70 | 41 | pc.printf( "Sending %d - %d %d\r\n",temp,count[0],count[1]); | 
| ganeshgore | 0:19a03658bf70 | 42 | |
| ganeshgore | 0:19a03658bf70 | 43 | // Toggle LED1 (to help debug Host -> nRF24L01+ communication) | 
| ganeshgore | 0:19a03658bf70 | 44 | RedLED = !RedLED; | 
| ganeshgore | 0:19a03658bf70 | 45 | |
| ganeshgore | 0:19a03658bf70 | 46 | count[1]++; | 
| ganeshgore | 0:19a03658bf70 | 47 | |
| ganeshgore | 0:19a03658bf70 | 48 | wait(1); | 
| ganeshgore | 0:19a03658bf70 | 49 | } | 
| ganeshgore | 0:19a03658bf70 | 50 | } | 
