Can't initialize SX1268 lora module

Hi there:
I tried to build my custom firmwire since i made a pcb with a esp-32-s module and a ra-01s(sx1268) lora module on it. I followed the doc and successfully compiled, but when i flash to esp32 the oled show start menue and chip reboot over and over again. and this is debug output:

//\ E S H T /\ S T / C
??:??:?? 0 booted, wake cause 0 (boot count 1), reset_reason=reset
??:??:?? 0 Filesystem files:
??:??:?? 0   /prefs/channels.proto (53 Bytes)
??:??:?? 0   /prefs/db.proto (139 Bytes)
??:??:?? 0   /prefs/radio.proto (5 Bytes)
??:??:?? 0 I2C device found at address 0x3c
??:??:?? 0 0x3 subtype probed
??:??:?? 0 ssd1306 display found
??:??:?? 0 done
??:??:?? 0 Meshtastic hwvendor=255, swver=1.3.5.e5b19fdf-d
??:??:?? 0 Setting random seed 1103890559
??:??:?? 0 Total heap: 237844
??:??:?? 0 Free heap: 205716
??:??:?? 0 Total PSRAM: 0
??:??:?? 0 Free PSRAM: 0
??:??:?? 0 NVS: UsedEntries 267, FreeEntries 363, AllEntries 630, NameSpaces 8
??:??:?? 0 Setup Preferences in Flash Storage
??:??:?? 0 Number of Device Reboots: 1173
??:??:?? 0 Initial packet id 1772541751, numPacketId 4294967295
??:??:?? 0 Setting default channel and radio preferences!
??:??:?? 0 Expanding short PSK #1
??:??:?? 0 Wanted region 0, using Unset
??:??:?? 0 Loading /prefs/db.proto
??:??:?? 0 Loaded saved preferences version 11
??:??:?? 0 Loading /prefs/radio.proto
??:??:?? 0 Loading /prefs/channels.proto
??:??:?? 0 Number of Device Reboots: 1173
??:??:?? 0 Expanding short PSK #1
??:??:?? 0 Wanted region 0, using Unset
??:??:?? 0 region=0, NODENUM=0xf7ecc4c0, dbsize=1
??:??:?? 0 Read RTC time as 50 (cur millis 230) quality=0
??:??:?? 0 Using MSL altitude model
??:??:?? 0 WANT GPS=1
??:??:?? 0 Setting GPS power=1
??:??:?? 2 ERROR: No UBLOX GPS found
??:??:?? 2 Using NMEA Mode
??:??:?? 2 WANT GPS=1
??:??:?? 2 GxGSA NOT available
??:??:?? 2 Turning on screen
??:??:?? 2 Module wants a UI Frame
??:??:?? 2 Starting meshradio init...
??:??:?? 2 (bw=250, sf=11, cr=4/8) packet symLen=8 ms, payloadSize=16, time 559 ms
??:??:?? 2 Set radio: name=LongFast, config=2, ch=19, power=0
??:??:?? 2 Radio myRegion->freqStart / myRegion->freqEnd: 902.000000 -> 928.000000 (26.000000 mhz)
??:??:?? 2 Radio myRegion->numChannels: 104
??:??:?? 2 Radio channel_num: 19
??:??:?? 2 Radio frequency: 433.174988
??:??:?? 2 Short packet time: 559 msec
??:??:?? 2 Set radio: final power level=22
??:??:?? 2 ++++++++++++++++++++++++++++++++SX126x init result -20
??:??:?? 2 Current limit set to 140.000000
??:??:?? 2 Current limit set result 0
assertion "err == ERR_NONE" failed: file "src/mesh/SX126xInterface.cpp", line 223, function: void SX126xInterface<T>::startReceive() [with T = SX1268]
abort() was called at PC 0x40126a33 on core 1

ELF file SHA256: 0000000000000000

Backtrace: 0x4008fdbb:0x3ffd5d50 0x40090141:0x3ffd5d70 0x40126a33:0x3ffd5d90 0x400de311:0x3ffd5dc0 0x400de416:0x3ffd5de0 0x400dda3e:0x3ffd5e10 0x4012527a:0x3ffd5e40

Rebooting...
ets Jul 29 2019 12:21:46

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:728
load:0x40078000,len:9132
load:0x40080400,len:5100
entry 0x40080640
E (657) spiram: SPI RAM enabled but initialization failed. Bailing out.
⸮⸮

the line start with “+++++” is the simble i put in source code, so i checked Radiolib and it tells that sx1268 is not properly configured:

|   \brief User tried to execute modem-exclusive method on a wrong modem. |
| - |
|  |   For example, this can happen when you try to change LoRa configuration when FSK modem is active. |
|  | */ |
|  | #define RADIOLIB_ERR_WRONG_MODEM                               (-20) |

Then i changed the code in “SX126xInterface.cpp” line 55:

`int res = lora.begin(getFreq(), bw, sf, cr, syncWord, power, preambleLength, tcxoVoltage, useRegulatorLDO);`

to:

`int res = lora.begin(getFreq(), 125.0, 9, 7, 0x2b, 17, 32, 0, false);`

and it did enter mainpage, but on screen it shows “Critical fault#3”, meaning that lora module not found.

I have tried a demo from RadioLib and i can say the module ra-01s works well, so i really want to know where i should go to solve the problem.

My sch:

Looks like you have set “region 0” or no region at all.

