local SPI_CS = pins.setup(pio.P0_10, 0)--SPI片选
local SPI_SCK = pins.setup(pio.P0_9, 0)--SPI CLK
local SPI_DO = pins.setup(pio.P0_11, 0)--SPI MOSI
local SPI_DI = pins.setup(pio.P0_12)--SPI MISO 输入
--[[/*******************************************************************************
****函数名称:
****函数功能:发送字节
****版本:V1.0
****日期:11-27-2021 ByHS
****入口参数:byte
****说明:
********************************************************************************/]]
function SPI_Send_Byte(byte)
Read = 0
for i = 1, 8 do
if (bit.band(byte, 0x80) == 0x80) then
SPI_DO(1)
else
SPI_DO(0)
end
SPI_SCK(1)
byte = bit.lshift(byte, 1)
Read = bit.lshift(Read, 1)
if (SPI_DI() == 1) then
Read = bit.bor(Read, 0x01)
end
SPI_SCK(0)
end
return Read
end