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.
Dependencies: BSP_DISCO_L476VG LCD_DISCO_L476VG mbed nRF24L01P
Fork of Final_project_Dom_2TOMS_addChannel123 by
main.cpp@4:dcee65c6cebf, 2018-04-17 (annotated)
- Committer:
- dnaples02
- Date:
- Tue Apr 17 21:33:05 2018 +0000
- Revision:
- 4:dcee65c6cebf
- Parent:
- 3:2544ec35c76f
- Child:
- 5:8d2188479eec
domthetechdudemuthafucka
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" |
| dnaples02 | 3:2544ec35c76f | 3 | #include "LCD_DISCO_L476VG.h" |
| Owen | 0:a51a6e7da590 | 4 | |
| Owen | 0:a51a6e7da590 | 5 | Serial pc(USBTX, USBRX); // tx, rx |
| Owen | 0:a51a6e7da590 | 6 | |
| dnaples02 | 2:9ecf15bfb0b4 | 7 | nRF24L01P my_nrf24l01p(PE_15, PE_14, PE_13, PE_12, PE_10, PE_11); // mosi, miso, sck, csn, ce, irq |
| Owen | 0:a51a6e7da590 | 8 | |
| Owen | 0:a51a6e7da590 | 9 | DigitalOut myled1(LED1); |
| Owen | 0:a51a6e7da590 | 10 | DigitalOut myled2(LED2); |
| dnaples02 | 3:2544ec35c76f | 11 | LCD_DISCO_L476VG lcd; |
| Owen | 0:a51a6e7da590 | 12 | |
| Owen | 0:a51a6e7da590 | 13 | int main() { |
| Owen | 0:a51a6e7da590 | 14 | |
| Owen | 0:a51a6e7da590 | 15 | // The nRF24L01+ supports transfers from 1 to 32 bytes, but Sparkfun's |
| Owen | 0:a51a6e7da590 | 16 | // "Nordic Serial Interface Board" (http://www.sparkfun.com/products/9019) |
| Owen | 0:a51a6e7da590 | 17 | // only handles 4 byte transfers in the ATMega code. |
| Owen | 0:a51a6e7da590 | 18 | #define TRANSFER_SIZE 4 |
| Owen | 0:a51a6e7da590 | 19 | |
| Owen | 0:a51a6e7da590 | 20 | char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE]; |
| Owen | 0:a51a6e7da590 | 21 | int txDataCnt = 0; |
| Owen | 0:a51a6e7da590 | 22 | int rxDataCnt = 0; |
| dnaples02 | 3:2544ec35c76f | 23 | uint32_t temp = 0; |
| dnaples02 | 3:2544ec35c76f | 24 | uint8_t stemp[7] = {0}; |
| dnaples02 | 3:2544ec35c76f | 25 | //uint8_t title[] = " DISCOVERY STM32L476"; |
| Owen | 0:a51a6e7da590 | 26 | my_nrf24l01p.powerUp(); |
| dnaples02 | 3:2544ec35c76f | 27 | |
| Owen | 0:a51a6e7da590 | 28 | |
| 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() ); |
| Owen | 0:a51a6e7da590 | 35 | |
| Owen | 0:a51a6e7da590 | 36 | pc.printf( "Type keys to test transfers:\r\n (transfers are grouped into %d characters)\r\n", TRANSFER_SIZE ); |
| Owen | 0:a51a6e7da590 | 37 | |
| Owen | 0:a51a6e7da590 | 38 | my_nrf24l01p.setTransferSize( TRANSFER_SIZE ); |
| Owen | 0:a51a6e7da590 | 39 | |
| Owen | 0:a51a6e7da590 | 40 | my_nrf24l01p.setReceiveMode(); |
| Owen | 0:a51a6e7da590 | 41 | my_nrf24l01p.enable(); |
| dnaples02 | 3:2544ec35c76f | 42 | |
| dnaples02 | 3:2544ec35c76f | 43 | printf("Hello\n"); |
| dnaples02 | 3:2544ec35c76f | 44 | //led_green = 1; |
| dnaples02 | 3:2544ec35c76f | 45 | lcd.Clear(); |
| dnaples02 | 3:2544ec35c76f | 46 | lcd.DisplayString((uint8_t *)"HELLO"); |
| dnaples02 | 4:dcee65c6cebf | 47 | wait(5); |
| dnaples02 | 4:dcee65c6cebf | 48 | lcd.Clear(); |
| dnaples02 | 4:dcee65c6cebf | 49 | |
| Owen | 0:a51a6e7da590 | 50 | while (1) { |
| Owen | 0:a51a6e7da590 | 51 | |
| Owen | 0:a51a6e7da590 | 52 | // If we've received anything over the host serial link... |
| Owen | 0:a51a6e7da590 | 53 | if ( pc.readable() ) { |
| Owen | 0:a51a6e7da590 | 54 | |
| Owen | 0:a51a6e7da590 | 55 | // ...add it to the transmit buffer |
| dnaples02 | 3:2544ec35c76f | 56 | txData[txDataCnt++] = pc.getc();} |
| Owen | 0:a51a6e7da590 | 57 | |
| Owen | 0:a51a6e7da590 | 58 | // If the transmit buffer is full |
| Owen | 0:a51a6e7da590 | 59 | if ( txDataCnt >= sizeof( txData ) ) { |
| Owen | 0:a51a6e7da590 | 60 | |
| Owen | 0:a51a6e7da590 | 61 | // Send the transmitbuffer via the nRF24L01+ |
| Owen | 0:a51a6e7da590 | 62 | my_nrf24l01p.write( NRF24L01P_PIPE_P0, txData, txDataCnt ); |
| Owen | 0:a51a6e7da590 | 63 | |
| Owen | 0:a51a6e7da590 | 64 | txDataCnt = 0; |
| dnaples02 | 3:2544ec35c76f | 65 | |
| Owen | 0:a51a6e7da590 | 66 | |
| Owen | 0:a51a6e7da590 | 67 | // Toggle LED1 (to help debug Host -> nRF24L01+ communication) |
| Owen | 0:a51a6e7da590 | 68 | myled1 = !myled1; |
| Owen | 0:a51a6e7da590 | 69 | } |
| Owen | 0:a51a6e7da590 | 70 | |
| Owen | 0:a51a6e7da590 | 71 | // If we've received anything in the nRF24L01+... |
| Owen | 0:a51a6e7da590 | 72 | if ( my_nrf24l01p.readable() ) { |
| Owen | 0:a51a6e7da590 | 73 | |
| Owen | 0:a51a6e7da590 | 74 | // ...read the data into the receive buffer |
| Owen | 0:a51a6e7da590 | 75 | rxDataCnt = my_nrf24l01p.read( NRF24L01P_PIPE_P0, rxData, sizeof( rxData ) ); |
| Owen | 0:a51a6e7da590 | 76 | // Display the receive buffer contents via the host serial link |
| Owen | 0:a51a6e7da590 | 77 | for ( int i = 0; rxDataCnt > 0; rxDataCnt--, i++ ) { |
| Owen | 0:a51a6e7da590 | 78 | |
| Owen | 0:a51a6e7da590 | 79 | pc.putc( rxData[i] ); |
| dnaples02 | 4:dcee65c6cebf | 80 | |
| Owen | 0:a51a6e7da590 | 81 | } |
| dnaples02 | 4:dcee65c6cebf | 82 | lcd.Clear(); |
| dnaples02 | 4:dcee65c6cebf | 83 | lcd.DisplayString((uint8_t *)"REC"); |
| dnaples02 | 4:dcee65c6cebf | 84 | wait(5); |
| dnaples02 | 4:dcee65c6cebf | 85 | lcd.Clear(); |
| dnaples02 | 3:2544ec35c76f | 86 | } |
| dnaples02 | 3:2544ec35c76f | 87 | |
| dnaples02 | 3:2544ec35c76f | 88 | |
| dnaples02 | 3:2544ec35c76f | 89 | |
| dnaples02 | 3:2544ec35c76f | 90 | // printf("Scroll sequence\n"); |
| dnaples02 | 3:2544ec35c76f | 91 | //led_green = 0; |
| dnaples02 | 3:2544ec35c76f | 92 | //lcd.Clear(); |
| dnaples02 | 4:dcee65c6cebf | 93 | |
| Owen | 0:a51a6e7da590 | 94 | // Toggle LED2 (to help debug nRF24L01+ -> Host communication) |
| Owen | 0:a51a6e7da590 | 95 | myled2 = !myled2; |
| Owen | 0:a51a6e7da590 | 96 | } |
| Owen | 0:a51a6e7da590 | 97 | } |
| dnaples02 | 3:2544ec35c76f | 98 |
