rc522 - rc522 Non-contact read/write card driver#
Adaptation status unknown
Note
This page document is automatically generated by this file. If there is any error, please submit issue or help modify pr, thank you!
Example
--Note: due to the use of sys.wait() all apis need to be used in the coroutine
-- Usage Examples
local rc522 = require "rc522"
sys.taskInit(function()
spi_rc522 = spi.setup(0,nil,0,0,8,10*1000*1000,spi.MSB,1,0)
rc522.init(0,pin.PB04,pin.PB01)
wdata = {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
while 1 do
rc522.write_datablock(8,wdata)
for i=0,63 do
local a,b = rc522.read_datablock(i)
if a then
print("read",i,b:toHex())
end
end
sys.wait(500)
end
end)
rc522.set_bit_mask(address, value)#
write rc522 register
Parameters
Incoming Value Type |
Explanation |
---|---|
number |
address Address |
number |
value Value |
Return Value
None
Examples
write_rawrc(rc522_bit_framing,0x07)
rc522.read_rawrc(address)#
read rc522 register
Parameters
Incoming Value Type |
Explanation |
---|---|
number |
address Address |
Return Value
return value type |
explanation |
---|---|
number |
Register Value |
Examples
local n = read_rawrc(rc522_com_irq)
rc522.set_bit_mask(address, mask)#
Set the rc522 register
Parameters
Incoming Value Type |
Explanation |
---|---|
number |
address Address |
number |
mask Set value |
Return Value
None
Examples
rc522.set_bit_mask (rc522_fifo_level, 0x80)
rc522.clear_bit_mask(address, mask)#
clear rc522 register
Parameters
Incoming Value Type |
Explanation |
---|---|
number |
address Address |
number |
mask Clear value |
Return Value
None
Examples
rc522.clear_bit_mask(rc522_com_irq, 0x80 )
rc522.command(command,data)#
Command Communication
Parameters
Incoming Value Type |
Explanation |
---|---|
number |
command |
number |
data |
Return Value
return value type |
explanation |
---|---|
status |
data len As a result, the data is returned, and the bit length received |
Examples
rc522.version()
rc522.anticoll(id)#
Anti-collision
Parameters
Incoming Value Type |
Explanation |
---|---|
string |
id Card Serial Number, 4 Bytes |
Return Value
return value type |
explanation |
---|---|
status |
uid Results,uid |
Examples
local status,uid = rc522.anticoll(array_id)
calculate_crc(data)#
crc Calculation
Parameters
Incoming Value Type |
Explanation |
---|---|
table |
data Data |
Return Value
return value type |
explanation |
---|---|
table |
crc Value |
Examples
local crc = calculate_crc(buff)
authstate(mode, addr,key,uid )#
Verify card password
Parameters
Incoming Value Type |
Explanation |
---|---|
number |
mode Mode |
number |
addr Address |
string |
key Password |
string |
uid uid |
Return Value
return value type |
explanation |
---|---|
bool |
Results |
Examples
status = authstate(rc522_authent1b, addr,Key_B,uid )
rc522.write(addr, data)#
Write Data to M1 Card
Parameters
Incoming Value Type |
Explanation |
---|---|
number |
addr Block address (0-63)M1 card has a total of 16 sectors (each sector has: 3 data blocks and 1 control block), a total of 64 blocks |
table |
data Data |
Return Value
return value type |
explanation |
---|---|
bool |
Results |
Examples
rc522.write(addr, data)
rc522.read(addr)#
Write Data to M1 Card
Parameters
Incoming Value Type |
Explanation |
---|---|
number |
addr Block address (0-63)M1 card has a total of 16 sectors (each sector has: 3 data blocks and 1 control block), a total of 64 blocks |
Return Value
return value type |
explanation |
---|---|
bool,string |
Results, data |
Examples
rc522.read(addr, data)
rc522.version()#
rc522 Hardware version
Parameters
None
Return Value
return value type |
explanation |
---|---|
number |
Hardware version |
Examples
rc522.version()
rc522.halt()#
rc522 Command card to go to sleep
Parameters
None
Return Value
return value type |
explanation |
---|---|
bool |
Results |
Examples
rc522.halt()
rc522.reset()#
rc522 Reset
Parameters
None
Return Value
None
Examples
rc522.reset()
rc522.antenna_on()#
Open antenna
Parameters
None
Return Value
None
Examples
rc522.antenna_on()
rc522.antenna_on()#
Switch off antenna
Parameters
None
Return Value
None
Examples
rc522.antenna_on()
rc522_config_isotype()#
Set rc522 to work ISO14443_A
Parameters
None
Return Value
None
Examples
rc522_config_isotype()
rc522.request(req_code)#
rc522 Card Search
Parameters
Incoming Value Type |
Explanation |
---|---|
number |
req_code rc522.reqidl Rc522.reqall all all cards in the antenna search area have not entered the sleep state in the antenna search area. |
Return Value
return value type |
explanation |
---|---|
bool |
tagtype Results, card type |
Examples
status,array_id = rc522.request(rc522.reqall)
rc522.select(id)#
Selected Card
Parameters
Incoming Value Type |
Explanation |
---|---|
number |
id Card Serial Number, 4 Bytes |
Return Value
return value type |
explanation |
---|---|
bool |
Results |
Examples
status = rc522.select(id)
rc522.write_datablock(addr,data)#
Write 16 bytes of data to the block according to the rc522 operation flow
Parameters
Incoming Value Type |
Explanation |
---|---|
number |
addr Any block address. M1 card has a total of 16 sectors (each sector has: 3 data blocks and 1 control block), a total of 64 blocks |
table |
data Point to the data to be written, must be 16 characters |
Return Value
return value type |
explanation |
---|---|
bool |
Results |
Examples
rc522.write_datablock(addr,data)
rc522.read_datablock(addr)#
Read blocks according to rc522 operation flow
Parameters
Incoming Value Type |
Explanation |
---|---|
number |
addr Any block address. M1 card has a total of 16 sectors (each sector has: 3 data blocks and 1 control block), a total of 64 blocks |
Return Value
return value type |
explanation |
---|---|
bool |
string Result data |
Examples
for i=0,63 do
local a,b = rc522.read_datablock(i)
if a then
print("read",i,b:toHex())
end
end
rc522.init(spi_id, cs, rst)#
rc522 Initialization
Parameters
Incoming Value Type |
Explanation |
---|---|
number |
spi_id spi Port number |
number |
cs cs Pin |
number |
rst rst Pin |
Return Value
return value type |
explanation |
---|---|
bool |
Initialization Results |
Examples
spi_rc522 = spi.setup(0,nil,0,0,8,10*1000*1000,spi.MSB,1,1)
rc522.init(0,pin.PB04,pin.PB01)