我已经在网上搜索了几天,网络和手册都没有帮助我。
事实上,我想在AT86RF231
的Python中使用简单的发送和接收例程。两个无线电都插在树莓派上。
我认为所有寄存器都设置正确,但在尝试发送数据包时,接收器端没有收到任何信息,并且IRQ TRX_END
也没有被提升。
实施的" test mode
"对我来说也不起作用,我无法弄清楚原因。
数据表可用here。
# -*- coding: utf-8 -*-
import spidev
import time
import RPi.GPIO as GPIO
import binascii
import string
import random
#Definitions
dont_care = 0
nRST = 27
#Abkürzung
spi=spidev.SpiDev()
#make sure /RST is high
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
#GPIO 27 als Output konfigurieren
GPIO.setup(nRST, GPIO.OUT)
GPIO.output(nRST,GPIO.HIGH)
#Reset
def reset():
GPIO.output(nRST,GPIO.LOW)
time.sleep(0.001)
GPIO.output(nRST,GPIO.HIGH)
while (read(0x01,0)[1]!= 0 | read(0x01,0)[1]!= 8):
time.sleep(0.001)
print "Reset complete"
# get Device ID
def DevID():
ID = spi.xfer2([0x9C,0])
print "ID:"
print ID
#write data
def write(addr, value):
spi.xfer2([addr | 0xC0, value])
#read data
def read(addr, value):
data = spi.xfer2([addr | 0x80, value])
return data
#read framebuffer
def frameread():
output = spi.xfer2([0x20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
return output
#read transmissionstatus
def transstatus():
status = read(0x01,0)[1]
print status
if (status == 0):
print "P_ON"
elif (status == 1):
print "Busy_RX"
elif (status== 2):
print "Busy_TX"
elif (status == 6):
print "RX_ON"
elif (status==8):
print "TRX_Off"
else :
print "Kontrolle des Status nötwendig"
#?
def status():
status = spi.xfer2([0x81, 0])
if (status[1]==0):
print "Status: default"
elif (status[1]==1):
print "Status: monitor TRX_Status"
elif (status[1]==2):
print "Status: monitor PHY_RSSI"
elif (status[1]==3):
print "Status: monitor IRQ_Statis"
return status[1]
#Continuous Transmission Test Mode
#Register werden in der Anleitung beschrieben
def testmode():
reset()
DevID()
write(0x0E, 0x01)
write(0x04, 0x00)
write(0x02, 0x03)
write(0x03, 0x01)
write(0x08, 0x33)
write(0x05, 0x00)
status()
while(read(0x01, 0x00) == 8):
time.sleep(0.1)
print "Transmission in progress - waiting"
write(0x036, 0x0F)
# hier muss der Inhalt beschrieben werden
#0x60 Frame write Acess,10 Frames, Inhalt
spi.xfer2([0x60,0x0A,1,2,6,4,5,6,7,8,9,10])
write(0x1C, 0x54)
write(0x1C, 0x46)
write(0x02, 0x09)
print read(0x0F, 0x01)
while(read(0x0F, 0x01)[1]!=0):
time.sleep(0.1)
print "Waiting for PLL_Lock"
write(0x02, 0x02)
#Messung
transstatus()
print "Messung durchführen"
time.sleep(10)
write(0x1C, 0x00)
#Reset machen
reset()
#enable receiver
def receiver_enable():
write(0x02,0x08)
write(0x02,0x06)
# make randomisierte Pakete
def id_generator(size,chars=string.digits):
return ''.join(random.choice(chars) for _ in range(size))
#generate Frame
def make_frame(length, power, transmission_type):
data = id_generator(length)
dataframe = []
dataframe.append(length + 2)
dataframe.append(power)
dataframe.append(transmission_type)
for i in range(0,len(data),1):
dataframe.append(data[i])
return dataframe
# send frame
def send_frame(frame):
write(0x0E, 0x01)
write(0x04, 0x00)
write(0x02, 0x03)
write(0x08, 0x33)
write(0x05, 0x00)
write_frame(frame)
while (read(0x01,0)[1] != 8):
time.sleep(0.1)
print "Waiting for TRX_OFF"
write(0x02, 0x09)
time.sleep(.1)
while(read(0x01,0)[1] != 9):
time.sleep(0.1)
print "Waiting for PLL_Lock"
#TX start
write(0x02, 0x02)
while(read(0x01, 0)[1] == 2):
time.sleep(0.1)
print "Busy TX"
#set transmit power 1-16
def set_power(power):
write(0x05, power)
# Framebuffer write
def write_frame(data):
if isinstance(data, basestring):
spi.xfer2([0x60,len(data)] + [int(ord(i)) for i in list(data)])
else:
print "bin heir"
dataframe = []
dataframe.append(0x60)
dataframe.append(len(data))
for i in range(0,len(data),1):
dataframe.append(int(data[i]))
print dataframe
spi.xfer2(dataframe)
发件人例程
spi.open(0,0)
reset()
while(1):
testmode()
time.sleep(1)
spi.close()
接收程序例程
spi.open(0,0)
reset()
receiver_enable()
while(1):
print frameread()
spi.close()
答案 0 :(得分:0)
我自己找到了解决方案。所选频道实际上是错误的。给出的手册中有0x33但该通道不存在。在发射器和接收器寄存器中更改它,一切都会像魅力一样。