0

I am building a single channel LoRa gateway using the RFM95W module. I am using this github repo; single_chan_pkt_fwd, as a guide.

However I am not yet using a PCB, even though it is very difficult, but I wanted the practice. So I removed the male ends off these jumper wires and soldered the copper directly to the module, and connected the female ends to the Pi.

I took extra care not to short the board, and I think I've done it correctly.

To verify that though, I wanted to read the contents of the RegVersion register, which is at address 0x42; see page 85 of the data sheet.

I am using the following python code in terminal (over ssh / not over network with daemon -- not sure if that's causing more problems) for testing:

####################################
# running Linux raspberrypi 4.14.34-v7+
####################################
import pigpio
import time
pi = pigpio.pi()

# this is the reset pin
pi.set_mode(17, pigpio.OUTPUT)
# this is the DIO0 pin
pi.set_mode(27, pigpio.INPUT)

# reset the board
pi.write(17, 1)
time.sleep(.1)
pi.write(17, 0)

# using main SPI with SPI_CE0_N GPIO08 as NSS
# this is different than the Github example
fd = pi.spi_open(0, 500000)
# file descriptor returns fine

# not sure how to data arg should be
# to read register at address 0x42
#http://abyz.me.uk/rpi/pigpio/python.html#spi_xfer
pi.spi_xfer(fd, ???)

I tried to use value b'\x042 for the data arg, but a hex zero was returned for rx_data

Of course I googled and found this question, which is clear, but I didn't quite understand how [1,(8+adc_channel)<<4,0] fits into my example.

I did try to chase down the spiGoS function in the C code in pigpio.c, but I couldn't tell how to go from SPI_FIFO to the address I wanted.

In summary: I am wondering how to pass a register address to spi_xfre to read the value of the register.

1

The pigpio Python module actually talks through the daemon regardless of whether it is been run over a network or locally.

The pigpio Python API.

See Python spi_xfer.

Note the identifier returned by spi_open is a handle not a file descriptor. I mention this as you can't pass the handle to standard Python file access routines and expect that to work.

Also if you are not using the standard slave select (18 is CE0 on the auxiliary SPI channel) you will have to set it to low (0) before the transfer and set it high (1) afterwards.

  • Thanks Joan! But you didn't answer the question! Does that mean b'\\0x42' is the correct value? I will have to check which pin is the standard SS, I thought it was CE0 – Sam Hammamy Jun 24 '18 at 12:10
  • I have no idea, I don't know that device. – joan Jun 24 '18 at 12:30
  • So from you responses, I am assuming that whatever the address of the register is, I can use that as the argument? – Sam Hammamy Jun 24 '18 at 12:49
  • Btw I meant to write GPIO08 not GPIO18, hence the CE0 confusion. – Sam Hammamy Jun 24 '18 at 12:54
0

Section 4.3 of the data sheet, of course titled "SPI Interface" has the information I was missing!

The first byte is the address byte. It is comprises:

A wnr bit,which is 1 for write access and 0 for read access.

Then 7 bits of address, MSB first.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.