D RAO
/
kl25Z_nRF_TX
dd
Fork of kl25Z_nRF_TX by
Transmitter.cpp@2:8ea3931ff17a, 2017-12-13 (annotated)
- Committer:
- sivanand
- Date:
- Wed Dec 13 06:26:52 2017 +0000
- Revision:
- 2:8ea3931ff17a
- Parent:
- 1:c5c9925140b7
updated
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 | { |
sivanand | 2:8ea3931ff17a | 11 | char count[1]; |
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(); |
sivanand | 2:8ea3931ff17a | 17 | my_nrf24l01p.setRfFrequency(2404); |
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 | |
sivanand | 2:8ea3931ff17a | 28 | TxDataCnt = 1; |
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; |
sivanand | 2:8ea3931ff17a | 34 | |
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 | |
sivanand | 2:8ea3931ff17a | 46 | count[0]++; |
ganeshgore | 0:19a03658bf70 | 47 | |
ganeshgore | 0:19a03658bf70 | 48 | wait(1); |
ganeshgore | 0:19a03658bf70 | 49 | } |
ganeshgore | 0:19a03658bf70 | 50 | } |