STM32F0 and Lora - missed packets - Page 1
Forum section: electronics / general

author: panoss
author_rank: Frequent Contributor
timestamp: January 28, 2020, 03:07:37 pm
content: I 've built an STM32F0F4P6+LoRa transmitter.I have managed to make it transmit.The code in the loop (in main.c) sends a message every 2.5 Seconds.BUT it does not work as it should:out of the 100 messages it transmits, the receiver receives only 10 to 15...I have tried sending them every 2.5 Seconds, then every 10 Seconds, every 30 Seconds...etc...but the result is the same.(this Lora module I 'm using works fine with Arduino)I 've also tried changing:-Frequency-Spreading Factor-Signal Bandwidth-Transmission Power-Coding Rate-SyncWord-Preamble LengthI also tried putting delays in lots of places in the code.Without any result.I have uploadedmy code on github, folders Inc and Src (and the whole project in the zip file, just in case).(the code is a 'mixture' of codes fromhereandhere)What can I do to make it work properly?Any help is welcome.

author: thm_w
author_rank: Super Contributor
timestamp: January 28, 2020, 11:36:19 pm
content: Do you have a logic analyzer or oscilloscope to check that the message is getting to SPI port output every 2.5s?

author: free_electron
author_rank: Super Contributor
timestamp: January 29, 2020, 01:41:04 am
content: every 2.5 seconds ? that is against lora principles ...

author: SiliconWizard
author_rank: Super Contributor
timestamp: January 29, 2020, 01:51:37 am
content: Have you actually tried using the library there:https://github.com/wdomski/SX1278with the example given? I'm not too sure about your "mix".I've just very briefly looked at your code, and one thing that doesn't seem right is that you do absolutely no error checking from called functions and no polling, you have just inserted fixed delays. The above library+example actually poll for tx conditions from the Lora chip, which apparently you don't. So you can never know whether your packets have actually been sent successfully. Just using fixed delays is probably not going to cut it. There may be other issues in your code, but I think this point should be sorted first. Additionally, it would help you figure out when it fails and why.

author: panoss
author_rank: Frequent Contributor
timestamp: January 29, 2020, 08:17:17 am
content: Quote from: thm_w on January 28, 2020, 11:36:19 pmNo I haven't but I 've ordered a logic analyzer exactly for this purpose!Quote from: free_electron on January 29, 2020, 01:41:04 amAs I 've mentioned, I 've tried lots of differrent intervals, 10 seconds, 30, 60 etc with the same result.Quote from: SiliconWizard on January 29, 2020, 01:51:37 amYes, this is where I started from.It worked exactly the same way as my code on github.Quote from: SiliconWizard on January 29, 2020, 01:51:37 amYou 're right, I will add the error checking that the initial library (wdomski) had.Now, about 'polling'?.Which parts of the code did this in the initial library? (so that I 'll reproduce them in my code)I think it 's an SPI problem, this is why I have ordered the logic analyzer.And have tried ANY possible value in it 's parameters (in STM32CubeMX).But without success.So, waiting for my logic analyzer to come, what else could I try with SPI?EDIT: for the shake of simplicity, I reverted back to the initial code (wdomski).So now I have the error checking and polling.The fies changed (to my github also) are: main.c, main.h, SX1278.h, SX1278.cLet me remind you the result is the same.

author: bugnate
author_rank: Regular Contributor
timestamp: January 29, 2020, 09:25:48 am
content: Another angle, what are the packet stats (RSSI and SNR) for the packets that do get through? Is CRC error interrupt enabled and logged or are you otherwise verifying the messages you receive? You only mention the transmitter, do you have a known good RX side? Are you using the Helical antenna in the RA-01 picture?My gut says it is not a SPI problem, but do the basics before you pull your hair out on higher level stuff... What is your Vdd (3.3v?) and it's the same rail on both the radio and F0? You are running the SPI pretty slowly (I see 31.25 kHz), it would take something significant to cause intermittent errors (but one can imagine). In your old code at least, I saw you were checking the value of ID register or something, so it was presumably working at least some of the time...I've worked with a sister chip (SX1276) but with a different driver base than yours. My experience was that the interface is relatively quirky and fragile. So reverting to known good code was probably a good instinct, IMO.Quote from: free_electron on January 29, 2020, 01:41:04 amLoRaWAN maybe, but he's got no MAC here (yet) so it doesn't apply and he only answers to ETSI/FCC/etc. (Not to say one way or the other what that situation would be.)

author: panoss
author_rank: Frequent Contributor
timestamp: January 29, 2020, 11:34:01 am
content: Quote from: bugnate on January 29, 2020, 09:25:48 amWith my current code, I have an RSSI around -90 to -100.With my previous code I had an RSSI around -40.SNR around -5 to -7.Quote from: bugnate on January 29, 2020, 09:25:48 amThe receiver is an ESP8266+LoRa, it uses no CRC at all.As I mention in my first post, I also have a transmitter board with Arduino.On this board my LoRa module works fine.Quote from: bugnate on January 29, 2020, 09:25:48 amYes, 3.3V. Both STM32 and LoRa are on the same rail.

author: bugnate
author_rank: Regular Contributor
timestamp: January 29, 2020, 11:07:16 pm
content: Quote from: panoss on January 29, 2020, 11:34:01 amSo a RSSI of -90 dBm (your current code) at short range is an incidental reception and would suggest to me a radio configuration issue. Or a RF signals problem, but you are mostly using a module and you say the same hw works with another platform. At -40 dBm it is plausibly working, but you say that you still get a lot of loss so there must be something additional going on. The SNR values are not great, not terrible; plausibly OK. You'd think it'd be better (at least positive), but I never paid them much attention. Maybe near-field effect (too close or too much power?).My only other suggestion at this point would be to cross reference with the old Semtech driver, bottom of the below link, one SPI transaction at a time. Or any other driver for that matter.https://www.semtech.com/products/wireless-rf/lora-transceivers/sx1278Other long-shot questions:What is your power supply, it is good for the 500mW (max) or so during transmission (+20 dBm)?Instead of doing 100 packet sequences, what about 1 packet per reset (easy if you have a button). Is that same or more reliable?Are you *sure* your receiver is always camping in RX mode and available?

author: Nerull
author_rank: Frequent Contributor
timestamp: January 30, 2020, 01:26:28 am
content: Are you using an external antenna and is the setup identical in both cases?It's possible to mate SMA and SMA-RP connectors in such a way that they appear to go together fine but don't make any actual connection, I've seen that before with lora modules.

author: panoss
author_rank: Frequent Contributor
timestamp: January 30, 2020, 08:59:10 am
content: The power supply I 'm using is more than adequate: a 18650 Li-ion (with auto step-down step-up module (outputs 3.3V)).The same I 'm using with the other board where everything works fine.The receiver stays always on no matter which of the two transmitter I use.I 'm usinghelical antennas.The setup is exactly the same in both cases.I changed the code for setting the frequency and now the RSSI from -90 is at about -30.But this has not decreased the percentage of the lost messages.I tried the 'one packet per reset' but I see no difference.

author: kamtar
author_rank: Regular Contributor
timestamp: January 30, 2020, 01:48:25 pm
content: You can use one of the DIO pins as a TxDone interrupt so use that to count packets sent (or check if they were sent successfully in polling) if it matches then your problem will be probably wrong configuration.

author: panoss
author_rank: Frequent Contributor
timestamp: January 30, 2020, 03:24:11 pm
content: I tried with TxDone, seems ok.