LowPowerLab Forum

Software support => Wireless Programming (aka OTA) => Topic started by: Camerart on October 22, 2016, 07:08:37 AM

Title: Programming SX1276 modules in Basic
Post by: Camerart on October 22, 2016, 07:08:37 AM
Hi,
Can anyone help with programming SX1276 modules please?

I work in BASIC, so perhaps a more general answer would be better. 

I need to know first, if when these modules are switched on, are the default settings shown in the data sheet loaded, then if any need changing, then send changes to the registry settings?

Regards, C.
Title: Re: Programming SX1276 modules
Post by: raggedyanne on October 23, 2016, 05:21:08 AM
QuoteAre the default settings shown in the data sheet loaded?
Yes, defaults are loaded until changed by user.

Quotethen send changes to the registry settings
Yes you must modify the internal registers.

In order to change most settings you must either put the module into standby or sleep mode, here is a snippet;
Write(RegOpMode, 0x00); //Putting RADIO to sleep
Write(RegOpMode, 0x80); //Switch to LoRa mode
Write(RegOpMode, 0x81); //Setting RADIO to standby
  while (digitalRead(DIO5) == LOW)  //Wait for mode ready
  {
  }


--Now it is time to make your register settings here--
--And now we leave standby.

Write(RegOpMode, 0x85); //Set RADIO to continuous receive
  while (digitalRead(DIO5) == LOW)  //Wait for mode ready
  {
  }


And all that being said that you can connect through the spi bus under basic.
Title: Re: Programming SX1276 modules
Post by: Camerart on October 25, 2016, 07:41:15 AM
Quote from: . on October 23, 2016, 05:21:08 AM
Yes, defaults are loaded until changed by user.
Yes you must modify the internal registers.

In order to change most settings you must either put the module into standby or sleep mode, here is a snippet;
Write(RegOpMode, 0x00); //Putting RADIO to sleep
Write(RegOpMode, 0x80); //Switch to LoRa mode
Write(RegOpMode, 0x81); //Setting RADIO to standby
  while (digitalRead(DIO5) == LOW)  //Wait for mode ready
  {
  }


--Now it is time to make your register settings here--
--And now we leave standby.

Write(RegOpMode, 0x85); //Set RADIO to continuous receive
  while (digitalRead(DIO5) == LOW)  //Wait for mode ready
  {
  }


And all that being said that you can connect through the spi bus under basic.

Hi .
Noted, defaults loaded before changes.

Thanks for the snippet.
I use Oshonsoft BASIC, and if I read the data sheet correctly, it can't load addresses with data like this (Not sure though)
I think it works something like: (See attachment)
I hope to be able to make variables or similar for different Addresses and DATA.

Regards, Camerart

Title: Re: Programming SX1276 modules in Basic
Post by: raggedyanne on October 25, 2016, 07:10:44 PM
In C we can define variable names to values
//Define Module Registers
#define        RegFifo                    0x00
#define        RegOpMode                  0x01
#define        RegFrMsb                   0x06
#define        RegFrMid                   0x07
#define        RegFrLsb                  0x08


Write(RegOpMode, 0x00);

Which translates to

Write(0x01, 0x00);

or in basic

Call writetoreg(0x01, 0x00)


And definitions also apply to basic;

//Basic Module Registers
Define RegFifo = 0x00
Define RegOpMode = 0x01
Define RegFrMsb = 0x06
Define RegFrMid = 0x07
Define RegFrLsb = 0x08
Define RegPaConfig = 0x09
Define RegOcp = 0x0B
Define RegLna = 0x0C
Define RegFifoAddrPtr = 0x0D
Define RegFifoRxCurrentAddr = 0x10
Define RegIrqFlags = 0x12
Define RegPktRssiValue = 0x1A
Define RegModemConfig1 = 0x1D
Define RegModemConfig2 = 0x1E
Define RegPreambleMsb = 0x20
Define RegPreambleLsb = 0x21
Define RegPayloadLength = 0x22
Define RegDetectOptimize = 0x31
Define RegDetectionThreshold = 0x37
Define RegSyncWord = 0x39
Define RegDioMapping1 = 0x40
Define RegPaDac = 0x4D
Title: Re: Programming SX1276 modules in Basic
Post by: Camerart on October 26, 2016, 11:18:04 AM
Hi R,

Excellent!

However, since starting to understand what I'm doing, I have realised that I should really be programming a PIC to talk to the SX1276 modules.

I have chosen an 18F4520 PIC, and I use an Oshonsoft simulator to visualise it.  I changed your DEFINES to DIM and DATA and here's the CODE and result shown as an oscilloscope reading.  This shows the SDI output working.  If you look at 'above' ADDR2 and DATA2 you will see that the PORTC.3 bits are selected by PORTC.5 showing RegOpMode BIT1 = 0x01 and Standby BIT1 and 7 =129 =0x81  So it appears to be sending DATA to the correct addresses.

Thanks.
C.

I