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 testuC by
main.cpp@2:0b023bf05e0d, 2016-01-05 (annotated)
- Committer:
- thorb3n
- Date:
- Tue Jan 05 15:12:38 2016 +0000
- Revision:
- 2:0b023bf05e0d
- Parent:
- 1:5be2682710c6
FERTIG;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Owen | 0:a51a6e7da590 | 1 | #include "mbed.h" |
| Owen | 0:a51a6e7da590 | 2 | #include "nRF24L01P.h" |
| thorb3n | 2:0b023bf05e0d | 3 | #define IWDG_START 0x0000CCCC |
| thorb3n | 2:0b023bf05e0d | 4 | #define IWDG_WRITE_ACCESS 0x00005555 |
| thorb3n | 2:0b023bf05e0d | 5 | #define IWDG_PR_PR_0 7 |
| thorb3n | 2:0b023bf05e0d | 6 | #define IWDG_RELOAD 512*100 |
| thorb3n | 2:0b023bf05e0d | 7 | #define IWDG_REFRESH 0xAAAA |
| Owen | 0:a51a6e7da590 | 8 | Serial pc(USBTX, USBRX); // tx, rx |
| Owen | 0:a51a6e7da590 | 9 | |
| thorb3n | 2:0b023bf05e0d | 10 | nRF24L01P my_nrf24l01p(D4,D5,D3,D10,D8,D9); // mosi, miso, sck, csn, ce, irq |
| thorb3n | 2:0b023bf05e0d | 11 | |
| Owen | 0:a51a6e7da590 | 12 | |
| thorb3n | 2:0b023bf05e0d | 13 | int main() |
| thorb3n | 2:0b023bf05e0d | 14 | { |
| thorb3n | 2:0b023bf05e0d | 15 | // |
| thorb3n | 2:0b023bf05e0d | 16 | // pLATHALTER FÜR ANSHCALTEN ÜBER GPIO |
| thorb3n | 2:0b023bf05e0d | 17 | // |
| thorb3n | 2:0b023bf05e0d | 18 | |
| Owen | 0:a51a6e7da590 | 19 | // The nRF24L01+ supports transfers from 1 to 32 bytes, but Sparkfun's |
| Owen | 0:a51a6e7da590 | 20 | // "Nordic Serial Interface Board" (http://www.sparkfun.com/products/9019) |
| Owen | 0:a51a6e7da590 | 21 | // only handles 4 byte transfers in the ATMega code. |
| thorb3n | 2:0b023bf05e0d | 22 | #define TRANSFER_SIZE 2 |
| Owen | 0:a51a6e7da590 | 23 | |
| Owen | 0:a51a6e7da590 | 24 | char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE]; |
| Owen | 0:a51a6e7da590 | 25 | int txDataCnt = 0; |
| Owen | 0:a51a6e7da590 | 26 | int rxDataCnt = 0; |
| Owen | 0:a51a6e7da590 | 27 | |
| Owen | 0:a51a6e7da590 | 28 | my_nrf24l01p.powerUp(); |
| thorb3n | 2:0b023bf05e0d | 29 | my_nrf24l01p.setAirDataRate(250); |
| thorb3n | 2:0b023bf05e0d | 30 | my_nrf24l01p.setTxAddress(0xE7E7E7E7E1,5); |
| thorb3n | 2:0b023bf05e0d | 31 | my_nrf24l01p.setRxAddress(0xE7E7E7E7E7,5,0); |
| Owen | 0:a51a6e7da590 | 32 | // Display the (default) setup of the nRF24L01+ chip |
| Owen | 0:a51a6e7da590 | 33 | pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() ); |
| Owen | 0:a51a6e7da590 | 34 | pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() ); |
| Owen | 0:a51a6e7da590 | 35 | pc.printf( "nRF24L01+ Data Rate : %d kbps\r\n", my_nrf24l01p.getAirDataRate() ); |
| Owen | 0:a51a6e7da590 | 36 | pc.printf( "nRF24L01+ TX Address : 0x%010llX\r\n", my_nrf24l01p.getTxAddress() ); |
| Owen | 0:a51a6e7da590 | 37 | pc.printf( "nRF24L01+ RX Address : 0x%010llX\r\n", my_nrf24l01p.getRxAddress() ); |
| Owen | 0:a51a6e7da590 | 38 | |
| Owen | 0:a51a6e7da590 | 39 | pc.printf( "Type keys to test transfers:\r\n (transfers are grouped into %d characters)\r\n", TRANSFER_SIZE ); |
| Owen | 0:a51a6e7da590 | 40 | |
| Owen | 0:a51a6e7da590 | 41 | my_nrf24l01p.setTransferSize( TRANSFER_SIZE ); |
| Owen | 0:a51a6e7da590 | 42 | |
| thorb3n | 2:0b023bf05e0d | 43 | my_nrf24l01p.setTransmitMode(); |
| Owen | 0:a51a6e7da590 | 44 | my_nrf24l01p.enable(); |
| thorb3n | 2:0b023bf05e0d | 45 | txData[1] = 2; |
| thorb3n | 2:0b023bf05e0d | 46 | txData[0] = 23; |
| thorb3n | 2:0b023bf05e0d | 47 | txDataCnt =1; |
| thorb3n | 2:0b023bf05e0d | 48 | IWDG->KR=IWDG_START; |
| thorb3n | 2:0b023bf05e0d | 49 | IWDG->KR=IWDG_WRITE_ACCESS; |
| thorb3n | 2:0b023bf05e0d | 50 | IWDG->PR=IWDG_PR_PR_0; |
| thorb3n | 2:0b023bf05e0d | 51 | IWDG->RLR=IWDG_RELOAD; |
| thorb3n | 2:0b023bf05e0d | 52 | while(IWDG->SR) { |
| thorb3n | 2:0b023bf05e0d | 53 | wait(0.1); |
| thorb3n | 2:0b023bf05e0d | 54 | } |
| thorb3n | 2:0b023bf05e0d | 55 | my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt ); |
| thorb3n | 2:0b023bf05e0d | 56 | wait(1); |
| thorb3n | 2:0b023bf05e0d | 57 | IWDG->KR=IWDG_REFRESH; /* (6) */ |
| thorb3n | 2:0b023bf05e0d | 58 | pc.printf("go to sleep"); |
| thorb3n | 2:0b023bf05e0d | 59 | deepsleep(); |
| Owen | 0:a51a6e7da590 | 60 | while (1) { |
| Owen | 0:a51a6e7da590 | 61 | |
| thorb3n | 2:0b023bf05e0d | 62 | /* |
| Owen | 0:a51a6e7da590 | 63 | // If we've received anything over the host serial link... |
| Owen | 0:a51a6e7da590 | 64 | if ( pc.readable() ) { |
| Owen | 0:a51a6e7da590 | 65 | |
| Owen | 0:a51a6e7da590 | 66 | // ...add it to the transmit buffer |
| Owen | 0:a51a6e7da590 | 67 | txData[txDataCnt++] = pc.getc(); |
| Owen | 0:a51a6e7da590 | 68 | |
| Owen | 0:a51a6e7da590 | 69 | // If the transmit buffer is full |
| Owen | 0:a51a6e7da590 | 70 | if ( txDataCnt >= sizeof( txData ) ) { |
| Owen | 0:a51a6e7da590 | 71 | |
| Owen | 0:a51a6e7da590 | 72 | // Send the transmitbuffer via the nRF24L01+ |
| Owen | 0:a51a6e7da590 | 73 | my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt ); |
| Owen | 0:a51a6e7da590 | 74 | |
| Owen | 0:a51a6e7da590 | 75 | txDataCnt = 0; |
| Owen | 0:a51a6e7da590 | 76 | } |
| Owen | 0:a51a6e7da590 | 77 | |
| Owen | 0:a51a6e7da590 | 78 | // Toggle LED1 (to help debug Host -> nRF24L01+ communication) |
| thorb3n | 2:0b023bf05e0d | 79 | // myled1 = !myled1; |
| Owen | 0:a51a6e7da590 | 80 | } |
| Owen | 0:a51a6e7da590 | 81 | |
| Owen | 0:a51a6e7da590 | 82 | // If we've received anything in the nRF24L01+... |
| Owen | 0:a51a6e7da590 | 83 | if ( my_nrf24l01p.readable() ) { |
| Owen | 0:a51a6e7da590 | 84 | |
| Owen | 0:a51a6e7da590 | 85 | // ...read the data into the receive buffer |
| Owen | 0:a51a6e7da590 | 86 | rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, rxData, sizeof( rxData ) ); |
| Owen | 0:a51a6e7da590 | 87 | |
| Owen | 0:a51a6e7da590 | 88 | // Display the receive buffer contents via the host serial link |
| Owen | 0:a51a6e7da590 | 89 | for ( int i = 0; rxDataCnt > 0; rxDataCnt--, i++ ) { |
| Owen | 0:a51a6e7da590 | 90 | |
| Owen | 0:a51a6e7da590 | 91 | pc.putc( rxData[i] ); |
| Owen | 0:a51a6e7da590 | 92 | } |
| Owen | 0:a51a6e7da590 | 93 | |
| Owen | 0:a51a6e7da590 | 94 | // Toggle LED2 (to help debug nRF24L01+ -> Host communication) |
| thorb3n | 2:0b023bf05e0d | 95 | //myled2 = !myled2; |
| Owen | 0:a51a6e7da590 | 96 | } |
| thorb3n | 2:0b023bf05e0d | 97 | */ |
| Owen | 0:a51a6e7da590 | 98 | } |
| Owen | 0:a51a6e7da590 | 99 | } |
