The more we know the harder it is to defeat us!

STM32 HAL driver for LoRa SX1278 wireless module

Long range wireless communication is getting more and more attention. Today, I would like to share with you my experience with a LoRa module — SX1278 and also the drive for this device.

LoRa took its name from “Long Range”. It is a proprietary communication system which is using chirp spread spectrum radio modulation technology. In other words, it uses chirps to encode a piece of information. What is really interesting about the LoRa is a fact that it can transmit data over very long distance. By very long distance I mean over a couple of kilometres and sometimes more and all of this is done very power–efficiently.

I decided to work on SX1278 LoRa module. It is an affordable radio module and offers not only LoRa but other types of modulation like FSK. The test platform is an STM32F103C8T6 development board.

Prerequisite

You need two boards equipped with STM32F103C8T6 MCU and two SX1278 modules.

One of the boards will work as master and the other one will work as slave. Master is sending data to slave. Both boards have the same firmware. The mode in which the board is working in is determined by the state of input pin PB2.

Above you can see screen shoot from CubeMX where MCU’s pins are configured.

To actually see what is being send over via radio SWV interface was used. For this to work you need to have a debugger, preferably ST-Link V2, with support for SWV. Sometimes when you want to take advantage of SWV it does not work out of the box. The most probable reason for this is that the debugger firmware outdated. Please remember to upgrade the firmware of ST-Link in advance.

Wiring

The module has to be connected with the MCU board with following pins:

MCU pin

SX1278 pin

Description

PA4

NSS

SPI chip–select

PA5

SCK

SPI SCK

PA6

SO

SPI MISO

PA7

SI

SPI MOSI

PB0

DIO0

LoRa interrupt indicator pin (for receiver mode)

PB1

RST

LoRa reset

——-

———-

———–

VDD

VCC

+3V3

VSS

GND

GND

The SX1278 communicates with STM32 MCU via SPI those are PA4, PA5, PA6 and PA7. There are two other logic pins — PB0 which is DIO0 of radio module and PB1 which is Reset pin of this module. The meaning of the reset input if obvious, what is not is the DIO0. It is used for pulling the state of LoRa module. If the DIO0 output is high it means that there are received data and MCU can read it. MCU can be configured for detecting rising edge to trigger immediate action of reading the data. However, in this example polling was used (checking manually if the DIO0 is high).

Compilation

The example was prepared for SW4STM32 IDE. However, nothing stands in the way to use other IDE like i.e. TrueSTUDIO – Atollic.

Run

After flashing the image you should mind the PB2 port. It is configured as input and depending on its state the board boots as a master or as a slave. For master mode the PB2 has to be pulled high. For slave mode the PB2 has to be pulled low.

All the communication is going through redirected printf() function to SWV. To read the communicates you have to have ST-Link Utility installed. There you can chose Printf via SWO viewer and set the right frequency.

Before you start transmitting and receiving data via LoRa you need to set up the driver. Below is an example how to do this.

Provided example works in ordinary fashion, the master board is constantly sending messages while the slave is constantly reading them. That’s simple, isn’t it? Below a code snippet was provided to clarify the situation.

C

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

while(1)

{

if(master==1){

printf("Master ...\r\n");

HAL_Delay(2500);

printf("Sending package...\r\n");

message_length=sprintf(buffer,"Hello %d",message);

ret=SX1278_LoRaEntryTx(&SX1278,message_length,2000);

printf("Entry: %d\r\n",ret);

printf("Sending %s\r\n",buffer);

ret=SX1278_LoRaTxPacket(&SX1278,(uint8_t*)buffer,message_length,

2000);

message+=1;

printf("Transmission: %d\r\n",ret);

printf("Package sent...\r\n");

}else{

printf("Slave ...\r\n");

HAL_Delay(1000);

printf("Receiving package...\r\n");

ret=SX1278_LoRaRxPacket(&SX1278);

printf("Received: %d\r\n",ret);

if(ret>0){

SX1278_read(&SX1278,(uint8_t*)buffer,ret);

printf("Content (%d): %s\r\n",ret,buffer);

}

printf("Package received ...\r\n");

}

}

Working example

Below you can see two screen shoots. The first one shows a log from master session. The second image shows a log from slave session.

Master:

Slave:

Source code

