|
|
@@ -17,6 +17,7 @@ require "Drv_spi"
|
|
|
require "sx126x_reg"
|
|
|
|
|
|
SX126xResetGPIO = pins.setup(pio.P0_13,0)
|
|
|
+OperatingMode = sx126x_reg.RadioStandbyModes_t.STDBY_RC
|
|
|
|
|
|
-- 初始化SPI
|
|
|
function SX126xIoInit()
|
|
|
@@ -32,20 +33,21 @@ function SX126xReset()
|
|
|
sys.wait(10)
|
|
|
end
|
|
|
|
|
|
--- 初始化SX126x
|
|
|
-function SX126xInit()
|
|
|
- SX126xIoInit()
|
|
|
- SX126xReset()
|
|
|
-end
|
|
|
-
|
|
|
function SX126xWakeup()
|
|
|
- Drv_spi.drv_spi_read_write_byte("C00000",2)
|
|
|
+ local command = sx126x_reg.RadioCommands.RADIO_GET_STATUS .. "00"
|
|
|
+ local ret = Drv_spi.drv_spi_read_write_byte(command)
|
|
|
+ log.info("SX126xWakeup",ret)
|
|
|
end
|
|
|
|
|
|
-function SX126xWriteCommand(command ,buffer)
|
|
|
+--local numbers = {10, 20, 30, 40} -- Indices: 1→10, 2→20, 3→30, 4→40
|
|
|
+function SX126xWriteCommand(command,buffer)
|
|
|
+ local bufferTotal = ""
|
|
|
+ for i, num in ipairs(buffer) do
|
|
|
+ bufferTotal = bufferTotal .. num
|
|
|
+ end
|
|
|
Drv_spi.drv_spi_read_write_byte(command,0)
|
|
|
sys.wait(20)
|
|
|
- drv_spi_read_write_byte(buffer);
|
|
|
+ drv_spi_read_write_byte(bufferTotal,0);
|
|
|
sys.wait(20)
|
|
|
end
|
|
|
|
|
|
@@ -65,6 +67,32 @@ function SX126xReadRegisters(address,size)
|
|
|
return result
|
|
|
end
|
|
|
|
|
|
+
|
|
|
+function SX126xReadRegisters(address,size)
|
|
|
+ SX126xWriteCommand(sx126x_reg.RadioCommands.RADIO_SET_STANDBY)
|
|
|
+end
|
|
|
+
|
|
|
+function SX126xSetStandby(standbyConfig)
|
|
|
+ SX126xWriteCommand(sx126x_reg.RadioCommands.RADIO_SET_STANDBY,standbyConfig)
|
|
|
+
|
|
|
+ if standbyConfig[0] == sx126x_reg.RadioStandbyModes_t.STDBY_RC then
|
|
|
+ OperatingMode = sx126x_reg.RadioOperatingModes_t.STDBY_RC
|
|
|
+ else
|
|
|
+ OperatingMode = sx126x_reg.RadioOperatingModes_t.STDBY_XOSC
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+-- 初始化SX126x
|
|
|
+function SX126xInit()
|
|
|
+ SX126xIoInit()
|
|
|
+ SX126xReset()
|
|
|
+ SX126xWakeup()
|
|
|
+ local test = {sx126x_reg.RadioStandbyModes_t.STDBY_RC}
|
|
|
+ SX126xSetStandby(test)
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
-- --测试案例1
|
|
|
-- sys.taskInit(function ()
|
|
|
-- sys.wait(3000)
|
|
|
@@ -101,13 +129,31 @@ end
|
|
|
-- end)
|
|
|
|
|
|
-- --测试案例:测试字符拼接
|
|
|
+-- sys.taskInit(function ()
|
|
|
+-- sys.wait(3000)
|
|
|
+-- SX126xInit()
|
|
|
+-- sys.wait(3000)
|
|
|
+-- log.info("计算结果", "测试1")
|
|
|
+-- while true do
|
|
|
+-- log.info("计算结果", SX126xReadRegisters("0740",2))
|
|
|
+-- sys.wait(3*1000)
|
|
|
+-- end
|
|
|
+-- end)
|
|
|
+
|
|
|
+
|
|
|
+--测试案例:测试初始化
|
|
|
+-- sys.taskInit(function ()
|
|
|
+-- sys.wait(3000)
|
|
|
+-- SX126xInit()
|
|
|
+-- sys.wait(3000)
|
|
|
+-- log.info("计算结果", "测试1")
|
|
|
+-- end)
|
|
|
+
|
|
|
+--测试案例:拼接buffer
|
|
|
sys.taskInit(function ()
|
|
|
sys.wait(3000)
|
|
|
- SX126xInit()
|
|
|
+ SX126xWriteCommand(sx126x_reg.RadioCommands.RADIO_READ_REGISTER,numbers)
|
|
|
sys.wait(3000)
|
|
|
log.info("计算结果", "测试1")
|
|
|
- while true do
|
|
|
- log.info("计算结果", SX126xReadRegisters("0740",2))
|
|
|
- sys.wait(3*1000)
|
|
|
- end
|
|
|
-end)
|
|
|
+end)
|
|
|
+
|