this is full duplex led on/off involving 2 FRDM-KL25Z which act as trans recievers

Dependencies:   mbed nRF24L01P

Committer:
mrbhatter
Date:
Thu May 30 12:49:34 2019 +0000
Revision:
1:f97915cf7a69
Parent:
0:ec3b5f850a28
Child:
2:f3f30833fd01
NEW CODE# NRF

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mrbhatter 0:ec3b5f850a28 1 #include "mbed.h"
mrbhatter 0:ec3b5f850a28 2 #include "nRF24L01P.h"
mrbhatter 0:ec3b5f850a28 3
mrbhatter 0:ec3b5f850a28 4 Serial pc(USBTX, USBRX); // tx, rx
mrbhatter 0:ec3b5f850a28 5
mrbhatter 0:ec3b5f850a28 6 nRF24L01P my_nrf24l01p(PTD2, PTD3, PTD1, PTD0, PTD5, PTD4); // MOSI, MISO, SCK, CSN, CE, IRQ
mrbhatter 0:ec3b5f850a28 7 DigitalOut GreenLED(PTA12);
mrbhatter 0:ec3b5f850a28 8
mrbhatter 0:ec3b5f850a28 9
mrbhatter 0:ec3b5f850a28 10 int main() {
mrbhatter 0:ec3b5f850a28 11
mrbhatter 0:ec3b5f850a28 12 char count[2];
mrbhatter 0:ec3b5f850a28 13 char RxDataCnt;
mrbhatter 0:ec3b5f850a28 14 char temp;
mrbhatter 0:ec3b5f850a28 15
mrbhatter 0:ec3b5f850a28 16 my_nrf24l01p.powerUp();
mrbhatter 1:f97915cf7a69 17 my_nrf24l01p.setRfFrequency(2411);
mrbhatter 0:ec3b5f850a28 18
mrbhatter 0:ec3b5f850a28 19 // Display the (default) setup of the nRF24L01+ chip
mrbhatter 0:ec3b5f850a28 20 pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() );
mrbhatter 0:ec3b5f850a28 21 pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() );
mrbhatter 0:ec3b5f850a28 22 pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() );
mrbhatter 0:ec3b5f850a28 23 pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() );
mrbhatter 0:ec3b5f850a28 24 pc.printf( "nRF24L01+ RX Address : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() );
mrbhatter 0:ec3b5f850a28 25
mrbhatter 0:ec3b5f850a28 26 pc.printf( "Simple 2 Byte Receiver\r\n" );
mrbhatter 0:ec3b5f850a28 27
mrbhatter 0:ec3b5f850a28 28 RxDataCnt = 2;
mrbhatter 0:ec3b5f850a28 29 my_nrf24l01p.setTransferSize( RxDataCnt );
mrbhatter 0:ec3b5f850a28 30
mrbhatter 0:ec3b5f850a28 31 my_nrf24l01p.setReceiveMode();
mrbhatter 0:ec3b5f850a28 32 my_nrf24l01p.enable();
mrbhatter 0:ec3b5f850a28 33
mrbhatter 0:ec3b5f850a28 34 while (1) {
mrbhatter 0:ec3b5f850a28 35
mrbhatter 0:ec3b5f850a28 36 // If we've received anything in the nRF24L01+...
mrbhatter 0:ec3b5f850a28 37 if ( my_nrf24l01p.readable() ) {
mrbhatter 0:ec3b5f850a28 38
mrbhatter 0:ec3b5f850a28 39 // ...read the data into the receive buffer
mrbhatter 0:ec3b5f850a28 40 temp = my_nrf24l01p.read( NRF24L01P_PIPE_P0, count, RxDataCnt );
mrbhatter 0:ec3b5f850a28 41
mrbhatter 0:ec3b5f850a28 42
mrbhatter 0:ec3b5f850a28 43 pc.printf( "Cnt %d = %d %d\r\n",temp,count[0],count[1]);
mrbhatter 0:ec3b5f850a28 44
mrbhatter 0:ec3b5f850a28 45
mrbhatter 0:ec3b5f850a28 46 // Toggle LED2 (to help debug nRF24L01+ -> Host communication)
mrbhatter 0:ec3b5f850a28 47 GreenLED = !GreenLED;
mrbhatter 0:ec3b5f850a28 48 wait_ms(10);
mrbhatter 0:ec3b5f850a28 49 }
mrbhatter 0:ec3b5f850a28 50 }
mrbhatter 0:ec3b5f850a28 51 }