![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Simple SX1272 Test Application
main.cpp@0:7e7575bda256, 2017-04-21 (annotated)
- Committer:
- mick_ccc
- Date:
- Fri Apr 21 15:36:26 2017 +0000
- Revision:
- 0:7e7575bda256
- Child:
- 1:4c82bff12ad0
Simple SX1272 Test Application
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mick_ccc | 0:7e7575bda256 | 1 | #include "mbed.h" |
mick_ccc | 0:7e7575bda256 | 2 | |
mick_ccc | 0:7e7575bda256 | 3 | #include "board.h" |
mick_ccc | 0:7e7575bda256 | 4 | #include "radio.h" |
mick_ccc | 0:7e7575bda256 | 5 | |
mick_ccc | 0:7e7575bda256 | 6 | Serial pc(USBTX, USBRX); // tx, rx |
mick_ccc | 0:7e7575bda256 | 7 | |
mick_ccc | 0:7e7575bda256 | 8 | InterruptIn DatarateButton(USER_BUTTON); |
mick_ccc | 0:7e7575bda256 | 9 | |
mick_ccc | 0:7e7575bda256 | 10 | static uint8_t LoRaMacBuffer[255]; |
mick_ccc | 0:7e7575bda256 | 11 | |
mick_ccc | 0:7e7575bda256 | 12 | uint32_t TxFreq; |
mick_ccc | 0:7e7575bda256 | 13 | uint8_t CurrentDatarate = 12; |
mick_ccc | 0:7e7575bda256 | 14 | bool ButtonPressed = false; |
mick_ccc | 0:7e7575bda256 | 15 | |
mick_ccc | 0:7e7575bda256 | 16 | /* -------------- */ |
mick_ccc | 0:7e7575bda256 | 17 | |
mick_ccc | 0:7e7575bda256 | 18 | void UserButtonPressed( void ) |
mick_ccc | 0:7e7575bda256 | 19 | { |
mick_ccc | 0:7e7575bda256 | 20 | if( CurrentDatarate == 7 ) |
mick_ccc | 0:7e7575bda256 | 21 | { |
mick_ccc | 0:7e7575bda256 | 22 | CurrentDatarate = 12; |
mick_ccc | 0:7e7575bda256 | 23 | } |
mick_ccc | 0:7e7575bda256 | 24 | else |
mick_ccc | 0:7e7575bda256 | 25 | { |
mick_ccc | 0:7e7575bda256 | 26 | CurrentDatarate -= 1; |
mick_ccc | 0:7e7575bda256 | 27 | } |
mick_ccc | 0:7e7575bda256 | 28 | |
mick_ccc | 0:7e7575bda256 | 29 | ButtonPressed = true; |
mick_ccc | 0:7e7575bda256 | 30 | } |
mick_ccc | 0:7e7575bda256 | 31 | |
mick_ccc | 0:7e7575bda256 | 32 | /* -------------- */ |
mick_ccc | 0:7e7575bda256 | 33 | |
mick_ccc | 0:7e7575bda256 | 34 | int main() { |
mick_ccc | 0:7e7575bda256 | 35 | pc.printf("HelLoRa !\n"); |
mick_ccc | 0:7e7575bda256 | 36 | |
mick_ccc | 0:7e7575bda256 | 37 | // Get USER button pressed |
mick_ccc | 0:7e7575bda256 | 38 | DatarateButton.fall( &UserButtonPressed ); |
mick_ccc | 0:7e7575bda256 | 39 | |
mick_ccc | 0:7e7575bda256 | 40 | // Radio board init |
mick_ccc | 0:7e7575bda256 | 41 | BoardInit( ); |
mick_ccc | 0:7e7575bda256 | 42 | |
mick_ccc | 0:7e7575bda256 | 43 | while( 1 ) |
mick_ccc | 0:7e7575bda256 | 44 | { |
mick_ccc | 0:7e7575bda256 | 45 | if( ButtonPressed == true ) |
mick_ccc | 0:7e7575bda256 | 46 | { |
mick_ccc | 0:7e7575bda256 | 47 | // Send one packet |
mick_ccc | 0:7e7575bda256 | 48 | TxFreq = 868100000; |
mick_ccc | 0:7e7575bda256 | 49 | Radio.SetChannel( TxFreq ); |
mick_ccc | 0:7e7575bda256 | 50 | Radio.SetTxConfig( MODEM_LORA, 14, 0, 0, CurrentDatarate, 1, 8, false, true, 0, 0, false, 3e3 ); |
mick_ccc | 0:7e7575bda256 | 51 | Radio.Send( LoRaMacBuffer, 10 ); |
mick_ccc | 0:7e7575bda256 | 52 | pc.printf( "LoRa packet: Freq=%u, SF%u\n", TxFreq, CurrentDatarate ); |
mick_ccc | 0:7e7575bda256 | 53 | |
mick_ccc | 0:7e7575bda256 | 54 | // Stop sending |
mick_ccc | 0:7e7575bda256 | 55 | ButtonPressed = false; |
mick_ccc | 0:7e7575bda256 | 56 | } |
mick_ccc | 0:7e7575bda256 | 57 | } |
mick_ccc | 0:7e7575bda256 | 58 | |
mick_ccc | 0:7e7575bda256 | 59 | return 0; |
mick_ccc | 0:7e7575bda256 | 60 | } |
mick_ccc | 0:7e7575bda256 | 61 |