ladecadence / pyRF95

HopeRF RF95 (and similar LoRa modules) python library using spidev
GNU General Public License v2.0
14 stars 10 forks source link

Device not detectd #3

Open ToninoTarsi opened 6 years ago

ToninoTarsi commented 6 years ago

Hi David , Maybe you can help me and address me to a solution. I just got two Dragino Bee board : http://wiki.dragino.com/index.php?title=Lora_BEE and I'm trying to use them with two RaspberriPI Zero. Connection is standard : SpDev0.0 interrupt GPIO25. When I try to use your library the device is not detected :

pi@swpi ~/pyRF95 $ sudo python
Python 2.7.3 (default, Jun 22 2016, 03:14:32)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import rf95
>>> lora = rf95.RF95(0, 25)
>>> print lora.init()
False

So I installed RadioHead library (from https://github.com/hallard/RadioHead) to test also with the original library :

pi@swpi ~/RadioHead/examples/raspi/spi_scan $ sudo ./spi_scan
Checking register(0x42) with CS=GPIO06 => Nothing!
Checking register(0x10) with CS=GPIO06 => Nothing!
Checking register(0x42) with CS=GPIO07 => Nothing!
Checking register(0x10) with CS=GPIO07 => Nothing!
Checking register(0x42) with CS=GPIO08 => SX1276 RF95/96 (V=0x12)
Checking register(0x10) with CS=GPIO08 => Nothing!
Checking register(0x42) with CS=GPIO26 => Nothing!
Checking register(0x10) with CS=GPIO26 => Nothing!

so the SX1276 looks to be correctly detected on CS0 and TX RX works fine.

Any idea where the problem could be ? Thanks Tony

ToninoTarsi commented 6 years ago

The problem looks like to be related in the continuous open and close of spi port for every operation.

If I do not close it on Init() and modify every read/write like for example :

    def spi_read(self, reg):
        #self.spi.open(self.port,self.cs)
        data = self.spi.xfer2([reg & ~SPI_WRITE_MASK, 0])
        #self.spi.close()
        return data[1]

xfer2 works fine.

Now the problem left is related to functions like lora.available() or lora.wait_packet_sent() that never exit. Tony

ladecadence commented 6 years ago

This code was just tested with the RFM95 modules so it's nice to see the code been tested with other chips. I don't know why the SX1276 behaves badly with the opening and closing of the spi port, but well, perhaps I need to get one of those modules to test it and for now I can leave that opening and closing as an option of the library. That functions rely on the interrupts being generated by the LoRa module, how are you connecting the Gpio25 pin to the module? usually you need to connect DIO0, DIO1 and DIO2 pins from the LoRa module to the interrupt pin, and to do so, you'll need to put diodes to form an OR (and prevent current to flow to the other pins), like I did in my board: imagen Tell me if this works.

ToninoTarsi commented 6 years ago

Thanks David , As matter of fact the problem is the interrupt feature. Looking at RadioHead examples with RaspberryPI it uses an interrupt less approach. I just added some code to also have interrupt less in your library

Constructor is now :

__init__(self,port=0,cs=0,int_pin=25,reset_pin=None):

and if int_pin = None register reading is used instead of interrupt as in RadioHead

My branch is on : https://github.com/ladecadence/pyRF95/compare/master...ToninoTarsi:master

But not yet tested. Tony

PS. I only connected DI0 to GPIO25

ToninoTarsi commented 6 years ago

This version (https://github.com/ToninoTarsi/pyRF95) works with my SX1276 in interrupt less mode. It would be interesting to know if it works also on your device Tony

ladecadence commented 6 years ago

Hello!, I'll test the code ASAP and perhaps we can merge both codebases. I don't know why your interrupts aren't working, I've reading the SX1276 datasheet and the interrupts are the same ones than the rf95. They should be all enabled by default, but perhaps you can try to unmask all interrupts using self.spi_write(REG_11_IRQ_FLAGS_MASK, 0) at the init method. The DIO0 pin carries RX and TX interrupts, and DIO1 RX timeout interrupt, they respond to the configuration of the RegDIOMapping1 register, and the configuration is the same in the SX1276 and the rf95, so this should be ok. Do you have any means of looking at the interrupt pin (DIO0) to see if it's triggering (logic analyzer, oscilloscope in trigger mode...) ? Anyway, good work! David.