If you are intrigued enough you can go and download the driver or the whole example. Both are available at my github. The driver is written in C and it can be easily ported to other targets. Also the hardware layer was separated from the driver logic so it is not a hassle to actually port it.

The driver was written using HAL so it will work with different MCU. You need to create a new project in CubeMX. After that migrate the CubeMX project which was provided with the example. It will import the configuration for your MCU. Then you should regenerate the project. And that is almost all.
If you change the pin configuration you should update hardware structure of the driver with your configuration.

To answer both of your questions.
Yes, I’m using dio0. The purpose of this is to read irq when the data (or a portion of the data) has been sent over.
Also please look into the module documentation. There is a sequence diagram for transmission.
You could actually omit reading the dio0 but you would have to wait longer to make sure it was sent over plus clear the irq nevertheless.

Yes, the example was prepared for SW4STM32. Unfortunately, I do not use Keil software but you should be able to import this example. If not you can try to create an empty project and copy source files which are inside SX1278-example repository — it should work flawlessly.

As a matter a fact I have forgotten to mention a different path.
You can take the STM32CubeMX file and change the Toolchain to MDK-ARM and regenerate the code. I think it will be the most straight forward way to do this.

hi
Thanks for sharing your works.
but i have a little problem with your project. Can you help me with project for stm32f0?
i use two board for test, and i make program for master and slave and it not work…maybe you can check my project?
thank you

yes. copy your project on the stm32f0 via cube after generate code and add your files gpio/spi/sxlib and i use your code from main file. I change pin for my board and now my project success compile. But between board tx/rx not work
if you want i can send my project with cube on your mail

You are only required to copy the driver of the SX1278 and some of the code from main. While regenerating the code Cube will take care of adjusting GPIO and so on. You should not copy them to the new project. Just a quick question, did you connected all required pins of the LoRa module to your STM32?
You can send it to me but I do not have STM32F0 to check it. The best way of sharing your project would be by using Github and sending me a link to it.

Ok. I took a look at your code. Everything looks all right. The reason you do not see anything is that because you did not redefined _write() function. In the example I am using SWV as a debug interface. It is using SWO pin at which it is sending the data. You could use an UART interface if you wish.

Where did you get this function HAL_USART_Puts() from? From HAL lib you get only HAL_UART_Transmit() and similar. I advice you to sort out the communication first. After that you can use it to properly redefine _write() to use your serial interface as output for printf(). Also, the less you change the original code the better. The example I have uploaded works and was tested with STM32F1 and it should work also for you. I have confirmations that it was also ported to STM32F4 where it also works. You only need to sort out the communication issue.

You welcome! As for the SWV that is why I did write to use a serial interface like UART. Then you only need to redefine the _write() function and everything should work out of the box provided that the serial interface is properly configured. Redefinition of _write() function can look like this for UART:
int _write(int file, char *ptr, int len) {
HAL_UART_Transmit(&huart2,ptr,len,50);
return len;
}

i can’t launch your library. Did the necessary for checks SPI and he work, the registers are read and written, the state of GPIO is the same as yours, what else needs to be change? If there is an opportunity, share an example for a f4disc…

It seams that the Master does not send any data. Look at what you have received from debug log of the Master:

Transmission: 0

It means that the function SX1278_LoRaTxPacket() returned 0 because of timeout. There was no signal on DIO0 of the SX1278. Also check what value is returned by
ret = SX1278_LoRaEntryTx(&SX1278, 16, 2000);
at the very beginning.

What did:
ret = SX1278_LoRaEntryRx(&SX1278, 16, 2000);
return?
Also, below function:
ret = SX1278_LoRaRxPacket(&SX1278);
is also using DIO0 to know if there are any pending data to be read. From what you have written before I think that you did not connect the DIO0 on the slave side.
Please connect all pins as described in the table inside the post.

Reading raw value from LoRa module is pretty straightforward. However, SX1278_RSSI_LoRa() returns RSSI after some calculations. The way you calculate the RSSI differs depending on what configuration you are using. Please refer to SX1278 documentation for more information.

Thank you so much for your help, actually i want o implement code of SX1278 on STM32L152 as you mentioned earlier i have added the header files and other necessary files into the folders but i have one doubt regarding the pins,
1. MODE pin where i have to connect on board and on Module.
2. Same for the DIO0 pin.
Thank You!

