test

Dependencies:   mbed nRF24L01P

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Transmitter.cpp Source File

Transmitter.cpp

00001 #include "mbed.h"
00002 #include "nRF24L01P.h"
00003 
00004 Serial pc(USBTX, USBRX); // tx, rx
00005 
00006 nRF24L01P my_nrf24l01p(PTD6, PTE3, PTE2, PTB8, PTB9, PTD0);    // mosi, miso, sck, csn, ce, irq
00007 DigitalOut RedLED(LED1);
00008 
00009 int main()
00010 {
00011     char count[2];
00012     char TxDataCnt;
00013     char temp;
00014 
00015 
00016     my_nrf24l01p.powerUp();
00017     my_nrf24l01p.setRfFrequency(2410);
00018 
00019     // Display the (default) setup of the nRF24L01+ chip
00020     pc.printf( "nRF24L01+ Frequency    : %d MHz\r\n",  my_nrf24l01p.getRfFrequency() );
00021     pc.printf( "nRF24L01+ Output power : %d dBm\r\n",  my_nrf24l01p.getRfOutputPower() );
00022     pc.printf( "nRF24L01+ Data Rate    : %d kbps\r\n", my_nrf24l01p.getAirDataRate() );
00023     pc.printf( "nRF24L01+ TX Address   : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() );
00024     pc.printf( "nRF24L01+ RX Address   : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() );
00025 
00026     pc.printf( "Simple Transmitter (0 - 9 Counter) \r\n");
00027 
00028     TxDataCnt = 2;
00029     my_nrf24l01p.setTransferSize(TxDataCnt);
00030 
00031     my_nrf24l01p.enable();
00032 
00033     count[0] = 0x01;
00034     count[1] = 0x01;
00035 
00036     while (1) {
00037 
00038         // Send the Transmit buffer via the nRF24L01+
00039         temp = my_nrf24l01p.write( NRF24L01P_PIPE_P0,count, TxDataCnt );
00040 
00041         pc.printf( "Sending %d - %d %d\r\n",temp,count[0],count[1]);
00042 
00043         // Toggle LED1 (to help debug Host -> nRF24L01+ communication)
00044         RedLED = !RedLED;
00045             
00046         count[1]++;
00047         
00048         wait(1);
00049     }
00050 }