我参考Luat_2G_RDA_8955\script\demo\spi 例程,修改如下: ADXL362 读寄存器指令为:0x0b 设备ID寄存器:0x02
localfunctionreadFlashID()
--拉低CS开始传输数据
pio.pin.setval(0,pio.P0_10)
local recvStr = string.toHex(spi.send_recv(spi.SPI_1,string.fromHex("0B02"))) --读取的值应该为00000000EF17
log.info("testADXL362.readADXL362ID",recvStr)
--传输结束拉高CS
pio.pin.setval(1,pio.P0_10)
end
localfunctionloop()
--打开SPI引脚的供电
pmd.ldoset(6,pmd.LDO_VMMC)
--SPI 初始化
local result = spi.setup(spi.SPI_1,0,0,8,4000000,1,1)
log.info("testADXL362.init",result)
--重新配置GPIO10 (CS脚) 配为输出,默认高电平
pio.pin.close(pio.P0_10)
pio.pin.setdir(pio.OUTPUT,pio.P0_10)
pio.pin.setval(1,pio.P0_10)
readFlashID()
spi.close(spi.SPI_1)
end
sys.timerLoopStart(loop,5000)
实际调试信息如下:
[2019-01-03 17:12:07.847]: [I]-[testADXL362.readADXL362ID] FFFF
[2019-01-03 17:12:12.863]: [I]-[testADXL362.init] 1
[2019-01-03 17:12:12.867]: [I]-[testADXL362.readADXL362ID] FFFF
[2019-01-03 17:12:17.878]: [I]-[testADXL362.init] 1
[2019-01-03 17:12:17.880]: [I]-[testADXL362.readADXL362ID] FFFF
[2019-01-03 17:12:22.878]: [I]-[testADXL362.init] 1
[2019-01-03 17:12:22.899]: [I]-[testADXL362.readADXL362ID] FFFF
[2019-01-03 17:12:27.902]: [I]-[testADXL362.init] 1
[2019-01-03 17:12:27.905]: [I]-[testADXL362.readADXL362ID] FFFF
[2019-01-03 17:12:32.917]: [I]-[testADXL362.init] 1
[2019-01-03 17:12:32.922]: [I]-[testADXL362.readADXL362ID] FFFF
[2019-01-03 17:12:37.919]: [I]-[testADXL362.init] 1
[2019-01-03 17:12:37.939]: [I]-[testADXL362.readADXL362ID] FFFF
为何总是FFFF呢?