The MODE pin can be any GPIO configured as input same goes for DIO0. Just remember to update hardware initialization structure for LoRa module:
SX1278_hw.dio0.port = DIO0_GPIO_Port;
SX1278_hw.dio0.pin = DIO0_Pin;
The MODE pin is selecting whether the board works as master or as slave. If you stick to the same labels in Cube and regenerate code everything should work right of the box. Since you are running this example on STM32L1 the easiest way is to import my example and change appropriate pins.

I did no try this out. But you can do that kind of experiment. The minimum gap between data transfers is defined by the parameters of transmission and how many data you want to send. You can calculate it based on datasheet of SX1278 device.

Hi,
I did followed your instructions with the Dragino LoRa Shield instead of SX1278. I connected the wire and also use SX11278.c to do just like you. However, ret = SX1278_LoRaEntryTx(&SX1278, message_length, 2000) or ret = SX1278_LoRaTxPacket(&SX1278, (uint8_t *) buffer, message_length, 2000) always returned to 0 not 1 like you to send and receice the package. I do not know how to fix that. I used KeilC to do that. Do you have any idea to solve it?

My first step in solving this would be to actually check if there is proper ongoing SPI transmission. You can verify that by reading some register with constant value or using a logic analyser. SX1278_LoRaEntryTx() returns 0 when the timeout has been reached. That is why I would check SPI communication first.

Hi,
can i use multiple transmitters sending data to one receiver with your driver? i have a project to set multiple node of wireless sensor network, and i’m interested to use sx1278 lora module and stm32f103.

Yes, you can do this. There are two ways. You can use single SPI and share MISO, MOSI and SCK pins (as it was intended) or you can use different SPIs. The best way would be to use single SPI and multiple CSes (chip select pins) to chose with which device you want to communicate with. Also remember to use different pins for DIO0 and RST for each LoRa module.

Good day, Wojciech Domski
Help me please, can you show me how i can read rssi from your lib? i see function but if i use this function i see only data “H#” on the receiver. I can’t understand why…
please, show me a little example

Hi!
You have two functions for this: SX1278_RSSI_LoRa() and SX1278_RSSI().
SX1278_RSSI_LoRa() read data from 0x1B register and returns the absolute RSSI value in dBm.
SX1278_RSSI() read data from 0x11 register and returns the current RSSI value in dBm.
All RSSI values returned by the functions are positive. You can always refer to SX1278 manual for more documentation. It is explained there. However, I do not know how you got 2 bytes “H#” instead one since both functions in question return uint8_t.

Hi. Have you had a look at the example. In the main.c file you have initialization of the LoRa module:SX1278_begin(&SX1278, SX1278_433MHZ, SX1278_POWER_17DBM, SX1278_LORA_SF_8, SX1278_LORA_BW_20_8KHZ, 10);
Through this function you can initialize the module and set all the necessary parameters.

I’m thinking of implementing a Half-Duplex communication (both transmit and receive, but not simultaneously) and in your code I see that to receive any data, I must configure a transceiver as a slave necessarily. In a communication in which the Master constantly sends data to the Slave, there will be some way in which the Master can receive data that the Slave sends, but does not know when ?. Thank you

This module seems to be similar to yours, but, the datasheet (Semtech SX1276/77/78) indicates that the maximum power is +20 dBm (the RA-02 module indicates +18 dBm). Do you think there will be a problem if I set my module (RA-02) to +20 dBm (using the PA_BOOST pin in the RegPaConfig register)?
I am trying to reach the maximum possible range but without exceeding SF = 7 and BW = 125KHz

Yes, I think you can give it a try. Since both modules are based on the same Semtech chip it should work. If you have modified other values in RegPaConfig, also set OutputPower to 0x0F (it’s default value).
Please leave a comment when you run some tests. I am really curious about the results.

Sorry for the late reply.
As I mentioned, I am using the RA-02 module (based on the SX-1278 chip) and it indicates that the maximum power is +18 dBm. I set the registers: RegPaConfig = 0x8F (PA_BOOST selected) and RegPaDac = 0x87 (Enables the + 20dBm option on PA_BOOST pin). I directly connected the SMA output of the LoRa module to two attenuators (each of 30 dBm) and then to the RTL-SDR. I could see that, between the configuration of +17 dBm and +20 dBm, there was a difference of 2-3 dB (It would be better if this was done with a spectrum analyzer)

