Comments (11)
I think lgpio might be the way to go here. Event management with gpiod is a pain in this mode... we'd have to spawn a thread, lock/unlock data structures, etc... I don't think it's worth the trouble, especially given lgpio works just fine and also uses spidev (and the kernel GPIO interface directly). Once #1075 lands I will get the HAL into shape for merging.
from radiolib.
Thanks for pointing this out! So far I've been using pigpio without problems, though the need to run it as root has been a pain, so if we can switch to something more modern that would be great.
Regarding the error you are seeing, it seems that RadioLib is having trouble reading out the value it has just written into the SPI register, so the first place I would be looking at is the SPI configuration (number of bits, clock polarity/phase etc).
from radiolib.
Clock polarity and phase should be the same. lgpio uses 8 bits. I'm really at a loss here.
from radiolib.
So perhaps to help troubleshoot, here's some information:
My setup
- Raspberry Pi Zero 2W
- Breadboard
- Jumper wires
- RFM95W module from Adafruit
- Quarter-wave antenna
Things I have checked
- My sleep timers are ok
- My timestamp functions are ok
- The rising/falling edge stuff has no effect
- Clock, polarity, and phase
- The original example, which works
Things that I don't think are wrong but I would be open to changing my mind
- Pin mapping differences between pigpio and lgpio, but I think they're the same
- Wiring, given the pigpio example works I think it's fine tho?
- OS config; maybe I need to do something special to configure the device with spidev? I didn't have to do that with pigpio. I am using
dtoverlay=spi0-0cs
because RadioLib manages CS on its own (given I am getting something back from the chip, it's just incorrect, I think the CS line is working)
from radiolib.
I tried your lgpio HAL with RPi 3B and SX1276 and I'm getting back pretty much the same result. I did do one change, in that I used GPIO 4 as the chip select instead of GPIO8/CE0 (since that was always returning "GPIO busy" error).
RLB_SPI: R 42 12
RLB_SPI: R 1 9
RLB_SPI: R 1 9
RLB_SPI: W 1 9
RLB_SPI:
RLB_SPI: address: 0x1
RLB_SPI: bits: 2 0
RLB_SPI: value: 0x1
RLB_SPI: current: 0x9
RLB_SPI: mask: 0x7
RLB_SPI: new: 0x9
RLB_SPI: read: 0x0
failed, code -16
I also tried running this with SX1261 (because it has different SPI interface), and got back something slightly different:
Initializing ... RLB_DBG:
RadioLib Info
Version: "6.5.0.0"
Platform: "Generic"
Compiled: "Apr 24 2024" "05:50:22"
RLB_SPI: CMDW 80
RLB_SPI: SI 0
RLB_SPI: SO AA AA
RLB_SPI: CMDR 1D 3 20
RLB_SPI: SI 0 0 0 0 0 0 0 0 0 0 0 0 0 0 000
RLB_SPI: SO A2 A2 A2 A2 53 58 31 32 36 31 20 56 32 44 20 32 44 3032 0
RLB_DBG: Found SX126x: RADIOLIB_SX126X_REG_VERSION_STRING:
RLB_DBG: 0000320 53 58 31 32 36 31 20 56 32 44 20 32 44 30 32 00 | SX1261 V2D 2D02.
RLB_DBG:
RLB_DBG: M SX126x
RLB_SPI: CMDW 80
RLB_SPI: SI 0
RLB_SPI: SO A2 A2
RLB_SPI: CMDW 80
RLB_SPI: SI 0
RLB_SPI: SO A2 A2
RLB_SPI: CMDW 80
RLB_SPI: SI 0
RLB_SPI: SO A2 A2
RLB_SPI: CMDR 17
RLB_SPI: SI 0 0 0
RLB_SPI: SO A2 A2 0 20
RLB_SPI: CMDW 7
RLB_SPI: SI 0 0
RLB_SPI: SO A2 A2 A2
RLB_SPI: CMDW 97
RLB_SPI: SI 0 0 1 40
RLB_SPI: SO A2 A2 A2 A2 A2
RLB_SPI: CMDW 8F
RLB_SPI: SI 0 0
RLB_SPI: SO A2 A2 A2
RLB_SPI: CMDW 8A
RLB_SPI: SI 1
RLB_SPI: SO A2 A2
RLB_SPI: CMDW 93
RLB_SPI: SI 20
RLB_SPI: SO A2 A2
RLB_SPI: CMDW 88
RLB_SPI: SI 3 16 A 0 0 0 0
RLB_SPI: SO A2 A2 A2 A2 A2 A2 A2 A2
RLB_SPI: CMDW 2
RLB_SPI: SI 43 FF
RLB_SPI: SO A2 A2 A2
RLB_SPI: CMDW 8
RLB_SPI: SI 0 0 0 0 0 0 0 0
RLB_SPI: SO A2 A2 A2 A2 A2 A2 A2 A2 A2
RLB_DBG: GPIO post-transfer timeout, is it connected?
failed, code -705
Looks like the SPI can interface with the radio fine. Suspiciously enough, there seems to be no actual timeout, which should be one second, but the program returns immediately. This could also be the cause for the -16, since on SX127x, modification of the operation mode register (which is the thing that is failing) takes a couple ms to propagate and RadioLib waits for that.
After that, I realized that the HAL uses unsigned long
for its millis
/micros
methods, while internally uint32_t
is mostly used, which is an oversight on my part. Doing a dirty cast to to uint32_t
resolves the -16 error. There might be some other timing problems with that though, so maybe a better workaround would be to subtract part of the Unix timestamp (E.g. Januray 1st 2020) in the HAL so that it's not overflowing the 32-bit numbers.
unsigned long millis() override {
uint32_t time = lguTimestamp() / 1000000UL;
return time;
}
unsigned long micros() override {
uint32_t time = lguTimestamp() / 1000UL;
return time;
}
from radiolib.
Huh! I swore that was fine... but that makes sense! I will give it a spin locally and report back.
I'm also giving out a try porting it to gpiod and spidev directly. It might be a better direction, although it's a lower-level API all around. I'll keep you posted.
from radiolib.
unsigned long millis() override { uint32_t time = lguTimestamp() / 1000000UL; return time; } unsigned long micros() override { uint32_t time = lguTimestamp() / 1000UL; return time; }
That worked! Wow, thanks, I had been banging my head against this for days. This was such a non-obvious error.
However, it's probably better to move the code that interacts with millis/micros to unsigned long. That would probably be more ideal.
from radiolib.
I'm also giving out a try porting it to gpiod and spidev directly
That would be extremely interesting!
it's probably better to move the code that interacts with millis/micros to unsigned long
Definitely, that's the actual fix on RadioLib side. I can push that in the next couple of days (or you know - PRs are welcome ;) ).
from radiolib.
I'm also giving out a try porting it to gpiod and spidev directly
That would be extremely interesting!
it's probably better to move the code that interacts with millis/micros to unsigned long
Definitely, that's the actual fix on RadioLib side. I can push that in the next couple of days (or you know - PRs are welcome ;) ).
This is done in #1075.
from radiolib.
@Elizafox I've been using your lgpio HAL in my development for a while now and it seems to be working just fine (with a minor addition of tone
/noTone
implementation) - if you could open up a PR we could merge this. Thanks!
from radiolib.
@Elizafox I've changed the example and the CI to use lgpio in bc36c1e - it's been working great, so I don't think there's any reason not to do this change. Thanks for pointing me in this direction!
from radiolib.
Related Issues (20)
- Sending more than one message in POCSAG HOT 1
- 'virtual float PhysicalLayer::getRSSI()' was hidden ESP-IDF HOT 10
- Feature request: AX.25 parser HOT 4
- Think I introduced a bug with Promiscuous (requireCarrierSense) when used with directMode HOT 2
- Better error handling in the HAL HOT 3
- CC1101 Direct Mode getRSSI() only ever returns -74.0 HOT 2
- importing Radiolib into VSCODE + Platformio with NRF52840 board does not compile HOT 13
- SX1280 startTransmit after CAD not working HOT 4
- Move examples to a separate repository HOT 14
- Invalid calibrateImage parameters prevent initializing with 915MHz frequency on SX126x-based STM32WLx HOT 2
- #include <Radiolib/SX1262.h> is available to use less space than the hole library? HOT 1
- Minor issue in startReceiveDutyCycleAuto HOT 3
- GFSK support for SX1231/RFM69 and SX127x/RFM9x HOT 2
- Support for MSPM0 Microcontroller HOT 1
- STM8 Arduino HOT 2
- This line cause errors when build HOT 1
- AFSK not working on LILYGO T3_V1.6.1 HOT 2
- Examples not running on seed studio XIAO esp32C3 HOT 7
- Extra bits after the message using RFM69HCW module on feather 32u4 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from radiolib.