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.


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.


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

MCU pin SX1278 pin Description
PA4 NSS SPI chip–select
PB0 DIO0 LoRa interrupt indicator pin (for receiver mode)
PB1 RST LoRa reset
——- ———- ———–

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).


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


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.


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.



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 — SX1278

The example — SX1278-example

157 thoughts on “STM32 HAL driver for LoRa SX1278 wireless module

    1. Wojciech DomskiWojciech Domski Post author

      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.

    2. Wojciech DomskiWojciech Domski Post author

      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.

    3. AvatarYsn_ba

      Hi Nhan , can you please help me on my project , I want to use F4 (F407VGTx) , I tried but still got many Worn and errors , NOT WORKING TO ME

  1. Avatarsaeed

    hi, thanks for your blog.
    i have two stm32l152 and lora sx1278. i’m going to send and receive data with keil IDE.
    your example is for SW4STM32.
    could you help me please?

    1. Wojciech DomskiWojciech Domski Post author

      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.

    2. Wojciech DomskiWojciech Domski Post author

      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.

  2. Avatarpooriya

    Hi thank you.
    i have questions!
    What is the maximum distance?
    and how can we get it?
    The program must be change?

    1. Wojciech DomskiWojciech Domski Post author

      I am still planning to do some range testing. You do not have to change the program. However, tweeting the parameters as spread factor can give you better results.

  3. Avatarpooriya

    I ask some where if you shift 0x10000 in DIO1 – 5 . in for example 1 ms .it work for 9600 meters.
    but i don’t test it.

    1. Wojciech DomskiWojciech Domski Post author

      Sorry, but I do not know how it should work. The DIO pins are described in the datasheet and they perform specific functions as described in there. Where did you get that idea?

  4. AvatarJohn

    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

  5. AvatarJohn

    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

    1. Wojciech DomskiWojciech Domski Post author

      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.

    1. Wojciech DomskiWojciech Domski Post author

      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.

  6. AvatarJohn

    thank you,. yes, now i use interface usart for debug. Now i make
    if (master == 1) {
    HAL_USART_Puts(USART1,”Mode: Master\r\n”);

    //init lora module

    HAL_USART_Puts(USART1, “Configuring LoRa module\n\r”);

    now in my serial port i see only the master, but I do not see the initialization parameter and other parameters 🙁

    1. Wojciech DomskiWojciech Domski Post author

      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.

    1. Wojciech DomskiWojciech Domski Post author

      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) {
      return len;

    1. Wojciech DomskiWojciech Domski Post author

      Yes, I have some nucleo for F4 but if you are going to ask if I have used it on that board then no. However, as I have written earlier I know that one guy has successfully run the code on STM32F4.

  7. AvatarJohn

    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…

  8. AvatarJohn

    in serial wire i see only:

    Mode: Slave
    Configuring LoRa module
    Done configuring LoRaModule
    Slave …
    Receiving package…
    Received: 0
    Package received …
    Slave …
    Receiving package…
    Received: 0
    Package received …
    Slave …

    and master side:

    Master …
    Sending package…
    Entry: 0
    Sending Hello 2
    Transmission: 0
    Package sent…
    Master …
    Sending package…
    Entry: 0
    Sending Hello 3

    what i can check for launch lib?

    1. Wojciech DomskiWojciech Domski Post author

      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.

  9. AvatarJohn

    oh, yah, i see, on the tx board not needed use DIO for transmit. Now in the debug i see:

    Transmission: 1
    Package sent…
    Master …
    Sending package…
    Entry: 1
    Transmission: 1
    Package sent…
    Master …
    Sending package…
    Entry: 1
    Transmission: 1
    Package sent…
    Master ..

    but not see it on the receiver

    1. Wojciech DomskiWojciech Domski Post author

      What did:
      ret = SX1278_LoRaEntryRx(&SX1278, 16, 2000);
      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.

    1. Wojciech DomskiWojciech Domski Post author

      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.

  10. AvatarHuzaifah

    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!

    1. Wojciech DomskiWojciech Domski Post author

      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; = 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.

  11. AvatarStraryAnoda

    Why does the transmission crash when the send time is accelerated from 2,500 milliseconds to for example 100 milliseconds?

    1. Wojciech DomskiWojciech Domski Post author

      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.

  12. AvatarLê Thanh Dương

    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?

    1. Wojciech DomskiWojciech Domski Post author

      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.

  13. AvatarLuqman

    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.

    1. Wojciech DomskiWojciech Domski Post author

      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.

  14. AvatarJohn

    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

    1. Wojciech DomskiWojciech Domski Post author

      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.

  15. AvatarRoman

    Good day, Wojciech Domski
    Help me please, i want to implement code of SX1278 on STM32F0 and i have a question:
    1. How could i change parameters such as Frequency, SpreadFactor, LoRaBandwidth, Power

    1. Wojciech DomskiWojciech Domski Post author

      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.

  16. Avataralvaloa

    Thanks for sharing your great work.

    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

    1. Wojciech DomskiWojciech Domski Post author

      The driver is written to support Full-Duplex. Also, please look at the SX1278 datasheet. The Semtech company only mentions Full-duplex configuration.

  17. AvatarAlvaro

    Hi, Wojciech Domski

    I’m using an RA-02 module like this:

    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

    Thank you

    1. Wojciech DomskiWojciech Domski Post author

      Hi Alvaro,

      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.

    2. AvatarAlvaro

      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

    3. Wojciech DomskiWojciech Domski Post author

      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.

  18. Avatarpedram

    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?

    1. Wojciech DomskiWojciech Domski Post author

      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.

    1. Wojciech DomskiWojciech Domski Post author

      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.

    1. Wojciech DomskiWojciech Domski Post author

      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:

      static const uint8_t SX1278_Frequency[1][3] = { { 0x6C, 0x80, 0x00 }, //434MHz

      or better yet make a new definition

      #define SX1278_433MHZ 0
      #define SX1278_525MHZ 0

      static const uint8_t SX1278_Frequency[2][3] = { { 0x6C, 0x80, 0x00 }, //434MHz
      { 0x83, 0x53, 0x5D }, //525MHz

      During the initialization you have to pass correct frequency.

  19. AvatarDaniel

    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:

    Mode: Master
    Configuring LoRa module
    Mode: Slave
    Configuring LoRa module

    Although I only set up the sender’s (receiver’s) side, is this normal? Is the module burned too:( ?

  20. AvatarDaniel

    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?!

    1. Wojciech DomskiWojciech Domski Post author

      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?

  21. AvatarMasoud

    Dear Mr.Domski
    thank your for your help. It solved.

    May you Explain about:

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


    ret2 = SX1278_LoRaTxPacket(&SX1278, (uint8_t *) buffer, message_length,2000);

    I think when massage was send to slave madole, ret2 will be ‘1’.
    But about ret1 I do not know anything.

    regards, Masoud

    1. Wojciech DomskiWojciech Domski Post author

      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.

  22. AvatarDaniel

    Hi, Mr.Domski
    I wanna set up some LoRa network that don’t interfere with each other. for example three group that each group has two modules. which parameters of the code should be change ?

    1. Wojciech DomskiWojciech Domski Post author

      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.

    1. Wojciech DomskiWojciech Domski Post author

      I do not have stack for LoRaWAN. However, there is an open source implementation from one of the vendors if I am correct. You can find it by downloading examples for LoRaWAN from ST.

  23. AvatarDima Nikishin

    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.

  24. AvatarApril Inamura

    Hello I am using your HAL STM32 Library as a base for the MSP430G2553 and the LoRa chip I am using is a SX1278. I just wanted to ask, is ret defined as a bool? And what are in the buffer and message?

    Like is buffer = 256 and message = “Hello World\n\r” ?

  25. AvatarPanagiotis

    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?

    Every detail plus my code as I have modified it can be found here:

    Any help is welcome.

    1. Wojciech DomskiWojciech Domski Post author

      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.

    1. AvatarPanagiotis

      I tried some debugging with printf in function SX1278_LoRaEntryTx:

      int SX1278_LoRaEntryTx(SX1278_t * module, uint8_t length, uint32_t timeout) {
      uint8_t addr;
      uint8_t temp;

      module->packetLength = length;

      SX1278_defaultConfig(module); //setting base parameter
      SX1278_SPIWrite(module, REG_LR_PADAC, 0x87); //Tx for 20dBm
      SX1278_SPIWrite(module, LR_RegHopPeriod, 0x00); //RegHopPeriod NO FHSS
      SX1278_SPIWrite(module, REG_LR_DIOMAPPING1, 0x41); //1000001: DIO0=01, DIO1=00,DIO2=00, DIO3=01
      SX1278_SPIWrite(module, LR_RegIrqFlagsMask, 0xF7); //Open TxDone interrupt
      SX1278_SPIWrite(module, LR_RegPayloadLength, length); //RegPayloadLength 21byte
      addr = SX1278_SPIRead(module, LR_RegFifoTxBaseAddr); //RegFiFoTxBaseAddr
      SX1278_SPIWrite(module, LR_RegFifoAddrPtr, addr); //RegFifoAddrPtr

      printf(“1. SX1278_LoRaEntryTx addr: %u\r\n”, addr);

      while (1) {
      temp = SX1278_SPIRead(module, LR_RegPayloadLength);
      printf(“2. SX1278_LoRaEntryTx temp: %u\r\n”, temp);
      if (temp == length) {
      module->status = TX;
      return 1;

      The first printf prints ‘addr:0’.
      The second one prints: ‘temp:0’.
      So, SPIRead of register LR_RegPayloadLength returns 0.
      Is this normal?

    2. Wojciech DomskiWojciech Domski Post author

      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.

  26. AvatarApril Inamura

    Hello Domski!

    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.

    1. Wojciech DomskiWojciech Domski Post author

      The DIO0 is an input which inform you if the package was sent over. It is not a trigger.

      There is also a possibility to pull it with software but in my opinion this is better approach. You can adjust it easily.

    1. AvatarPanagiotis

      (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?

      (syncWord – byte value to use as the sync word, defaults to 0x12)

    2. Wojciech DomskiWojciech Domski Post author

      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?

    3. AvatarPanagiotis

      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. (

      So I found that SX1278_FRF_VALUE should have the value 0x6C4000.

      LoRa_writeRegister(module, LR_RegFrfMsb, 0x6C);
      LoRa_writeRegister(module, LR_RegFrfMid, 0x40);
      LoRa_writeRegister(module, LR_RegFrfLsb, 0x00);

      But still the same, most of the transmitions are not received by the receiver.

      About ‘ pulling too slow for the new data’… I have no idea if I ‘m pulling slowly or fast! 🙂
      How can I check this?
      The transmitter is sending a message every 10 seconds.

    4. Wojciech DomskiWojciech Domski Post author

      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?

    5. AvatarPanagiotis

      A correction: in ‘It ‘s something in the hardware. It must be in the software.’
      I meant: It ‘s NOT something in the hardware. It must be in the software.

    6. Wojciech DomskiWojciech Domski Post author

      Well, I had a look on your code and it seems that you have the same problem as it was already mentioned here.
      You have misconfigured the SPI, in your code it uses 4 bits instead of 8 bits.

      Recheck your configuration.

    7. AvatarPanagiotis

      In file spi.c:
      /* SPI1 init function */
      void MX_SPI1_Init(void)

      hspi1.Instance = SPI1;
      hspi1.Init.Mode = SPI_MODE_MASTER;
      hspi1.Init.Direction = SPI_DIRECTION_2LINES;
      hspi1.Init.DataSize = SPI_DATASIZE_8BIT;

      So it ‘s correctly configured at 8 bit.
      Why do you say I have it misconfigured?
      (anyway, if I had it at 4 bit it would not work at all)

    8. Wojciech DomskiWojciech Domski Post author

      It was in the repository which you have shared. You also mentioned something about a zip file. Is your code there? If yes, please put it directly on the repo so it can be checked.

    9. Wojciech DomskiWojciech Domski Post author

      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.

  27. AvatarAshish Verma

    can we connect two loRa module which are transmitting to single loRa module which will be receiving the data

    1. Wojciech DomskiWojciech Domski Post author

      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.

  28. AvatarJacob

    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.

    1. Wojciech DomskiWojciech Domski Post author

      It seems like lack of path for header files. Check it. It does not matter in what IDE you are compiling as long as you have configured paths properly. Wast majority is suing the same ARM GNU compiler.

  29. Avatarjalal

    ,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؟؟؟

    SX1278_begin(&SX1278, SX1278_433MHZ, SX1278_POWER_20DBM, SX1278_LORA_SF_6,SX1278_LORA_BW_500KHZ, 64);
    for(int i=0 ; i0)
    master = 0;
    ret = SX1278_LoRaEntryRx(&SX1278, 64, 400);
    // HAL_Delay(50);
    ret = SX1278_LoRaRxPacket(&SX1278);
    if (ret > 0)
    HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);
    SX1278_read(&SX1278, my_packet, ret);
    HAL_UART_Transmit(&huart1, my_packet, 64, 100);
    master =1;
    ret = SX1278_LoRaEntryTx(&SX1278, 64, 400);

    1. Wojciech DomskiWojciech Domski Post author

      Could you add an exact snipped of your code or better yet publish it on Github? Now, there are some syntax errors. Also what you want to achieve is rather Half duplex than full duplex.

  30. AvatarYsn_ba

    Hi ,
    I megrated with your program to STMF4 using Keil IDE , but I can’t see the output of the program as you did with serial wire !
    can you help me . THANKS FOR YOUR EFFORT.

    1. Wojciech DomskiWojciech Domski Post author

      In the example I’m using SWV. You need to use an application for this, e.g. st-link utility. There is a tool for this.
      In the example I have provided serial port is not being used.

    2. AvatarYsn_ba

      is your __Write function still working for me even if I am using F4 and Keil IDE with link utility ! I’m stuck here , I can’t know if it’s working for me or not.

    3. Wojciech DomskiWojciech Domski Post author

      Yes, it should work. However, did you connect SWO pin? What board do you use. Nucleo boards have it already connected to appropriate pin of ST-Link programmer.

  31. AvatarBob

    Hello, it’s really exciting, what you’ve done. I’ll be very grateful if you help me. What exactly should I change to make it work with sx1272?

    1. AvatarBob

      I’ve already changed the frequency (this 0x6C, 0x80, 0x00 to this 0xD9, 0x00, 0x00), but it doesn’t work. The frequency is 868MHz

    2. Wojciech DomskiWojciech Domski Post author

      Are you using the chip as a module? Or is it a bare bone chip? If it is the first case changing frequency will not do any difference since there is a band pass filter on the module.

    3. Wojciech DomskiWojciech Domski Post author

      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.

  32. AvatarFarouk

    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.

    Are the my ways true or not? Thanks.

    1. Wojciech DomskiWojciech Domski Post author

      Yes, your understanding is correct. Please keep close eye on SPI configuration since this is usually the most common issue due to default configuration provided by STM32CubeMX.

  33. AvatarFarouk

    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!

  34. AvatarFurkan

    Hi dear Wojciech Domski!

    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?

    I shared codes on this link:

  35. AvatarFurkan

    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 “???????” .

  36. Avatarmohammed ibrahim djadir

    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

    1. Wojciech DomskiWojciech Domski Post author

      SW, meaning System Workbench for STM32? I would recommend to create a new debug profile. The message you are getting indicates that there is no debug configuration for the OpenOCD.

    1. Wojciech DomskiWojciech Domski Post author

      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.

Leave a Reply to John Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.