It is curious that the module indicates + 18dBm, already the datasheet indicates that it could be +17 dBm or +20 dBm, but nothing intermediate. I also noticed that the SX-1278 chip, although it has two outputs (RFO and PA_BOOST), the only output enabled is the PA_BOOST, since when configuring RegPaConfig and selecting RFO pin, I did not get anything in the output

Also, it is worthy of a note that LoRa modules have additional components on the board. If you design your own module you could overcome some limitations. For example, the SX1278 chip’s frequency can be altered in broad range. However, on the LoRa modules there are filters which block the signal.

Hi, I have four lora nodes. Each node is made with STM32 and RA-01 (sx1278) Lora module.
On of the nodes is considred as master. How can I send data to one of the three other slave nodes?
Can I assign a dedicated code to each slave node?

Basically when you use LoRa module it does not have a support for any protocol. Generally, it broadcast data to all recipients. You can implement a simple data frame which has an ID field through which it identifies nodes. After each node receives this datagram it checks if it is addressed to it, if not then it drops it. On the other hand, you can use LoRaWAN protocol which uses LoRa as a transportation layer. The choice is yours. However, for a simple communication you can implement what I have described at the beginning.

Answering your both questions.
Keil is only IDE. You can either import the project or add necessary files by hand (driver and some example). That’s all.
As for different frequencies. Yes, you can change the frequency by modifying proper registers in SX1278 module. I believe it was already answered in the comments, if not then you you have to modify three registers such as RegFrfMsb (0x06), RegFrfMid (0x07) and RegFrfLsb (0x08). The frequency is a multiplication of Frf (value concatenated from previously mentioned three registers) times frequency step (61Hz). Have a look at the manual for the SX1278.
Please also keep in mind that you need to have a proper module prepared for required band. If you use module for different band it will not work.

Yes, you can do this by calculating the value of register RegFrf. Since the frequency step is 61Hz and you want to get 525MHz you can obtain the correct value of RegFrf like this
525MHz / 61Hz (approx)= 8606557 = 0x83535D.
Now, you put this value to RegFrf like so
RegFrfMsb (0x06) = 0x83, RegFrfMid (0x07) = 0x53 and RegFrfLsb (0x08) = 0x5D.
Keep in mind that this is approximate value. The real frequency would be 8606557 * 61Hz = 524999977Hz (approx)= 525MHz.
Now, you have to make some alteration to the code and change the line:

Good day, Wojciech Domski
I implement your code in microcontroller’s board. Unfortunately one of boards was burned. I bought it but it comes to me a week later. I connected one of the LoRa module to the board, Now in the debug just I see:

Hi Mr.Domski
I used your code in my project.
But unfortunately one of my microcontroller was burn. I bought it, but they will sent it the next week.
Now I connected one of Lora madule to my board and I see:
Mode: master(or slave)
Lora configuration…
Compiler stopped in sx1278-begin function.
Is it normal? Or my madule burned too?!

It is hard to say what is going on. You should debug the code to see where exactly it is hanging. Also I quite don’t get how compiler could stop at sx1278_begin function. I assume that you meant it hangs there during the execution.
Could you also verify that all GPIOs are correctly connected?
Did the module worker prior to the damage?

SX1278_LoRaEntryTx() returns 1 if the module entered transmission mode successfully.
SX1278_LoRaTxPacket() also returns 1 if the message was sent successfully.
Both functions return 0 if a timeout period was reached.

The quickest and the easiest way would be to change the frequency by a reasonable step. Although I would recommend implementing a simple protocol with acknowledgements where it would resend a message to ensure it was delivered.

Hello
Thank you for sharing your work.
but I have a little problem with your project. Can you help me with a project for stm32f405?
I use two boards for the test, and it does not work … maybe you can check my project?
I connected everything correctly, the module is working.
thanks

I ‘ve built a transmiter with STM32F030F4P6 and a Lora RA-01.
But I ‘m struggling a month now (!!!) to make it work without any success.
I have multiple-times checked my hardware connections, they must be correct!

From the SX1278_LoRaEntryTx I get a 0 as an answer, so I suppose it cannot enter transmission mode.
How can I debug the SX1278_LoRaEntryTx function?

The best way to figure out what is going on is to enter debug mode and step into the function in question. Also, does your module has the same chip. To my knowledge RA-01 should be the same but I would verify it, just to be sure.

Best way to debug the code is to use debugger instead of printfs. You could check with the documentation for the module if the data you have received is correct.

