rc522_test.lua 871 B

1234567891011121314151617181920212223242526
  1. --[[
  2. 本demo演示的功能为:
  3. 使用Air780EPM开发板通过spi接口驱动RC522传感器读取ic数据卡数据
  4. 通过spi0通道
  5. cs片选脚接gpio8
  6. rst接gpio16
  7. ]]
  8. local rc522 = require "rc522" --引入rc522驱动模块
  9. function rc522_test()
  10. spi_rc522 = spi.setup(0,8,0,0,8,10*1000*1000,spi.MSB,1,0) --初始化spi接口
  11. rc522.init(0,8,16) --初始化rc522相关接口
  12. wdata = {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} --测试写入数据
  13. while 1 do
  14. -- rc522.write_datablock(7,wdata) --测试ic卡写入
  15. for i=0,63 do
  16. local a,b = rc522.read_datablock(i) --测试ic卡读取
  17. if a then
  18. print("read",i,b:toHex()) --打印读取的数据
  19. end
  20. sys.wait(50)
  21. end
  22. sys.wait(500)
  23. end
  24. end
  25. sys.taskInit(rc522_test)