almusil / rfm69

A generic rust driver to support RFM69 family wireless chips.
Apache License 2.0
9 stars 9 forks source link

Having trouble getting this working with Adafruit RFM69 bonnet on Raspberry Pi #26

Closed qwandor closed 3 years ago

qwandor commented 3 years ago

This is more of a support request than a bug, let me know if there's a more appropriate place to ask.

I'm trying to get this working with an Adafruit RFM69 bonnet on my Raspberry Pi 4. For a start I'm trying to run the receive example included with the crate.

According to the pinout, RST is connected to GPIO 25 and CS to CE1, so I changed the example to use /dev/spidev0.1 (which from what I understand will result in CE1 being pulled high while communicating). I don't understand why the example also sets up a SysfsPin for CS. What is this supposed to do, given that spidev is already managing the CS line? I tried commenting out the code in lib.rs which uses CS, and changing receive.rs to set_direction(Direction::Low) so it isn't holding RST high, but it's still not working; it reports every register value as being 0x00 and then panics on the recv call.

Any idea what I'm missing here? And why does Rfm69::new take a separate pin for CS?

almusil commented 3 years ago

Hi,

so this library is design to manage CS pin on it's own. That might be helpful for setups where there are multiple devices sharing the bus and we can also optimize multiple writes/reads see implementation of read_many/write_many.

However you can still let the HW manage the CS and pass "mock" or some dummy pin to the Rfm69 struct. For the mock take a look at the src/tests.rs, this mock does "nothing" but provides the needed OutputPin trait.

The examples were written skipping the HW CS pin, and used the pin 25 instead. Looking at the pinout of the board it seems that the "mock" CS pin is your best bet. Up to you but I would not recommend commenting out some parts of the library.

If any of the suggestions above wouldn't help let me know and we can try to figure out further what is going on.

qwandor commented 3 years ago

So, uh, I have two Raspberry Pis and it turns out I was SSHing into the wrong one to run the code. It failed because there was no radio connected.

But thanks for the suggestion! OutputPinMock works, I was thinking of doing something similar. I also needed to change write_many/read_many to use Transactional rather than Write and Transfer, so that the CS line isn't released between operations. I'll send you a PR.