Also I had a quick look at your project. It seems that the SPI configuration is wrong. By default the data size is set to 8 bits for the module, while you have configured it to 4 bits.
Best practise is to check if the SPI communication is working by itself. For example, you can try to read some registers which have predefined value, an equivalent to WHOAMI register for I2C interface.

I have another question! So my get_DIO0 is sending back a 0 or a non 1 (HIGH) number, thus the txPacket is not getting triggered and the package is not being sent. I understand that the GPIO0 pin is reading low. How do I go about fixing this? If you need any more details, please let me know.

(Sorry for not answering directly to your answer but I clicked on your answer but no ‘answer’ button appears)
(At STM32CubeMX->Inout & Configuration->Connectivity->SPI1->Sarameters Settings->Data Size)
I changed the ‘Data Size’ to 8….and…IT WORKS!!
I can ‘t believe it!! It works!!!
Wojciech I can ‘t thank you enough! Thank you!!Thank you!!Thank you!!!!

But now I have another problem: the transmitter emits a 100 messages (‘Hello’ plus a number: ‘Hello 1’, ‘Hello 2’, ‘Hello 3’ etc).
But the receiver receives, about, only 7 messages out of this one hundred.

Maybe it ‘s because my receiver uses LoRa.setSyncWord(syncWord) which defaults to 0x12?

Glad to hear that!
As I understand, you are using a different transmitter? The reason for dropping frames is usually a bad link. Check your antenna if it is fixed properly, maybe there is a little or no contact. Also maybe you are pulling too slow for the new data. How quickly the transmitter sends the data and how often do you pull?

