SkyLok/chip_test_example/README.md
2026-05-29 09:30:44 +02:00

112 lines
2.6 KiB
Markdown

# chip_test_example
Tests for LR1121 LoRa, ICM-20948 IMU, u-blox GPS on Raspberry Pi Zero W 2.
Header-only drivers, kernel ioctls, no external libs.
Driver: `lr1121_malnus.hpp` — crystal oscillator, RF switch via DIO5/DIO6.
---
## Wiring
### LR1121 (SPI0)
| Module | Pi GPIO | Pi pin |
|---------|---------|--------|
| SCK | GPIO11 | 23 |
| MOSI | GPIO10 | 19 |
| MISO | GPIO9 | 21 |
| NSS | GPIO8 | 24 |
| BUSY | GPIO24 | 18 |
| NRESET | GPIO25 | 22 |
| DIO5 | — | chip-driven RF switch (RFSW0) |
| DIO6 | — | chip-driven RF switch (RFSW1) |
| DIO9 | GPIO4 | 7 |
| DIO8 | GPIO23 | 16 |
DIO5 and DIO6 are driven directly by the LR1121 — they go to your module's RF
switch and do not connect to the Pi. The driver configures them automatically
via `SetDioAsRfSwitch`: HIGH on DIO5 in RX, HIGH on DIO6 in TX, both LOW in standby.
Enable SPI: `sudo raspi-config` → Interfaces → SPI → Yes → reboot
### ICM-20948 (I2C1)
| Module | Pi GPIO | Pi pin |
|--------|---------|--------|
| SDA | GPIO2 | 3 |
| SCL | GPIO3 | 5 |
| AD0 | GND → addr 0x68 / VCC → addr 0x69 |
Enable: `sudo raspi-config` → Interfaces → I2C → Yes → reboot
### u-blox GPS (UART0)
| Module | Pi GPIO | Pi pin |
|--------|---------|--------|
| TX | GPIO15 | 10 |
| RX | GPIO14 | 8 |
Enable: `sudo raspi-config` → Interfaces → Serial Port → login shell: No, hardware: Yes → reboot
---
## Build
```sh
sudo apt install g++ make
make
```
Run verbose first so you see exactly where it fails:
```sh
sudo ./lora_rx -v
sudo ./imu_test -v
./gps_test -v
```
---
## LoRa debug
```sh
ls /dev/spidev0.0 # SPI enabled?
sudo ./lora_rx -v # step labels show exactly which command hangs
```
If it hangs at `Calibrate` — the chip isn't responding over SPI at all.
Check wiring, CS, and that SPI is enabled. The crystal needs no tuning.
If TX/RX runs but packets never arrive — check that DIO5/DIO6 reach the RF
switch on your module. Without the switch, the antenna path is disconnected.
If the chip is stuck in bootloader (fw < 0x02xx), escape with:
```sh
sudo ./lora_rx --reset
```
---
## IMU debug
```sh
sudo i2cdetect -y 1 # 0x68 or 0x69 must show
sudo ./imu_test -v # auto-detects both addresses
sudo ./imu_test -v -r # raw 16-bit values
```
Nothing on i2cdetect: I2C not enabled, wrong wiring, or no pull-ups on SDA/SCL.
---
## GPS debug
```sh
ls -la /dev/serial0
stty -F /dev/serial0 38400 raw && cat /dev/serial0 # raw NMEA bytes
./gps_test -v -a # all sentences
./gps_test -b 9600 # try different baud
```