adafruit / RadioHead

A github'ified version of http://www.airspayce.com/mikem/arduino/RadioHead/
Other
185 stars 115 forks source link

How do I use a different hardware SPI interface if my board supports more than one? #6

Open TehProgrammer opened 6 years ago

TehProgrammer commented 6 years ago

I am interested in using this library for a LoRa antenna tracker and that would require running two radios at once on two different SPI ports. I have looked into it, and it seems there is a way to do it. I just can't figure it out after looking at all the code...

gojimmypi commented 6 years ago

With the RadioHead drivers, it is simply a matter of selecting the two key parameters (GPIO connection pins) during init: the CS (chip select) and INT (interrupt) pins specific to each device.

// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);
TehProgrammer commented 6 years ago

Will this allow my to simultaneously read two radios at the same time? I'm building an antenna tracker and it's important I can read the RSSI at about the same time for each radio.

gojimmypi commented 6 years ago

well, "nearly simultaneously": As they would both be interrupt driven, it would appear they are reading concurrently. In reality, on a single core processor, only one interrupt would be processed at a time, Given the relatively low rates of data transfer vs processing speed - you'd likely never notice. If you are using something like FreeRTOS, it would appear even more like simultaneous events. (I've not actually used the RadioHead drivers with an RTOS yet)

ludoplt commented 5 years ago

Hello,

I want to use this library for a LORA project but we are using SAM D21E instead of SAM D21G. SAN D21E only as 32 pins and don't have the pins for Arduino default hardware SPI.

Is it possible to use this library but with another SPI interface ?

Best regards, Ludovic

ludoplt commented 5 years ago

We can change the ports using RHSoftwareSPI like this :

#include <RHSoftwareSPI.h>
RHSoftwareSPI spi;
RH_RF69 rf69(RFM69_CS, RFM69_INT, spi);
void setup()
{
spi.setPins(12, 11, 13); // MISO 12, MOSI 11, SCK  13
}

RadioHead says this software SPI interface will be much slower than hardware SPI on most platforms... Perhaps not in SAM D21 ? Is there another way to achieve changing SPI port ?

orhanyor commented 5 years ago

@ludoplt have you managed to find a way to use another SPI port for this library? im thinking may be a sercom SPI can be used if theres a constructor for it.

john-- commented 4 years ago

I'm also curious about setting up an additional SPI SERCOM for my SAMD21. Would be great if this was supported. I tried hacking something together with no luck.

Software SPI does seem to work fine, though.

john-- commented 4 years ago

Also, btw, it seems some boards support SPI1 like the teensy. You'd initial it like

#include <RHHardwareSPI1.h>
RH_NRF24 nrf24(9, 8, hardware_spi1);

Having it more generic to support custom SERCOMs would be great though.

wyattearp commented 1 year ago

I'm also curious about setting up an additional SPI SERCOM for my SAMD21. Would be great if this was supported. I tried hacking something together with no luck.

Software SPI does seem to work fine, though.

For anyone else looking for a similar problem with the SAMD21 (Feather M0 platforms), I found this comment after about 5 days of searching it's the only way I've been able to get SPI to function with this library on the platform; normally, it would just "hang" or hard fault the system when attempting to either do a setNetworkAddress() or a waitPacketSent(). Hope that helps future people looking for the same issue.