I have two transmitters, one with Arduino (works ok) and one with STM32.
The Lora RA-01 module is ok because it works fine with Arduino.
So it ‘s not a hardware issue.
It ‘s something in the hardware. It must be in the software.
It maybe has to do with frequency.
I want to make the Lora work at 433MHz.
The equation is f = (32 * SX1278_FRF_VALUE) / 2^19. (https://github.com/jgromes/LoRaLib/issues/8#issuecomment-390381373)

Does the transmitter and receiver use the same frequency? Even if you configure the module to use a certain frequency then the hardware can not allow it since the modules have a band pass filter.
Maybe the Arduino code is using different frequency while it is not explicit?

Yes, it’s visible but if you would like me to look into it please extract it on the repository. Generally, pushing zips or other binaries is not a good practice unless it’s required.
You can do this on a different branch.

Ok, I uploaded the whole project on https://github.com/panosss/sx1278-test-code.
Except for the folders ‘Drivers’ and ‘startup’ because they contain files for STM32F1 (the project is for STM32F1, so I guess they are not used).
I think I uploaded all the files, if you have any problem please let me know.

Yes. You can connect multiple transmitters to a single receiver.
However, keep in mind that if two or more transmitters are transmitting a portion of data you can receive garbage or nothing at all.
For this, it is good to have a simple protocol with delivery system such as acknowledgments of reception to make sure that what was sent was also received. Also you can use LoraWAN for this but sometimes it is a bit too much piece of machinery for small problems.

hey,
i recreated your project on keil but i’m missing one file, specifically: stm32f1xx_hal_exti.h
and i think its important file, because i get like 20+ errors when compiling.
if anyone could help me i would be honored.
thanks

Hi
,I’m having problem to implementing a Full-Duplex communication . when we switch from transmitter(m=1) to receiver(m=0) we must create hal_delay(50) but Data rates are low ,if commented hal_delay(50) communication between two module is Disconnected. i debug mycode and see ret=0 in ret =1278_LoRaRxPacket(&SX1278); What is the problem؟؟؟

There is also bandpass filter. Are you sure that you have the right version? Depending on the country to which the module is being send it can have different **hardware** settings, different components.

Firstly, thank you so much for this unique project. I have two questions related with it.

1- I will use STM32F407. To be able to use it I regenerate a new project on CubeMX. After that I will only copy and paste which is SX127 c and h. Is it true way? Then I will set the SPI as half dublex mode.

2- I will read the print commands with UART and RS-232 usb to ttl converter.

For the MODE pin should I set it SET for master and RESET for the slave respectively? or Should I debug it randomly to the both master and slave? I could not understand how the MCUs understand slave or master with MODE pin? Can you inform me? Thanks!

I have problem with the project. I use stm32f103 and also dorji drf1278f RF module. I rewrite codes and added main.c codes, SX1278.c and h codes. Then, even though the master which I determined with MODE PIN which is PULLUP sends the data correctly on Putty, in the slave part which is the PULLDOWN (MODE PIN) I got ret value as 255 but I could not get the data. I mean that the data that I received was like “?????????”. Also, Im using UART and RS232 to be able to read data from serial port. Can you help me please?

It means that the receiving part is not working. Have you tried to debug it? I would start with checking the configuration. There is a lot of discussion on this matter. Maybe looking through it can help you solve your problem.

That is interesting. Setting the mode pin should do the trick. I have also checked your code on github and I do not see that there is some misconfiguration.
One other thing to check. Could you read some values from the LoRa module registers (before initialization) and verify it if the value you are reading is correct one. Check any configuration register against its default value.

I have checked SX1278_LoRaEntryTx and SX1278_LoRaEntryRx for each master, slave(MODE PIN is pullup and pullldown respectively). I got 1 for SX1278_LoRaEntryTx which equals to ret variable and I got 255 for SX1278_LoRaEntryRx which equals to ret variable again. On the other hand, I could not see the that what does the SX1278_begin() return on the serial window on Keil. So, now I have no any idea to access to the result. Im still reading value as “???????” .

hellom thank you very much for sharing your work i treidto import your project yousing SW and i, facing this error: OpenOCD Script not found (or not support yet) while debbuging could you help me please

I would recommend to use STM32CubeIDE. It is a good start for beginners since almost everything is done automatically. If you want to, in time, you can get to the nitty gritty of it since it allows to configure almost everything.

Hello, I decided to use your driver, but the data is not transmitted, sx1278_begin and sx1278_entry_tx returns 1, but sx1278_tx_packet returns 0. I looked at this method, where you read the dio0 pin, but why read it if this pin is only used when receiving data. I removed this check, but the data is still not sent. What might be the problem? Here is a link to my code on github : https://github.com/gug2/lora_radio_test

When SX1278_LoRaTxPacket() returns 0 it means that the package was not sent. Also the DIO0 is being used to check if the message actually was sent over. Removing dependencies on DIO0 from configuration is not advised. Also, I believe end of transmitting can be pulled using internal registers but it required to change the configuration. Please check the manual for this.

Hello! Thank you for sharing this project. I am currently working on implementing this project for my STM32F0. For some reason System Workbench says that „expected ‚=’, ‚,’, ‚;’, ‚asm’ or ‚__attribute__’ before void (or any datatype)” on lines 256-262 and „unknown type name ‚__weak’ on line 260 of SX1278.h . What would be your advice of solving those issues? Thank you!

The errors are gone! Thank you for that. I have another question: I would like to change the frequency operated to 915MHz as I am using an SX1276. I noticed that you defined the frequency as : “#define SX1278_433MHZ 0” and “static const uint8_t SX1278_Frequency[1][3] = { { 0x6C, 0x80, 0x00 }, };” on lines 169-172. May I ask what those numbers mean and some guidance on how to change the number so that it is suitable for 915MHz? Thank you again.

I was about to propose the very same, to check out the previous answers. Generally yes. You have to overwrite the 3 bytes.
Also, please keep in mind that usually modules have a bandpass filter. Even if you change the frequency in the LoRa module the transmitted signal will be very weak.

Will the signal be weak even though SX1276 is designed for frequencies between 137-1030MHz? I noticed that SX1278 only has a frequency range of 137-525MHz but the spreading factor, bandwidth, effective bitrate, and sensitivity ranges on the datasheet are the same. Because the datasheet has SX1276, 77, 78, and 79 combined, I think the SX1276 chip should work in the same way as the SX1278 chip.

It is not a matter of supported frequencies of the SX1276 chip. Depending on what kind of the module you are using some have a bandpass filter which reduces other frequencies.
Although, I believe that you should be able to receive some signal on your desk. Moreover, you can always design your own RF PCB with SX1278 LoRa chip.

My application need bidirectional communication. In order to do that, i used the function that you described, however, didn’t work.
I initially uses the F103_1 as master and the F103_2 as slave, and did work. But when I try to change (F103_1 as slave and F103_2 as master), the same code didn’t work. I used the functions ret = SX1278_LoRaEntryRx(&SX1278, 16, 2000); and ret = SX1278_LoRaEntryTx(&SX1278, 16, 2000);. Both returned 1 in ret, and the function ret = SX1278_LoRaTxPacket(&SX1278, (uint8_t *) buffer, message_length, 2000); in the F103_2 (working as master) return 1 to ret too, but the F103_1 doesnt receive the package.
Can you help me? Did you already test bidirection code with this lib?
Thanks a lot

To speak frankly, I have not tested the bidirectional transmission. However, I have this on my bucket list. Currently, I am working on a different driver. When I will have some time I will check this. Probably modify the driver and corresponding example.

Hi, you wrote a code specifically for sx1278. ST provides code for sx1276 for example. Do you know if sx1278 chip will run on sx1276 drivers for 433 MHZ? since the supported frequencies seem to be the only difference between the chips. The pinout and registers are the same as far as 433mhz goes.

Yes, those two chips are virtually the same. The difference is about frequency range. This subject was already tuckled many times and also one of the Readers has successfully used the code with some changes. Please keep in mind that if you use a module there is usually a bandpass filter and changing the frequency can have very poor effect.

Hello, I configured your driver as in the example, but nothing is visible at the frequency of 433-434mHz. I looked at other frequencies and it turned out that there are some signals on the frequency 234mHz. I attach a photo. The question is, should LoRa packages look like this and if so, why is it transmit on the wrong frequency? Link to picture: https://ibb.co/YfNFdx7

Hi again! Through trial and error, it turned out that the module is in sleep mode,because the RegOpMode (0x01) register in the last 3 bits contains 000 (Sleep mode), the problem is that if i write data to these 3 bits, they are ignored and remain 000. (bit 7, 6 and 3 write and read normally) What am I doing wrong?

It is strange, that after the initialization the chip goes to sleep mode. Could you verify if you can get some data from the chip. For example, please read some data from a configuration register without initialization of the device. This will let us verify if communication is working properly.

I provide two cases: read register in the setup and read register in the loop. In both cases value 0x08. In the setup i make reset as follows: RESET_PIN to GPIO_PIN_RESET -> HAL_Delay(1) -> RESET_PIN to GPIO_PIN_SET -> HAL_Delay(100). In the loop i read register once per second. In the datasheet write that reset state of the RegOpMode – (bit 7 long range mode – 0, bit 6 accessSharedReg – 0, bit 5-4 reserved – 0, bit 3 lowFrequencyModeOn – 1, bit 2-0 mode – 0x01. The value 0x08 describe that all bits right but first 3 bits contain 000 instead of 0x01.

It seems like you have permanently enabled low frequency mode. Can you change it by hand and verify if it was changed. Please keep in mind that it can be changed when conditions are are met. Please refer to manual.

I do not quite understand. You are changing the LowFrequencyModeOn bit (bit number 3 starting from 0) and you want to change the value of the Mode bits?
I would suggest to read the RegOpMode and modify only LowFrequencyModeOn bit.

I cleared 3 bit LowFrequencyModeOn like that:
SX1278_SPIWrite(&SX1278, 0x01, SX1278_SPIRead(&SX1278, 0x01) & ~(1 << 3));
And read this register again and return value is 0x00 (bit3 cleared).
What should I do next?
Thank you in advance!

I would suggest now setting the state of the SX1278 accordingly. Just try to move it from the sleep state by changing the value of the last three bits. Please mind the state machine diagram in the manual.
After setting it to other state try to read the value of this register once again. If it was done correctly i should indicate a different state.
Nevertheless, it is very strange that your device behaves in this way. Do you have a different unity to try it? Also, could you share which unit you are using?

From manual point of view you are doing this right. You are transferring from sleep mode to standby mode. This should be possible.
Please try instead of reading current value of the register under 0x01, write there 0x01 directly. Then we will be certain that you are entering standby mode.

I also noticed that if you first write to the first 3 bits (mode) then the the following write are not readable (everything is read as 0x00) and if you write first to 7 bits (Lora mode) that value is read EXCEPT for the last 3 bits. I have 2 LoRa modules, I tried each one, I don’t think the problem is with the chip itself.

I have noticed that you have two versions of LoRa drivers. Please clean up the project and use the appropriate one. If you are using SX1276 then make changes to SX1278 driver. Now, it is hard to say what’s going on. Please push the changes to the repo and let me know.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.