Driver for the SX1276 RF Transceiver

Dependents:   LoRa_PIR LoRaWAN-lmic-app SX1276PingPong LoRaWAN-lmic-app ... more

Files at this revision

API Documentation at this revision

Comitter:
GregCr
Date:
Wed Aug 20 06:29:01 2014 +0000
Parent:
3:ca84be1f3fac
Child:
5:11ec8a6ba4f0
Commit message:
Removed use of LED1 which is causing issues with the SPI on the Nucleo board. Clean up

Changed in this revision

sx1276/sx1276-hal.cpp Show annotated file Show diff for this revision Revisions of this file
sx1276/sx1276-hal.h Show annotated file Show diff for this revision Revisions of this file
sx1276/sx1276.cpp Show annotated file Show diff for this revision Revisions of this file
sx1276/sx1276.h Show annotated file Show diff for this revision Revisions of this file
--- a/sx1276/sx1276-hal.cpp	Tue Aug 19 09:15:01 2014 +0000
+++ b/sx1276/sx1276-hal.cpp	Wed Aug 20 06:29:01 2014 +0000
@@ -13,7 +13,6 @@
 Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin
 */
 #include "sx1276-hal.h"
-#include "debug.h"
 
 const RadioRegisters_t SX1276MB1xAS::RadioRegsInit[] = 
 {                                                 
@@ -102,19 +101,17 @@
 uint8_t SX1276MB1xAS::DetectBoardType( void )
 {
     antSwitch.input( );
-    wait_us( 10 );
+    wait_ms( 1 );
     if( antSwitch == 1 )
     {
         boardConnected = SX1276MB1LAS;
-        debug("\r\n     >>>>>>>>>>>>>SX1276MB1LAS \r\n" );
     }
     else
     {
         boardConnected = SX1276MB1MAS;
-        debug("\r\n     >>>>>>>>>>>>>SX1276MB1MAS \r\n" );
     }
     antSwitch.output( );
-    wait_us( 10 );
+    wait_ms( 1 );
     
     return ( boardConnected );
 }
@@ -136,7 +133,6 @@
 
 void SX1276MB1xAS::SpiInit( void )
 {
-    
     nss = 1;    
     spi.format( 8,0 );   
     uint32_t frequencyToSet = 8000000;
@@ -246,9 +242,10 @@
 
 void SX1276MB1xAS::Reset( void )
 {
+    reset.output();
     reset = 0;
     wait_ms( 1 );
-    reset = 1;
+    reset.input();
     wait_ms( 6 );
 }
     
--- a/sx1276/sx1276-hal.h	Tue Aug 19 09:15:01 2014 +0000
+++ b/sx1276/sx1276-hal.h	Wed Aug 20 06:29:01 2014 +0000
@@ -15,7 +15,6 @@
 #ifndef __SX1276_HAL_H__
 #define __SX1276_HAL_H__
 #include "sx1276.h"
-#include "debug.h"
 
 /*! 
  * Actual implementation of a SX1276 radio, includes some modifications to make it compatible with the MB1 LAS board
@@ -42,7 +41,6 @@
     virtual ~SX1276MB1xAS( ) { };
     
     protected:
-        
     /*!
      * @brief Initializes the radio I/Os pins interface
      */
--- a/sx1276/sx1276.cpp	Tue Aug 19 09:15:01 2014 +0000
+++ b/sx1276/sx1276.cpp	Wed Aug 20 06:29:01 2014 +0000
@@ -14,8 +14,6 @@
 */
 #include "sx1276.h"
 
-#include "debug.h"
-
 const FskBandwidth_t SX1276::FskBandwidths[] =
 {       
     { 2600  , 0x17 },   
@@ -65,6 +63,8 @@
 	this->dioIrq[3] = &SX1276::OnDio3Irq;
 	this->dioIrq[4] = &SX1276::OnDio4Irq;
 	this->dioIrq[5] = NULL;
+	
+	this->settings.State = IDLE;
 }
 
 SX1276::~SX1276( )
@@ -131,7 +131,7 @@
     
     SetOpMode( RF_OPMODE_RECEIVER );
 
-    wait( 0.001 );
+    wait_ms( 1 );
     
     rssi = GetRssi( modem );
     
@@ -170,7 +170,7 @@
 
     for( i = 0; i < 32; i++ )
     {
-        wait( 0.001 );
+        wait_ms( 1 );
         // Unfiltered RSSI value reading. Only takes the LSB value
         rnd |= ( ( uint32_t )Read( REG_LR_RSSIWIDEBAND ) & 0x01 ) << i;
     }
@@ -514,7 +514,7 @@
     {
     case MODEM_FSK:
         {
-            airTime = floor( ( 8 * ( this->settings.Fsk.PreambleLen +
+            airTime = ceil( ( 8 * ( this->settings.Fsk.PreambleLen +
                                      ( ( Read( REG_SYNCCONFIG ) & ~RF_SYNCCONFIG_SYNCSIZE_MASK ) + 1 ) +
                                      ( ( this->settings.Fsk.FixLen == 0x01 ) ? 0.0 : 1.0 ) +
                                      ( ( ( Read( REG_PACKETCONFIG1 ) & ~RF_PACKETCONFIG1_ADDRSFILTERING_MASK ) != 0x00 ) ? 1.0 : 0 ) +
@@ -644,7 +644,7 @@
             if( ( Read( REG_OPMODE ) & ~RF_OPMODE_MASK ) == RF_OPMODE_SLEEP )
             {
                 Standby( );
-                wait( 0.001 );
+                wait_ms( 1 );
             }
             // Write payload buffer
             WriteFifo( buffer, size );
@@ -721,7 +721,7 @@
             Write( REG_LR_IRQFLAGSMASK, //RFLR_IRQFLAGS_RXTIMEOUT |
                                               //RFLR_IRQFLAGS_RXDONE |
                                               //RFLR_IRQFLAGS_PAYLOADCRCERROR |
-                                              //RFLR_IRQFLAGS_VALIDHEADER |
+                                              RFLR_IRQFLAGS_VALIDHEADER |
                                               RFLR_IRQFLAGS_TXDONE |
                                               RFLR_IRQFLAGS_CADDONE |
                                               RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL |
@@ -729,7 +729,6 @@
             
             // DIO0=RxDone
             Write( REG_DIOMAPPING1, ( Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK ) | RFLR_DIOMAPPING1_DIO0_00 );
-            Write( REG_DIOMAPPING1, ( Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO3_MASK ) | RFLR_DIOMAPPING1_DIO3_01 );
             Write( REG_LR_FIFORXBASEADDR, 0 );
             Write( REG_LR_FIFOADDRPTR, 0 );
         }
@@ -865,29 +864,27 @@
 
 void SX1276::SetModem( ModemType modem )
 {
-    if( this->settings.Modem == modem )
-    {
-        return;
-    }
-
-    this->settings.Modem = modem;
-    switch( this->settings.Modem )
+    if( this->settings.Modem != modem )
     {
-    default:
-    case MODEM_FSK:
-        SetOpMode( RF_OPMODE_SLEEP );
-        Write( REG_OPMODE, ( Read( REG_OPMODE ) & RFLR_OPMODE_LONGRANGEMODE_MASK ) | RFLR_OPMODE_LONGRANGEMODE_OFF );
-    
-        Write( REG_DIOMAPPING1, 0x00 );
-        Write( REG_DIOMAPPING2, 0x30 ); // DIO5=ModeReady
-        break;
-    case MODEM_LORA:
-        SetOpMode( RF_OPMODE_SLEEP );
-        Write( REG_OPMODE, ( Read( REG_OPMODE ) & RFLR_OPMODE_LONGRANGEMODE_MASK ) | RFLR_OPMODE_LONGRANGEMODE_ON );
-
-        Write( REG_DIOMAPPING1, 0x00 );
-        Write( REG_DIOMAPPING2, 0x00 );
-        break;
+	    this->settings.Modem = modem;
+	    switch( this->settings.Modem )
+	    {
+	    default:
+	    case MODEM_FSK:
+	        SetOpMode( RF_OPMODE_SLEEP );
+	        Write( REG_OPMODE, ( Read( REG_OPMODE ) & RFLR_OPMODE_LONGRANGEMODE_MASK ) | RFLR_OPMODE_LONGRANGEMODE_OFF );
+	    
+	        Write( REG_DIOMAPPING1, 0x00 );
+	        Write( REG_DIOMAPPING2, 0x30 ); // DIO5=ModeReady
+	        break;
+	    case MODEM_LORA:
+	        SetOpMode( RF_OPMODE_SLEEP );
+	        Write( REG_OPMODE, ( Read( REG_OPMODE ) & RFLR_OPMODE_LONGRANGEMODE_MASK ) | RFLR_OPMODE_LONGRANGEMODE_ON );
+	
+	        Write( REG_DIOMAPPING1, 0x00 );
+	        Write( REG_DIOMAPPING2, 0x00 );
+	        break;
+	    }
     }
 }
 
@@ -1055,7 +1052,7 @@
                         }
                         rxTimeoutTimer.detach( );
 
-                        if( (rxError != NULL ) )
+                        if( ( rxError != NULL ) )
                         {
                             rxError( ); 
                         }
--- a/sx1276/sx1276.h	Tue Aug 19 09:15:01 2014 +0000
+++ b/sx1276/sx1276.h	Wed Aug 20 06:29:01 2014 +0000
@@ -55,7 +55,7 @@
     /*!
      * SX1276 Reset pin
      */
-    DigitalOut reset;
+    DigitalInOut reset;
 
     /*!
      * SX1276 DIO pins