code

Dependencies:   mbed temp_sensor

Fork of nRF24L01P_Hello_World by Owen Edwards

Committer:
thorb3n
Date:
Tue Dec 22 12:46:12 2015 +0000
Revision:
2:ec74a752a796
Parent:
1:5be2682710c6
hi

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Owen 0:a51a6e7da590 1 #include "mbed.h"
Owen 0:a51a6e7da590 2
thorb3n 2:ec74a752a796 3 #define IWDG_START 0x0000CCCC
thorb3n 2:ec74a752a796 4 #define IWDG_WRITE_ACCESS 0x00005555
thorb3n 2:ec74a752a796 5 #define IWDG_PR_PR_0 7
thorb3n 2:ec74a752a796 6 #define IWDG_RELOAD 512*60
thorb3n 2:ec74a752a796 7 #define IWDG_REFRESH 0xAAAA
thorb3n 2:ec74a752a796 8 DigitalOut myled(LED1);
thorb3n 2:ec74a752a796 9 #include "nRF24L01P.h"
thorb3n 2:ec74a752a796 10 DigitalOut pwr(D2);
thorb3n 2:ec74a752a796 11 Serial pc(USBTX, USBRX); // tx, rx
thorb3n 2:ec74a752a796 12 #define TRANSFER_SIZE 1
thorb3n 2:ec74a752a796 13 int main()
thorb3n 2:ec74a752a796 14 {
thorb3n 2:ec74a752a796 15 pwr = 1;
thorb3n 2:ec74a752a796 16 wait(2);
thorb3n 2:ec74a752a796 17 nRF24L01P my_nrf24l01p(D4,D5,D3,D10,D8,D9); // mosi, miso, sck, csn, ce, irq
Owen 0:a51a6e7da590 18
thorb3n 2:ec74a752a796 19 char txData[TRANSFER_SIZE];
Owen 0:a51a6e7da590 20 int txDataCnt = 0;
thorb3n 2:ec74a752a796 21 txData[0] = 2;
thorb3n 2:ec74a752a796 22 txDataCnt = 2;
thorb3n 2:ec74a752a796 23 my_nrf24l01p.powerUp();
thorb3n 2:ec74a752a796 24 my_nrf24l01p.setAirDataRate(250);
thorb3n 2:ec74a752a796 25 my_nrf24l01p.setTxAddress(0xE7E7E7E7E1,5);
thorb3n 2:ec74a752a796 26 my_nrf24l01p.setRxAddress(0xE7E7E7E7E7,5,0);
Owen 0:a51a6e7da590 27
thorb3n 2:ec74a752a796 28 #ifdef DEBUG
Owen 0:a51a6e7da590 29 // Display the (default) setup of the nRF24L01+ chip
Owen 0:a51a6e7da590 30 pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() );
Owen 0:a51a6e7da590 31 pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() );
Owen 0:a51a6e7da590 32 pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() );
Owen 0:a51a6e7da590 33 pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() );
Owen 0:a51a6e7da590 34 pc.printf( "nRF24L01+ RX Address : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() );
thorb3n 2:ec74a752a796 35 #endif
Owen 0:a51a6e7da590 36 my_nrf24l01p.setTransferSize( TRANSFER_SIZE );
thorb3n 2:ec74a752a796 37 my_nrf24l01p.setTransmitMode();
Owen 0:a51a6e7da590 38 my_nrf24l01p.enable();
thorb3n 2:ec74a752a796 39 #ifdef DEBUG
thorb3n 2:ec74a752a796 40 IWDG->KR=IWDG_START;
thorb3n 2:ec74a752a796 41 wait(5);
thorb3n 2:ec74a752a796 42 IWDG->KR=IWDG_WRITE_ACCESS;
thorb3n 2:ec74a752a796 43 IWDG->PR=IWDG_PR_PR_0;
thorb3n 2:ec74a752a796 44 IWDG->RLR=IWDG_RELOAD;
thorb3n 2:ec74a752a796 45 while(IWDG->SR) {
thorb3n 2:ec74a752a796 46 wait(0.1);
thorb3n 2:ec74a752a796 47 }
thorb3n 2:ec74a752a796 48 pc.printf("Starte");
thorb3n 2:ec74a752a796 49 pc.printf("sende");
thorb3n 2:ec74a752a796 50 pc.printf("%d",txData[0]);
thorb3n 2:ec74a752a796 51 #endif
thorb3n 2:ec74a752a796 52 my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt );
thorb3n 2:ec74a752a796 53 IWDG->KR=IWDG_REFRESH;
thorb3n 2:ec74a752a796 54 deepsleep();
Owen 0:a51a6e7da590 55
Owen 0:a51a6e7da590 56
thorb3n 2:ec74a752a796 57 }
Owen 0:a51a6e7da590 58