EHUOYAN
YHY522R
RFID module
Page 9 of 36
The original setting for the host and
YHY522R
communicates at
19200bps, N, 8, 1.
In the slave mode, the host first sends the command and the module executes the
operation and replies with a response to the command. The host can analyze the reply
to check if the operation was successful or if any error occurred during the operation.
10.4.1 Host to YHY522R Transfer Protocol
Table 5. UART frame send by host
1
.
1. Header:
This header has 2 bytes that indicates the beginning of a frame. These 2
bytes should be always 0xAA 0xBB.
2. Length:
This byte is used to indicate the length of the payload data. This includes
the Length, Command and the Data bytes.
3. Command:
This byte is used to instruct the module on what operation to perform.
4. Data:
These are parameters for the module to execute the command. For example,
for a Read command, the data will be the block number to be read and the
authenticated key. For a Write command, this will be the block number and
the authenticated key and 16 bytes data to write into the block. For other
command, it maybe empty.
5. CSUM:
This is the checksum byte. This byte is used on the host as well as the
module to check the validity of the packet and to trap any data
corruption. This is calculated by
XOR
all the bytes in the packet except
the Header and the CSUM byte.
CSUM=Length
⊕
Command
⊕
Data[0]
⊕
Data[1]…
⊕
Data[n-1]
Note: If there is one byte “
0xAA
” in the packet data from Length to CSUM
,
please
insert one byte “0x00” after “0xAA”,but the Length need not change.
Code example:
//--------------------------------------------------
if (cSendBuffer[i] == 0xAA)
{
TI = 0;
SBUF = 0;
while
(!TI);
}
//--------------------------------------------------
10.4.2 YHY522R to Host Transfer Protocol
Table 6. UART frame send by YHY522R
1
.
Header
Length
Command
Data
CSUM
2 Byte
1 Byte
1 Byte
N Bytes
1 Byte
Header
Length
Status
Data
CSUM
2 Byte
1 Byte
1 Byte
N Bytes
1 Byte