SPI: Procedure for Reading Registers

I’m trying to learn the SPI interaction between a RasPi and a RFM69HCW. Will a read request sent to the slave result in the desired data present during that read request, or do I have to send another transaction to receive the data? I’m wondering this because of the simultaneous write/read transaction that happens with SPI. For the RFM69, the MSB of the address determines the transaction, 1 for write, 0 for read. I’m thinking, when the slave “sees” the 0, it sends the data in that location during that transaction.

this thread may be of some help…welcome to the core forum community…

1 Like

Hi Joe,

We’ve got a pretty good SPI tutorial for Raspberry Pi here:

This video detailing the protocol is also really good:

And I’d recommend checking out the Wikipedia article:

Once you’re through those basics, check out page 44 of the datasheet: https://cdn.sparkfun.com/datasheets/Wireless/General/RFM69HCW-V1.1.pdf

It provides full details of how to read data from it. I’d also recommend checking out Adafruit and Sparkfun’s libraries for their boards based on this chip. See their tutorials here:

1 Like

Thank you so much for helping. I have read or viewed those, and they are required for understanding SPI operation. For me, however, there was still a disconnect between all that and how to communicate with the RFM69 on my desk. There is a lot of information in the RFM69 datasheet, but not much at my level, that helped me understand how, actually, to use it. There are a lot of really complicated software examples from really smart people that make the RFM69 work, but I’ve found nothing at my level to help me understand the basics. So, I’m submitting the code below that might help newbies like me.

My current status is, with the RFM69, I cannot seem to get anything out of the antenna. I have a spectrum analyzer, an SDR, that seems to be working because I can see other signals near 915MHz, but I don’t see my transmitter. So, I’m wondering if there are other register settings that I’m missing.

How the RFM69HCW responds to read and write operations.

print("\n…During either a read or write operation, the RFM69HCW")
print("…returns the data in that location at that time")
print("…A write operation then changes the data\n")
import spidev
import time
SPI_SS = 0
SPI_CLOCK = 2000000 #Mhz
spi = spidev.SpiDev(SPI_BUS, SPI_SS)
spi.max_speed_hz = SPI_CLOCK

Set the address to be read and written

read = 0x18 # desired location to read
write = 0x98 # same location, write bit set
data = 0x88 # data to write to the desired location

Read a single location

rx = spi.xfer([read,0x00]) # read the desired location
print(" Read Address is:",hex(read),"-",“Data is:”,hex(rx[1]),"(single read operation returns requested data)")

Write to that location

rx = spi.xfer([write,data]) # write to that location
print(“Write Address is:”,hex(write),"-",“Data is:”,hex(rx[1]),"(data returned is the existing data prior to write)")

Read that location again

rx = spi.xfer([read,0x00]) # read that location again
print(" Read Address is:",hex(read),"-",“Data is:”,hex(rx[1]),"(data returned was written previously)")



Awesome, thanks for the write-up Joe!

When I get a moment I’ll grab one from stock and have a go.

I’m really not understanding why I cannot transmit through the antenna (RFM69HCW). I don’t think it’s an SPI problem anymore because I can read and write the registers. Of the 80 or so registers, I think I’m not setting one or more correctly. Neither Sectech nor HopeRF are answering my requests for help. I get silence from other forums as well. The following code does not seem to work.

import spidev
import time
spi = spidev.SpiDev(0,0)
spi.max_speed_hz = 1000000
rx = spi.xfer([0x81,0x0c]) #TX mode
while True:
    rx = spi.xfer([0x80,0x55])

Hi Joe,

How interesting, this may be an issue with the component itself, as the setup all seems to be accurate. If it was ordered from Core Electronics please reply to your order confirmation email and we’ll get it sorted out for you ASAP. If it’s just the transceiver breakout that’s playing up we can get a new one out once we confirm the faults. Also, when you say that the code doesn’t seem to work, are you getting any kind of error messages/crashes? Or is it just that the board isn’t transmitting.