rust-iot / rust-radio-sx127x

Rust driver for the Semtech SX127x series of Sub-GHz LoRa/ISM radio transceivers
Mozilla Public License 2.0
33 stars 16 forks source link

Question: SPI settings Raspberry Pi 3 B+ Lora HAT #7

Open rhizoome opened 4 years ago

rhizoome commented 4 years ago

I am new to embedded, I hope it is ok to ask here, I have so much information and I can't figure out how it all relates. I am hoping to get some pointer that helps me to connect the information. I am trying to find out how the settings:

translate to the information from the Lora HAT [1] From their sample code that works and runs with WiringPI [2] I get these pin numbers:

int ssPin = 6;
int dio0  = 7;
int RST   = 0;

The names the lora HAT uses in documentation is

The biggest problem is, every subsystem numbers the pins different. See image:

image

Does the kernel translate the pin numbers too? I mean we access SPI via kernel device.

I converted the numbers in many way from most reasonable to some strange ways. What ever I do there are two outcomes

image

I also read about SPI and naming conventions didn't completely match neither rust-radio-sx127x nor one used in the Lora HAT.

[1] http://wiki.dragino.com/index.php?title=Lora/GPS_HAT [2] http://wiringpi.com/

ryankurte commented 4 years ago

ahh yes this is a classic embedded adventure, sorry that i haven't documented the generics better (if you fancy a PR later we could add some better docs and instructions for this shield).

I learned that nss, ss, ssPin, ce (chip enable) and cs (chip select) is the same thing.

there isn't super common nomenclature but yep, all talking about the SPI chip select pin

I assume that RST is reset

yep

This leaves dio0 to be busy??

yeah, the radio has a set of configurable DIO pins, at boot DIO0 is a BUSY signal that lets you know whether the radio is, busy. Technically it's possible to use other pins for this, but practically this could probably be renamed to DIO0 to be less ambiguous as there isn't a lot of reason to remap this.

I converted the numbers in many way from most reasonable to some strange ways. What ever I do there are two outcomes

  • InvalidDevice (After that, the sx127x still works with the C program)
  • ResourceBusy (The sx127x is bricked and I have to reboot)

As in you can interact with the device and send radio messages and things with sx127x-util? Usually this means the configuration is wrong and you can't communicate with the device in which case nothing should work.

It's is however possible you have a different version of the IC and that this needs updating to add the different version number.

It's also possible you haven't got the right reset pin mapped, because the driver will attempt to reboot the radio on connect / you shouldn't need to restart the pi.

I also read about SPI and naming conventions didn't completely match neither rust-radio-sx127x nor one used in the Lora HAT.

So long as you've enabled the SPI / are using the right spidev you shouldn't need to worry about MOSI/MISO (this is defined by the SPI device, and works on my rpi), should be just DIO=7, RST=0, and CS=6 from the table you linked. The pin numbers you're looking for (that the kernel understands) are the ones on the rpi gpio header, as in the image here.

rhizoome commented 4 years ago

EDIT: Solved

The config is:

export SX127X_CS=25
export SX127X_RST=17
export SX127X_BUSY=4

The table I linked must have referred to another raspi-version.

I'll do some experimenting and then I try to do a PR improving documentation.