9 years, 3 months ago.

LoRa receiver

Hi! I am trying to use sx127x as receiver (transmitting looks alright). My code looks as follows

sx127x receiver

#include "sx127x_lora.h"
#include "mbed.h"

SX127x kom(PTD6, PTD7, PTD5, PTD4, PTA6, PTA7, PTC16, PTC13, PTA14);
SX127x_lora Lora(kom);

DigitalOut led_red(LED_RED);
Serial pc(USBTX, USBRX);

int main()
{
    Lora.enable();
    uint8_t data[8];
    led_red = 1;            //no light
    pc.baud(115200);
    Lora.start_rx();
    //pc.printf("%x",kom.read_reg(0x01));
    
    while(true)
    {
       while(Lora.service() != SERVICE_READ_FIFO);
        for(unsigned i = 0; i < 8; i++)
            {
            data[i] = kom.rx_buf[i];
            pc.printf("%c",data[i]);
            }    
        Lora.start_rx();
    }    
}

Lora.service() function is always in SERVICE_NONE. Perhaps I have bad receiving code sequence but I don't know how to do it right. Thanks

Question relating to:

Driver library for SX1272/SX1276 transceivers Radio, transceiver

1 Answer

9 years, 3 months ago.

before you start_rx(), you must first set receiver to same settings as the transmitter side: Lora.setSf(), Lora.setBw() and kom.set_frf_MHz().

You should call kom.init() just before Lora.enable().

If you still have trouble, you can poll the REG_LR_IRQFLAGSMASK on receiver.

Accepted Answer

This is in both transceivers set equally. The problem was in bad connection. Btw: the code construction is good? I tried cut Lora.start_rx() from endless while loop and it works as well. But it receives individual characters, but not the message as it was sent. E.g. if I have in transmitter for(unsigned i = 0; i < 8; i++) kom.tx_buf[i] = 0xf; and in endless while loop Lora.start_tx(8), it receives only one character (in rx_buf).

posted by Jakub Siska 06 Feb 2015

after calling start_tx(), you must wait for SERVICE_TX_DONE before calling start_tx() again.

posted by wayne roberts 06 Feb 2015