Skip to content

Commit

Permalink
update: 优化demo/spislave
Browse files Browse the repository at this point in the history
  • Loading branch information
wendal committed Apr 1, 2024
1 parent ed661be commit 026da4c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 8 additions & 2 deletions demo/spislave/master/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ tmpbuff = zbuff.create(4)

function xt804_read(addr, len)
-- 尝试读取
if not len or len < 1 or len > 1500 then
return
end
tmpbuff:seek(0)
PIN_CS(0)
spi.send(SPI_ID, string.char(addr & 0xFF))
local data = spi.recv(SPI_ID, len)
local data = spi.recv(SPI_ID, len, tmpbuff)
-- local data = spi.recv(SPI_ID, len)
PIN_CS(1)
return data
return tmpbuff:query(0, len)
-- return data
end


Expand Down
4 changes: 3 additions & 1 deletion demo/spislave/slave/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ sys.taskInit(function()
wbuff[3] = 0x16
local count = 0
while true do
--wbuff:seek(0)
wbuff[7] = count & 0xFF
wbuff[8] = count >> 8
wbuff[8] = (count >> 8) & 0xFF
if spislave.ready(2) then
spislave.write(2, 0, wbuff, 16 + 4)
else
log.info("spislave", "当前不可写入")
end
--log.info("wbuff数据", wbuff[7], wbuff[8])
sys.wait(1000)
count = count + 1
end
Expand Down

0 comments on commit 026da4c

Please sign in to comment.