Mick Mick
/
SX1272_TestApp
Simple SX1272 Test Application
main.cpp
- Committer:
- mick_ccc
- Date:
- 2017-04-24
- Revision:
- 1:4c82bff12ad0
- Parent:
- 0:7e7575bda256
- Child:
- 2:61713a461cf1
File content as of revision 1:4c82bff12ad0:
#include "mbed.h" #include "board.h" #include "radio.h" Serial pc(USBTX, USBRX); // tx, rx InterruptIn DatarateButton(USER_BUTTON); // Global variables static uint8_t LoRaWANBuffer[255]; static uint16_t FCnt = 0; // ISR variables static volatile bool SingleDatarate = true; static volatile uint8_t CurrentDatarate = 12; static volatile bool ButtonPressed = false; /* -------------- */ void UserButtonPressed( void ) { if( SingleDatarate == false ) { // Increase datarate by 1 CurrentDatarate = (CurrentDatarate == 7) ? 12 : CurrentDatarate-1; } ButtonPressed = true; } /* -------------- */ int main() { Timer t; uint32_t TxFreq; pc.printf("HelLo Ra !\n"); // Get USER button pressed DatarateButton.fall( &UserButtonPressed ); // Radio board init BoardInit( ); while( 1 ) { if( ButtonPressed == true ) { // Configure radio TxFreq = 867720000; Radio.SetChannel( TxFreq ); Radio.Write( REG_LR_SYNCWORD, 0x34 ); // public: to be replaced with SetPublicNetwork() when available Radio.SetTxConfig( MODEM_LORA, 14, 0, 0, CurrentDatarate, 1, 8, false, true, 0, 0, false, 3e3 ); // Set packet payload //LoRaWANBuffer[0] = 0x40; // Unconfirmed Data Up LoRaWANBuffer[0] = 0x80; // Confirmed Data Up LoRaWANBuffer[1] = 0x03; // DevAddr LoRaWANBuffer[2] = 0x00; LoRaWANBuffer[3] = 0xFE; LoRaWANBuffer[4] = 0xCA; LoRaWANBuffer[5] = 0x0; // FCtrl LoRaWANBuffer[6] = FCnt; LoRaWANBuffer[7] = FCnt >> 8; LoRaWANBuffer[8] = 1; // FPort LoRaWANBuffer[9] = 0x0; // FRMPayload // Send packet Radio.Send( LoRaWANBuffer, 14 ); FCnt += 1; pc.printf( "LoRa packet: Freq=%u, SF%u\n", TxFreq, CurrentDatarate ); // Stop sending ButtonPressed = false; } } }