region 0 seems to have weird settings because the output says :

Radio myRegion->freqStart / myRegion->freqEnd: 902.000000 → 928.000000 (26.000000 mhz)
Radio myRegion->numChannels: 104
Radio channel_num: 19
Radio frequency: 433.174988

I think the frequency of 433.174988 is not valid.

Did you set a region or did you set no region at all ?
If not, why don’t you use : set region 1 ?

1 Like

Thank you for reply!
I tried to find the config file but really can not find where to set the region…
a little more hint?

I have sent you a message.

Thank you for help!
I changed settings in file the freq is ok, but still no luck, sx1268 won’t work. Debug output sx1268 init code -20.
and i changed back “SX126xInterface.cpp” line 55 to source code:
int res = lora.begin(getFreq(), bw, sf, cr, syncWord, power, preambleLength, tcxoVoltage, useRegulatorLDO);

//\ E S H T /\ S T / C

??:??:?? 0 booted, wake cause 0 (boot count 1), reset_reason=reset
??:??:?? 0 Setting forceSoftAP = 1
??:??:?? 0 Filesystem files:
??:??:?? 0   /prefs/db.proto
??:??:?? 0   /prefs/radio.proto
??:??:?? 0   /prefs/channels.proto
??:??:?? 0 I2C device found at address 0x3c
??:??:?? 0 ssd1306 display found
??:??:?? 0 done
??:??:?? 0 Meshtastic hwvendor=255, swver=1.2.59.fb5e8ad-d, hwver=unset
??:??:?? 0 Setting random seed 1764028136
??:??:?? 0 Total heap: 254300
??:??:?? 0 Free heap: 219932
??:??:?? 0 Total PSRAM: 0
??:??:?? 0 Free PSRAM: 0
??:??:?? 0 NVS: UsedEntries 290, FreeEntries 340, AllEntries 630, NameSpaces 8
??:??:?? 0 Setup Preferences in Flash Storage
??:??:?? 0 Number of Device Reboots: 1667
??:??:?? 0 Initial packet id 981266028, numPacketId 4294967295
??:??:?? 0 Setting default channel and radio preferences!
??:??:?? 0 Expanding short PSK #1
??:??:?? 0 Wanted region 0, using Unset
??:??:?? 0 Loading /prefs/db.proto
??:??:?? 0 Loaded saved preferences version 11
??:??:?? 0 Loading /prefs/radio.proto
??:??:?? 0 Loading /prefs/channels.proto
??:??:?? 0 Number of Device Reboots: 1667
??:??:?? 0 Expanding short PSK #1
??:??:?? 0 Wanted region 2, using EU433
??:??:?? 0 region=2, NODENUM=0xf7ecc4c0, dbsize=1
??:??:?? 0 Read RTC time as 0 (cur millis 210) quality=0
??:??:?? 0 Using MSL altitude model
??:??:?? 0 WANT GPS=1
??:??:?? 0 Setting GPS power=1
??:??:?? 2 ERROR: No UBLOX GPS found
??:??:?? 2 Hoping that NMEA might work
??:??:?? 2 WANT GPS=1
??:??:?? 2 GxGSA NOT available
??:??:?? 2 Turning on screen
??:??:?? 2 Plugin wants a UI Frame
??:??:?? 2 Starting meshradio init...
??:??:?? 2 (bw=125, sf=12, cr=4/8) packet symLen=32 ms, payloadSize=16, time 2269 ms
??:??:?? 2 Set radio: name=LongSlow, config=3, ch=2, power=0
??:??:?? 2 Radio myRegion->freq: 433.174988
??:??:?? 2 Radio myRegion->spacing: 0.200000
??:??:?? 2 Radio myRegion->numChannels: 8
??:??:?? 2 Radio channel_num: 2
??:??:?? 2 Radio frequency: 433.174988
??:??:?? 2 Short packet time: 2269 msec
??:??:?? 2 SX126x init result -20
??:??:?? 2 Warning: Failed to find SX1268 radio
??:??:?? 2 NOTE! Recording critical error 3 at src/main.cpp:297
??:??:?? 2 PowerFSM init, USB power=1
??:??:?? 2 Enter state: BOOT

settings i changed:

changes in main.cpp

SPI.begin(18,19,23,16); // my diy board , pin spi_cs is not connected

i tested this pin definition and used

lora.begin(433, 125.0, 9, 7, 0x2b, 17, 32, 0, false);

to test my module, it worked well.
in the debug out i can see -20 means error code in radiolib
but i don’t know where i missed.

Any success? I would like to buy a pair of T-Beams on SX1268 and wonder if it compatible with Meshtastic.

You should not to change main.cpp to reassign your pins number. There are special configuration file for that - variant.h.

#define LORA_DIO0 26  // a No connect on the SX1262/SX1268 module
#define LORA_RESET 23 // RST for SX1276, and for SX1262/SX1268
#define LORA_DIO1 33  // IRQ for SX1262/SX1268
#define LORA_DIO2 32  // BUSY for SX1262/SX1268

And not forget to use this initialization:

#define USE_SX1268

You could use variant.h from the DIY project as starting point in your project.

There is also platformio.ini with building flags, such as -D EBYTE_E22 for using with the power 30S EBYTE modules.

Not having one at hand, but the SX1268 support was added for meshtastic tbeam a few months back.So if you get one, even if there’s a bug in the implementation, it will most likely be fixed quick.

1 Like