Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
17 views1 page

LOra Reciever

The document contains a Python script that sets up SPI communication using the spidev library. It configures a device for continuous receiving mode and listens for incoming messages, printing them when received. The script includes functions to write and read registers, and it handles interrupt flags to determine when a message has been received.

Uploaded by

simonhaidenpd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

LOra Reciever

The document contains a Python script that sets up SPI communication using the spidev library. It configures a device for continuous receiving mode and listens for incoming messages, printing them when received. The script includes functions to write and read registers, and it handles interrupt flags to determine when a message has been received.

Uploaded by

simonhaidenpd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import spidev

import time

# SPI setup
spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 500000

def write_reg(addr, val):


spi.xfer2([addr | 0x80, val])

def read_reg(addr):
return spi.xfer2([addr & 0x7F, 0x00])[1]

# Set FIFO base address for RX


write_reg(0x0F, 0x00) # RegFifoRxBaseAddr
write_reg(0x0D, 0x00) # RegFifoAddrPtr

# Set to continuous RX mode


write_reg(0x01, 0x85)
print("Listening...")

while True:
irq_flags = read_reg(0x12)
if irq_flags & 0x40: # RxDone
print("Received!")
write_reg(0x12, 0xFF) # Clear IRQs

# Read received length


length = read_reg(0x13) # RegRxNbBytes
write_reg(0x0D, read_reg(0x10)) # Set FIFO pointer to current RX

msg = ""
for i in range(length):
msg += chr(read_reg(0x00))

print("Message:", msg)
break

time.sleep(0.1)

spi.close()

You might also like