上面的DIO maping 看懂就比较好理解了,DIO0,DIO1,DIO3,
发送和接收都可以触发中断,cad模式需要使用CADDetected和CADDone。
CADDetected这个中断就是有数据接收了,触发进入接收模式,前导码个数的计算还是比较简单的。
从上图可以看出,若要可靠唤醒
WOR
,发送包的前导码必须大于
T1+2*T2 才能可靠唤醒。
TS=2^SF/BW 这个值是一个字节传输所用的时间,发送前导码的个数对应的的时间要不小于T1+2*T2才能唤醒。
举个例子:SF=9,BW=125K,传输一个码元的时间就是TS=2^SF/BW=2^9/125K=4.1ms/symb,
睡眠时间加上CAD时间除以单个码元的时间就是合理的前导码长度,这个长度在一个周期内足以唤醒模块。就是发包的时间有点久。
?? ??? ?lora_write(0x20,0x03)--前导码长度 ?? ??? ?lora_write(0x21,0xec)--前导码长度
目前使用2017年在stm32平台开发的lora dtu,现在移植到lua 的平台。
想要实现实时通信,可以借助运营商基站工作原理(通信原理),蜂窝通信,一回事,使用一组公共信道(收发上行和下行,注册使用),然后从机使用公共信道注册,rssi符合要求,分配一组上行和下行信道给其使用。
local lora = {}
local sys = require "sys"
local spiId = 2
local _nss=13
local _dio0=8
local _dio1=4
local _dio3=5
local MC1={
BW125=0x70,
BW250=0x80,
BW500=0x90,
BW150=0x00
}
local MC2={
FSK=0x00,
SF6=0x60,
SF7=0x70,
SF8=0x80,
SF9=0x90,
SF10=0xA0,
SF11=0xB0,
SF12=0xC0
}
-- MC1["4/5"]=0x02
-- MC1["4/6"]=0x04
-- MC1["4/7"]=0x06
-- MC1["4/8"]=0x08
local _freq=470000000
local _bw=MC1.BW125
local _sf=MC2.SF9
local cspin = gpio.setup(_nss, 1)
local rst = gpio.setup(9, 1)
--收发数据
local function sendRecv(data,len)
local r = ""
cspin(0)
if data then spi.send(spiId,data) end
if len then r = spi.recv(spiId,len) end
cspin(1)
return r
end
local function lora_read(addr)
return string.byte(sendRecv(string.char(addr),1))
end
local function lora_write(addr,value)
cspin(0)
spi.send(spiId,string.char(addr+0x80,value))
cspin(1)
end
local function setFreq(freqHz)
-- local FRF_MSB=0x06
-- local FRF_MID=0x07
-- local FRF_LSB=0x08
local frfMsb,frfMid,frfLsb=0x75,0x80,0x00
local frf=(freqHz/1000*2^11)/125
frfMsb = (frf>>16)%256
frfMid = (frf>>8)%256
frfLsb = (frf>>0)%256
lora_write(0x06,frfMsb)
lora_write(0x07,frfMid)
lora_write(0x08,frfLsb)
print(string.format("%0d hz %02X %02X %02X ",freqHz,frfMsb,frfMid,frfLsb))
end
local function setRate(sf,bw,cr,crc,iiq,powe)
-- local SF10=0xA0
-- local SF11=0xB0
-- local SF12=0xC0
-- local PA_CONFIG=0x09
-- local MODEM_CONFIG1=0x1D
-- local MODEM_CONFIG2=0x1E
-- local MODEM_CONFIG3=0x26
-- local SYMB_TIMEOUT_LSB=0x1F
-- local INVERT_IQ=0x33
local mc1=bit.bor(bw,cr)
local mc2=bit.bor(sf,crc)
--local mc3=0x04
local mc3=0x00 -- no AGC
if (sf == 0xB0 or sf == 0xC0) then mc3=0x08 end -- MC2.SF11=0xB0, MC2.SF12=0xC0
local stl=0x08
if (sf == 0xA0 or sf == 0xB0 or sf == 0xC0) then stl=0x05 end
local pac
if powe > 17 then pac = 0x8F -- 17dbm
elseif powe < -3 then pac = 0x20 -- -3dbm
elseif powe <= 12 then pac = 0x20+powe+3 -- -3dbm .. 12dbm
else pac = 0x80+powe-2 -- 13dbm .. 16dbm
end
lora_write(0x09,pac)--发射功率
lora_write(0x1D,mc1)
lora_write(0x1E,mc2)
lora_write(0x26,mc3)
lora_write(0x1F,stl)
lora_write(0x33,iiq)
end
local function setChannel(freq,sf)
-- local HOP_PERIOD=0x24
-- local FIFO_ADDR_PTR=0x0D
-- local FIFO_RX_BASE_AD=0x0F
-- local CR4_5=0x02
-- local CRC_ON=0x04
setFreq(freq)
setRate(sf,_bw,0x02,0x04,0x27,14) -- CR4/5=0x02, CRC_ON=0x04
lora_write(0x24,0x00)
lora_write(0x0D,lora_read(0x0F))
end
--射频接收数据
local function RcvData()
local count = lora_read(0x13)--获取数据长度
lora_write(0x0D,lora_read(0x10))--指针需要手动清零
return sendRecv(string.char(0x00),count)--读数据
end
--DIO0--RxDone------------------------------------------------------
local getCount=0
local function dio0handler()
lora_write(0x12,0xff)--清除全部的中断标志位
if lora_read(0x40) == 0x40 then
print("TxDone")
if station_Module=="main" then --主站
Rx_mode("lora")
end
else
print("RxDone")
local data_buff=RcvData()
local pkt_rssi=lora_read(0x1A)
local rssi=lora_read(0x1B)
pkt_rssi=-137+16/15*pkt_rssi
getCount=getCount+1
local buff=string.format("rssi:%d,pkt_rssi:%f,getCount:%d.",rssi,pkt_rssi,getCount)
print(data_buff,#data_buff,buff)
if station_Module=="main" then --主站
--RFSend(buff,"wor")
else
RFSend(buff,"lora")
end
end
end
--DIO1--CADDetected------------------------------------------------------
local function dio1handler()
Rx_mode("wor")
print("CADDetected")
lora_write(0x12,0xff)--清除全部的中断标志位
sys.timerStart(RF_Sleepmode,4000)
end
--DIO3---CADDone------------------------------------------------------
local function dio3handler()
print("CADDone")
lora_write(0x12,0xff)--清除全部的中断标志位
RF_Sleepmode()
end
--接收模式
function Rx_mode(flag)
--local REG_LR_OPMODE = 0x01
--local REG_LR_PREAMBLEMSB = 0x20
--local REG_LR_PREAMBLELSB = 0x21
--local REG_LR_PAYLOADLENGTH = 0x22
--local RFLR_OPMODE_STANDBY = 0x01
--local REG_LR_DIOMAPPING1 = 0x40
--local RFLR_DIOMAPPING1_DIO0_00= 0x00
--local REG_LR_FIFOADDRPTR = 0x0D
--local RFLR_OPMODE_RECEIVER = 0x05
--local REG_LR_IRQFLAGS = 0x12
--gpio.close(_dio0)
gpio.close(_dio1)
gpio.close(_dio3)
setConfig(cid,"rxd")
lora_write(0x01,0x81) -- set mode LoRa standby
if flag=="wor" then
lora_write(0x20,0x03)--前导码长度
lora_write(0x21,0xec)--前导码长度
elseif flag=="lora" then
lora_write(0x20,0)--前导码长度
lora_write(0x21,10)--前导码长度
end
lora_write(0x40,0x00)-- 把DIO0-RXDONE标志位写入中断映射寄存器
lora_write(0x12,0xff)-- clear interrupt flags
gpio.setup(_dio0,dio0handler,gpio.PULLDOWN,gpio.RISING)
lora_write(0x0D,lora_read(0x0E))
lora_write(0x01, 0x85)--set mode LoRa rxContinuous
end
--发送数据
function RFSend(SendBuf,flag)
--local REG_LR_OPMODE = 0x01
--local REG_LR_PREAMBLEMSB = 0x20
--local REG_LR_PREAMBLELSB = 0x21
--local REG_LR_PAYLOADLENGTH = 0x22
--local REG_LR_FIFOADDRPTR = 0x0D
--local REG_LR_IRQFLAGS = 0x12
--local REG_LR_IRQFLAGSMASK = 0x11
--local REG_LR_DIOMAPPING1 = 0x40
--local RFLR_IRQFLAGS_TXDONE = 0x08
setConfig(cid,"txd")
gpio.close(_dio0)
gpio.close(_dio1)
gpio.close(_dio3)
lora_write(0x01,0x81)
if flag=="wor" then
lora_write(0x20,0x03)--前导码长度
lora_write(0x21,0xec)--前导码长度
elseif flag=="lora" then
lora_write(0x20,0)--前导码长度
lora_write(0x21,10)--前导码长度
end
lora_write(0x40,0x40)--RFLR_DIOMAPPING1_DIO0_01
lora_write(0x12,0xff) --clear interrupt flags
gpio.setup(_dio0,dio0handler,gpio.PULLDOWN,gpio.RISING)
lora_write(0x0D,lora_read(0x0E))
lora_write(0x22,#SendBuf) --发送数据的长度
sendRecv(string.char(0x00+0x80)..SendBuf)
lora_write(0x01,0x83)--send
print("RFSend",SendBuf)
end
function RF_Sleepmode()
lora_write(0x01,0x81)
lora_write(0x12,0xff)
lora_write(0x01,0x80)--sleep
gpio.close(_dio0)
gpio.close(_dio1)
gpio.close(_dio3)
print("RF_Sleepmode")
--esp32.enterLightSleep(esp32.RTC, 4 * 1000 * 1000)
--RF_CAD_Sample()
sys.timerStart(RF_CAD_Sample ,4000)
end
-- 说明: DIO1--CADDetected DIO3---CADDone
-- 说明 : 采样时间约为(2^SF+32)/BW
function RF_CAD_Sample()
--local RFLR_DIOMAPPING1_DIO3_00 = 0x00
--local RFLR_DIOMAPPING1_DIO1_10 = 0x20
gpio.close(_dio0)
gpio.setup(_dio1,dio1handler,gpio.PULLDOWN,gpio.RISING)
gpio.setup(_dio3,dio3handler,gpio.PULLDOWN,gpio.RISING)
setConfig(cid,"rxd")
lora_write(0x01,0x81)
lora_write(0x20,0x1f)--设置前导码长度为最长
lora_write(0x21,0x48)
lora_write(0x40,0x20)--dio3:CadDone.dio1:CadDetected RFLR_DIOMAPPING1_DIO3_00 | RFLR_DIOMAPPING1_DIO1_10
lora_write(0x01,0x87)--cad
lora_write(0x12,0xff)--clear interrupt flags
print("RF_CAD_Sample")
end
station_Module="main1"
cid = 99991234
function setConfig(cid,rxtx)
local RFoffset=(cid % 250)* 200000
local RF=420000000
if rxtx=="rxd" then--接收
if station_Module=="main" then --主站
RF=420000000 + RFoffset
else
RF=470000000 + RFoffset
end
else --发送
if station_Module=="main" then
RF=470000000 + RFoffset
else
RF=420000000 + RFoffset
end
end
setChannel(RF,MC2.SF9)
end
function lora.sxInit()
rst(0)
local result = spi.setup(spiId, _nss,0,0,8,10000)
print("open",result)
if result ~= 0 then--返回值为0,表示打开成功
print("spi open error",result)
end
rst(1)
if lora_read(0x42) == 0x12 and lora_read(0x44)==0x2D then
print("start init")
else
print("Unknown radio")
--return
end
--local REG_LR_MODEMCONFIG3 = 0x26
--local REG_LR_MODEMCONFIG1 = 0x1D
--local REG_LR_MODEMCONFIG2 = 0x1E
--local REG_LR_PREAMBLELSB = 0x21
--local REG_LR_PARAMP = 0x0A
lora_write(0x01,0x00)--设置为SLEEP模式
lora_write(0x01,0x80)--并且设置为LORA模式
lora_write(0x01,0x81)--设置为STANDBY模式
lora_write(0x4D,0x07)--最大发射功率20dmb开启
lora_write(0x0A,0x02)-- 上升,下降的斜率设置为1000US
lora_write(0x0B,bit.bor(0x20,0x1B))--过流保护开启,最大承载电流为240MA
if station_Module == "main" then --主节点
sys.timerLoopStart(RFSend,8000,"HELLO WORLD 0000000000000 12355555555558844442222111","wor")
print("lora init 主节点 ok")
else --低功耗从机
--setChannel(_freq,MC2.SF9)
sys.timerStart(RF_Sleepmode,500)
print("lora init 从机 ok")
end
end
return lora
-- --local RFLR_OPMODE_LONGRANGEMODE_MASK = 0x7F
-- --local RFLR_OPMODE_LONGRANGEMODE_OFF = 0x00 -- Default
-- --local RFLR_OPMODE_LONGRANGEMODE_ON = 0x80
-- --local RFLR_OPMODE_ACCESSSHAREDREG_MASK = 0xBF
-- --local RFLR_OPMODE_ACCESSSHAREDREG_ENABLE = 0x40
-- -- local RFLR_OPMODE_ACCESSSHAREDREG_DISABLE = 0x00 -- Default
-- -- local RFLR_OPMODE_FREQMODE_ACCESS_MASK = 0xF7
-- -- local RFLR_OPMODE_FREQMODE_ACCESS_LF = 0x08 -- Default
-- -- local RFLR_OPMODE_FREQMODE_ACCESS_HF = 0x00
-- -- local RFLR_OPMODE_MASK = 0xF8
-- local RFLR_OPMODE_SLEEP = 0x00
-- local RFLR_OPMODE_STANDBY = 0x01 -- Default
-- -- local RFLR_OPMODE_SYNTHESIZER_TX = 0x02
-- local RFLR_OPMODE_TRANSMITTER = 0x03
-- -- local RFLR_OPMODE_SYNTHESIZER_RX = 0x04
-- local RFLR_OPMODE_RECEIVER = 0x05
-- -- -- LoRa specific modes
-- -- local RFLR_OPMODE_RECEIVER_SINGLE = 0x06
-- local RFLR_OPMODE_CAD = 0x07
-- -- --SX1276 Internal registers Address
-- local REG_LR_FIFO = 0x00
-- -- -- Common settings
-- local REG_LR_OPMODE = 0x01
-- -- local REG_LR_BANDSETTING = 0x04
-- local REG_LR_FRFMSB = 0x06
-- local REG_LR_FRFMID = 0x07
-- local REG_LR_FRFLSB = 0x08
-- -- -- Tx settings
-- local REG_LR_PACONFIG = 0x09
-- local REG_LR_PARAMP = 0x0A
-- local REG_LR_OCP = 0x0B
-- -- -- Additional settings
-- -- local REG_LR_PLLHOP = 0x44
-- -- local REG_LR_TCXO = 0x4B
-- -- local REG_LR_PADAC = 0x4D
-- -- local REG_LR_FORMERTEMP = 0x5B
-- -- local REG_LR_BITRATEFRAC = 0x5D
-- -- local REG_LR_AGCREF = 0x61
-- -- local REG_LR_AGCTHRESH1 = 0x62
-- -- local REG_LR_AGCTHRESH2 = 0x63
-- -- local REG_LR_AGCTHRESH3 = 0x64
-- -- local RFLR_OCP_MASK = 0xDF
-- -- local RFLR_OCP_ON = 0x20 -- Default
-- -- local RFLR_OCP_OFF = 0x00
-- -- local RFLR_OCP_TRIM_MASK = 0xE0
-- -- local RFLR_OCP_TRIM_045_MA = 0x00
-- -- local RFLR_OCP_TRIM_050_MA = 0x01
-- -- local RFLR_OCP_TRIM_055_MA = 0x02
-- -- local RFLR_OCP_TRIM_060_MA = 0x03
-- -- local RFLR_OCP_TRIM_065_MA = 0x04
-- -- local RFLR_OCP_TRIM_070_MA = 0x05
-- -- local RFLR_OCP_TRIM_075_MA = 0x06
-- -- local RFLR_OCP_TRIM_080_MA = 0x07
-- -- local RFLR_OCP_TRIM_085_MA = 0x08
-- -- local RFLR_OCP_TRIM_090_MA = 0x09
-- -- local RFLR_OCP_TRIM_095_MA = 0x0A
-- -- local RFLR_OCP_TRIM_100_MA = 0x0B -- Default
-- -- local RFLR_OCP_TRIM_105_MA = 0x0C
-- -- local RFLR_OCP_TRIM_110_MA = 0x0D
-- -- local RFLR_OCP_TRIM_115_MA = 0x0E
-- -- local RFLR_OCP_TRIM_120_MA = 0x0F
-- -- local RFLR_OCP_TRIM_130_MA = 0x10
-- -- local RFLR_OCP_TRIM_140_MA = 0x11
-- -- local RFLR_OCP_TRIM_150_MA = 0x12
-- -- local RFLR_OCP_TRIM_160_MA = 0x13
-- -- local RFLR_OCP_TRIM_170_MA = 0x14
-- -- local RFLR_OCP_TRIM_180_MA = 0x15
-- -- local RFLR_OCP_TRIM_190_MA = 0x16
-- -- local RFLR_OCP_TRIM_200_MA = 0x17
-- -- local RFLR_OCP_TRIM_210_MA = 0x18
-- -- local RFLR_OCP_TRIM_220_MA = 0x19
-- -- local RFLR_OCP_TRIM_230_MA = 0x1A
-- local RFLR_OCP_TRIM_240_MA = 0x1B
-- -- local RFLR_PARAMP_MASK = 0xF0
-- -- local RFLR_PARAMP_3400_US = 0x00
-- -- local RFLR_PARAMP_2000_US = 0x01
-- local RFLR_PARAMP_1000_US = 0x02
-- -- local RFLR_PARAMP_0500_US = 0x03
-- -- local RFLR_PARAMP_0250_US = 0x04
-- -- local RFLR_PARAMP_0125_US = 0x05
-- -- local RFLR_PARAMP_0100_US = 0x06
-- -- local RFLR_PARAMP_0062_US = 0x07
-- -- local RFLR_PARAMP_0050_US = 0x08
-- -- local RFLR_PARAMP_0040_US = 0x09 -- Default
-- -- local RFLR_PARAMP_0031_US = 0x0A
-- -- local RFLR_PARAMP_0025_US = 0x0B
-- -- local RFLR_PARAMP_0020_US = 0x0C
-- -- local RFLR_PARAMP_0015_US = 0x0D
-- -- local RFLR_PARAMP_0012_US = 0x0E
-- -- local RFLR_PARAMP_0010_US = 0x0F
-- -- local RFLR_MODEMCONFIG2_SF_MASK = 0x0F
-- -- local RFLR_MODEMCONFIG2_SF_6 = 0x60
-- -- local RFLR_MODEMCONFIG2_SF_7 = 0x70 -- Default
-- local RFLR_MODEMCONFIG2_SF_8 = 0x80
-- -- local RFLR_MODEMCONFIG2_SF_9 = 0x90
-- -- local RFLR_MODEMCONFIG2_SF_10 = 0xA0
-- -- local RFLR_MODEMCONFIG2_SF_11 = 0xB0
-- -- local RFLR_MODEMCONFIG2_SF_12 = 0xC0
-- -- local RFLR_MODEMCONFIG2_TXCONTINUOUSMODE_MASK = 0xF7
-- -- local RFLR_MODEMCONFIG2_TXCONTINUOUSMODE_ON = 0x08
-- -- local RFLR_MODEMCONFIG2_TXCONTINUOUSMODE_OFF = 0x00
-- -- local RFLR_MODEMCONFIG2_RXPAYLOADCRC_MASK = 0xFB
-- local RFLR_MODEMCONFIG2_RXPAYLOADCRC_ON = 0x04
-- -- local RFLR_MODEMCONFIG2_RXPAYLOADCRC_OFF = 0x00 -- Default
-- -- local RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB_MASK = 0xFC
-- -- local RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB = 0x00 -- Default
-- -- local RFLR_MODEMCONFIG1_BW_MASK = 0x0F
-- -- local RFLR_MODEMCONFIG1_BW_7_81_KHZ = 0x00
-- -- local RFLR_MODEMCONFIG1_BW_10_41_KHZ = 0x10
-- -- local RFLR_MODEMCONFIG1_BW_15_62_KHZ = 0x20
-- -- local RFLR_MODEMCONFIG1_BW_20_83_KHZ = 0x30
-- -- local RFLR_MODEMCONFIG1_BW_31_25_KHZ = 0x40
-- -- local RFLR_MODEMCONFIG1_BW_41_66_KHZ = 0x50
-- -- local RFLR_MODEMCONFIG1_BW_62_50_KHZ = 0x60
-- -- local RFLR_MODEMCONFIG1_BW_125_KHZ = 0x70 -- Default
-- local RFLR_MODEMCONFIG1_BW_250_KHZ = 0x80
-- -- local RFLR_MODEMCONFIG1_BW_500_KHZ = 0x90
-- -- local RFLR_MODEMCONFIG1_CODINGRATE_MASK = 0xF1
-- -- local RFLR_MODEMCONFIG1_CODINGRATE_4_5 = 0x02
-- -- local RFLR_MODEMCONFIG1_CODINGRATE_4_6 = 0x04 -- Default
-- -- local RFLR_MODEMCONFIG1_CODINGRATE_4_7 = 0x06
-- local RFLR_MODEMCONFIG1_CODINGRATE_4_8 = 0x08
-- -- local RFLR_MODEMCONFIG1_IMPLICITHEADER_MASK = 0xFE
-- -- local RFLR_MODEMCONFIG1_IMPLICITHEADER_ON = 0x01
-- local RFLR_MODEMCONFIG1_IMPLICITHEADER_OFF = 0x00 -- Default
-- -- local RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_MASK = 0xF7
-- local RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_ON = 0x08
-- -- local RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_OFF = 0x00 -- Default
-- -- local RFLR_MODEMCONFIG3_AGCAUTO_MASK = 0xFB
-- local RFLR_MODEMCONFIG3_AGCAUTO_ON = 0x04 -- Default
-- -- local RFLR_MODEMCONFIG3_AGCAUTO_OFF = 0x00
-- -- LoRa registers
-- local REG_LR_FIFOADDRPTR = 0x0D
-- local REG_LR_FIFOTXBASEADDR = 0x0E
-- -- local REG_LR_FIFORXBASEADDR = 0x0F
-- -- local REG_LR_FIFORXCURRENTADDR = 0x10
-- local REG_LR_IRQFLAGSMASK = 0x11
-- local REG_LR_IRQFLAGS = 0x12
-- local REG_LR_NBRXBYTES = 0x13
-- -- local REG_LR_RXHEADERCNTVALUEMSB = 0x14
-- -- local REG_LR_RXHEADERCNTVALUELSB = 0x15
-- -- local REG_LR_RXPACKETCNTVALUEMSB = 0x16
-- -- local REG_LR_RXPACKETCNTVALUELSB = 0x17
-- -- local REG_LR_MODEMSTAT = 0x18
-- -- local REG_LR_PKTSNRVALUE = 0x19
-- -- local REG_LR_PKTRSSIVALUE = 0x1A
-- -- local REG_LR_RSSIVALUE = 0x1B
-- -- local REG_LR_HOPCHANNEL = 0x1C
-- local REG_LR_MODEMCONFIG1 = 0x1D
-- local REG_LR_MODEMCONFIG2 = 0x1E
-- -- local REG_LR_SYMBTIMEOUTLSB = 0x1F
-- local REG_LR_PREAMBLEMSB = 0x20
-- local REG_LR_PREAMBLELSB = 0x21
-- local REG_LR_PAYLOADLENGTH = 0x22
-- -- local REG_LR_PAYLOADMAXLENGTH = 0x23
-- -- local REG_LR_HOPPERIOD = 0x24
-- -- local REG_LR_FIFORXBYTEADDR = 0x25
-- local REG_LR_MODEMCONFIG3 = 0x26
-- -- -- Additional settings
-- -- local REG_LR_PLLHOP = 0x44
-- -- local REG_LR_TCXO = 0x4B
-- local REG_LR_PADAC = 0x4D
-- -- local REG_LR_FORMERTEMP = 0x5B
-- -- local REG_LR_BITRATEFRAC = 0x5D
-- -- local REG_LR_AGCREF = 0x61
-- -- local REG_LR_AGCTHRESH1 = 0x62
-- -- local REG_LR_AGCTHRESH2 = 0x63
-- -- local REG_LR_AGCTHRESH3 = 0x64
-- -- local RFLR_PADAC_20DBM_MASK = 0xF8
-- local RFLR_PADAC_20DBM_ON = 0x07
-- -- local RFLR_PADAC_20DBM_OFF = 0x04 // Default
-- -- local RFLR_PLL_BANDWIDTH_MASK = 0x3F
-- -- local RFLR_PLL_BANDWIDTH_75 = 0x00
-- -- local RFLR_PLL_BANDWIDTH_150 = 0x40
-- -- local RFLR_PLL_BANDWIDTH_225 = 0x80
-- -- local RFLR_PLL_BANDWIDTH_300 = 0xC0 -- Default
-- -- local RFLR_PLLLOWPN_BANDWIDTH_MASK = 0x3F
-- -- local RFLR_PLLLOWPN_BANDWIDTH_75 = 0x00
-- -- local RFLR_PLLLOWPN_BANDWIDTH_150 = 0x40
-- -- local RFLR_PLLLOWPN_BANDWIDTH_225 = 0x80
-- -- local RFLR_PLLLOWPN_BANDWIDTH_300 = 0xC0 -- Default
-- -- local RFLR_IRQFLAGS_RXTIMEOUT = 0x80
-- local RFLR_IRQFLAGS_RXDONE = 0x40
-- -- local RFLR_IRQFLAGS_PAYLOADCRCERROR = 0x20
-- -- local RFLR_IRQFLAGS_VALIDHEADER = 0x10
-- local RFLR_IRQFLAGS_TXDONE = 0x08
-- local RFLR_IRQFLAGS_CADDONE = 0x04
-- -- local RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL = 0x02
-- local RFLR_IRQFLAGS_CADDETECTED = 0x01
-- local REG_LR_DIOMAPPING1 = 0x40
-- -- local REG_LR_DIOMAPPING2 = 0x41
-- -- local RFLR_DIOMAPPING1_DIO0_MASK = 0x3F
-- local RFLR_DIOMAPPING1_DIO0_00 = 0x00 -- Default
-- local RFLR_DIOMAPPING1_DIO0_01 = 0x40
-- local RFLR_DIOMAPPING1_DIO0_10 = 0x80
-- local RFLR_DIOMAPPING1_DIO0_11 = 0xC0
-- -- local RFLR_DIOMAPPING1_DIO1_MASK = 0xCF
-- -- local RFLR_DIOMAPPING1_DIO1_00 = 0x00 -- Default
-- -- local RFLR_DIOMAPPING1_DIO1_01 = 0x10
-- local RFLR_DIOMAPPING1_DIO1_10 = 0x20
-- -- local RFLR_DIOMAPPING1_DIO1_11 = 0x30
-- -- local RFLR_DIOMAPPING1_DIO3_MASK = 0xFC
-- local RFLR_DIOMAPPING1_DIO3_00 = 0x00
-- --local RFLR_DIOMAPPING1_DIO3_01 = 0x01
-- --local RFLR_DIOMAPPING1_DIO3_10 = 0x02
-- --local RFLR_DIOMAPPING1_DIO3_11 = 0x03
以上代码可以直接使用,
下面是接线图
?
|