Problem with LoRa: sx127x.py --- Exception: Invalid version

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
doceave
Posts: 31
Joined: Fri Feb 14, 2020 4:02 pm

Problem with LoRa: sx127x.py --- Exception: Invalid version

Post by doceave » Wed Sep 15, 2021 6:40 pm

Hi there

I have no doubt that someone here can tell me why I cannot initiate communication with my sx1276:

My setup:
> ESP32-WROVER-B
> Micropython: esp32spiram-20210902-v1.17.bin
> Module: https://github.com/lemariva/uPyLoRaWAN
- config.py has been modified according to my circuit layout
- sx1276.py has been copied to the ESP32

Reproducing the problem:
> At the REPL I run the following:

Code: Select all

from config import *
from machine import Pin, SPI
from sx127x import SX127x

device_spi = SPI(baudrate = 10000000, 
        polarity = 0, phase = 0, bits = 8, firstbit = SPI.MSB,
        sck = Pin(device_config['sck'], Pin.OUT, Pin.PULL_DOWN),
        mosi = Pin(device_config['mosi'], Pin.OUT, Pin.PULL_UP),
        miso = Pin(device_config['miso'], Pin.IN, Pin.PULL_UP))

lora = SX127x(device_spi, pins=device_config, parameters=lora_parameters)
The following results:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sx127x.py", line 121, in __init__
Exception: Invalid version.
I have attempted the following to remedy the situation:
> Powered from USB and from 3V lithium cell --- both yield same result
> Installed 100nF and 1uF capacitor over the sx1276 module
> Removed transistor Q1 and powered the sx1276 direct from VCC
> Swapped out sx1276 module for another one
> Copper on the board is 12mil 1oz
> This is the 915MHz version; 78mm wire soldered to PCB as antenna

Please would someone advise me further?

Many many thanks

> Schematic
SchematicPIR.jpg
SchematicPIR.jpg (100.58 KiB) Viewed 3122 times
> PCB
PCB_PIR.jpg
PCB_PIR.jpg (167.65 KiB) Viewed 3122 times

marcidy
Posts: 133
Joined: Sat Dec 12, 2020 11:07 pm

Re: Problem with LoRa: sx127x.py --- Exception: Invalid version

Post by marcidy » Thu Sep 16, 2021 6:01 pm

I would comment out the version check. It doesn't actually do anything. I just print it out as a warning.

mine now does this:

Code: Select all

        re_try = 0                                                              
        # check version                                                         
        while(init_try and re_try < 5):                                         
            version = self.readRegister(REG_VERSION)                            
            re_try = re_try + 1                                                 
            if(version != 0):                                                   
                init_try = False                                                
        if version & 0xF0 != 0x10:                                              
            print('Warning: unsupported sx127x version: {}'.format(version)) 
After two years working with sx1276's, I have zero issues and it fails the version check about 50% of the time.

doceave
Posts: 31
Joined: Fri Feb 14, 2020 4:02 pm

Re: Problem with LoRa: sx127x.py --- Exception: Invalid version

Post by doceave » Fri Sep 17, 2021 8:27 am

Ahh Marcidy --- you are amazing! Thanks for your care.

I will test this and revert asap :)

doceave
Posts: 31
Joined: Fri Feb 14, 2020 4:02 pm

Re: Problem with LoRa: sx127x.py --- Exception: Invalid version

Post by doceave » Thu Sep 23, 2021 6:24 pm

Ahhh no... I hope I am one step closer to success...

This now executes without any problem (I commented out the entire section about version warning):

Code: Select all

lora = SX127x(device_spi, pins=device_config, parameters=lora_parameters)
However processing hangs following this:

Code: Select all

payload = "Testing"
lora.println(payload)
Is anyone able to advise me as to how I may further troubleshoot?

Thanks

marcidy
Posts: 133
Joined: Sat Dec 12, 2020 11:07 pm

Re: Problem with LoRa: sx127x.py --- Exception: Invalid version

Post by marcidy » Fri Sep 24, 2021 5:47 am

Are you confident the SPI bus is working well, and you can get responses from the chip by reading registers? Are you confident that your device config correctly reflects your hardware, specifically with respect to the DIO mappings (section 4.2.11 in the SEMTECH SX1276/7/8/9 datashseet)?

The driver is spinning endlessly in the end_packet while loop. This can be caused by your SPI bus not working correctly since you never get read(REG_IRQ_FLAGS) & IRQ_TX_DONE_MASK == 0. It can be caused by not configuring the chip correctly.

First, make sure your spi is working. If it is, you can work through each function call by hand on the repl to see exactly what's going on. instead of calling println, do what println does by hand, and check the contents of the registers before and after to see what effect occurs, and if that agrees with the datasheet.

You can debug this on the repl just like any other program. The hard part is knowing the communication over SPI is working. IF you have a scope or a logic analyzer, now is a great time to probe the SPI lines to make sure they work.

doceave
Posts: 31
Joined: Fri Feb 14, 2020 4:02 pm

Re: Problem with LoRa: sx127x.py --- Exception: Invalid version

Post by doceave » Fri Sep 24, 2021 7:53 am

@Marcidy --- I am learning so much! I will walk through println step by step ad then, if need be, crack an oscilloscope I inherited. Many many thanks.

doceave
Posts: 31
Joined: Fri Feb 14, 2020 4:02 pm

Re: Problem with LoRa: sx127x.py --- Exception: Invalid version

Post by doceave » Sat Sep 25, 2021 8:38 am

@Marcidy --- just as you said: Walking through each step manually reveals that the code is hanging waiting for end_packet loop to finish...

Before I troubleshoot further would you kindly just cast an eye over my schematic in my first post? This is the LoRa module I have used: https://www.lcsc.com/product-detail/LoR ... 18835.html

Also, for test purposes I have bypassed the PNP transistor and supplied the module from the lithium battery direct (so that is not adding to the problem list)

marcidy
Posts: 133
Joined: Sat Dec 12, 2020 11:07 pm

Re: Problem with LoRa: sx127x.py --- Exception: Invalid version

Post by marcidy » Sat Sep 25, 2021 3:49 pm

I'm not familiar with that module or your design, so looking at the schematic would be more work than I have time available. It will take a couple days to review every pin assignment and register configuration and confirm that the chip is powered and responsive to SPI, and in the end you will fully understand the chip and design. It's tedious work but required to understand the design. Spreadsheets are helpful to keep track of register values and build a mock-up of the chip.

Post Reply