Loading...
Searching...
No Matches
mfrc522_regs.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 Freie Universität Berlin
3 *
4 * This file is subject to the terms and conditions of the GNU Lesser
5 * General Public License v2.1. See the file LICENSE in the top level
6 * directory for more details.
7 */
8
22#ifndef MFRC522_REGS_H
23#define MFRC522_REGS_H
24
25#include "bitarithm.h"
26
27#ifdef __cplusplus
28extern "C"
29{
30#endif
31
36typedef enum {
37 /* Command and status register definitions (page 36, table 20) */
53 /* Command register definitions (page 36, table 20) */
67 /* Configuration register definitions (page 36-37, table 20) */
82 /* Test register definitions (page 37, table 20) */
140typedef enum {
141 /* Commands used by the PCD to manage communication with several PICCs (ISO 14443-3, Type A, section 6.4) */
150 /* Commands used for MIFARE Classic EV1 (https://www.nxp.com/docs/en/data-sheet/MF1S50YYX_V1.pdf, page 13, table 9) */
162 /* Commands used for MIFARE Ultralight (https://www.nxp.com/docs/en/data-sheet/MF0ICU1.pdf, Section 7.6) */
172#define MFRC522_FIFO_BUF_SIZE 64
173
177# define MFRC522_PICC_CASCADE_TAG 0x88
178
182#define MFRC522_BIT_COMMAND_RCV_OFF BIT5
183
192#define MFRC522_BIT_COMMAND_POWER_DOWN BIT4
193
201#define MFRC522_BITMASK_COMMAND_POWER_DOWN 0x0F
202
203
204
213#define MFRC522_BIT_COML_EN_IRQ_INV BIT7
214
219#define MFRC522_BIT_COML_EN_TX_I_EN BIT6
220
225#define MFRC522_BIT_COML_EN_RX_I_EN BIT5
226
231#define MFRC522_BIT_COML_EN_IDLE_I_EN BIT4
232
237#define MFRC522_BIT_COML_EN_HI_ALERT_I_EN BIT3
238
243#define MFRC522_BIT_COML_EN_LO_ALERT_I_EN BIT2
244
249#define MFRC522_BIT_COML_EN_ERR_I_EN BIT1
250
255#define MFRC522_BIT_COML_EN_TIMER_I_EN BIT0
256
257
258
263#define MFRC522_BIT_DIVL_EN_IRQ_PUSH_PULL BIT7
264
268#define MFRC522_BIT_DIVL_EN_MFIN_ACT_I_EN BIT4
269
274#define MFRC522_BIT_DIVL_EN_CRC_I_EN BIT2
275
276
277
283#define MFRC522_BIT_COM_IRQ_SET_1 BIT7
284
289#define MFRC522_BIT_COM_IRQ_TX_IRQ BIT6
290
296#define MFRC522_BIT_COM_IRQ_RX_IRQ BIT5
297
306#define MFRC522_BIT_COM_IRQ_IDLE_IRQ BIT4
307
313#define MFRC522_BIT_COM_IRQ_HI_ALERT_IRQ BIT3
314
320#define MFRC522_BIT_COM_IRQ_LO_ALERT_IRQ BIT2
321
325#define MFRC522_BIT_COM_IRQ_ERR_IRQ BIT1
326
330#define MFRC522_BIT_COM_IRQ_TIMER_IRQ BIT0
331
332
333
338#define MFRC522_BIT_DIV_IRQ_SET_2 BIT7
339
344#define MFRC522_BIT_DIV_IRQ_MFIN_ACT_IRQ BIT4
345
349#define MFRC522_BIT_DIV_IRQ_CRC_IRQ BIT2
350
351
352
359#define MFRC522_BIT_ERROR_WR_ERR BIT7
360
365#define MFRC522_BIT_ERROR_TEMP_ERR BIT6
366
371#define MFRC522_BIT_ERROR_BUFFER_OVFL BIT4
372
379#define MFRC522_BIT_ERROR_COLL_ERR BIT3
380
386#define MFRC522_BIT_ERROR_CRC_ERR BIT2
387
393#define MFRC522_BIT_ERROR_PARITY_ERR BIT1
394
402#define MFRC522_BIT_ERROR_PROTOCOL_ERR BIT0
403
404
405
413#define MFRC522_BIT_STATUS_1_CRC_OK BIT6
414
419#define MFRC522_BIT_STATUS_1_CRC_READY BIT5
420
426#define MFRC522_BIT_STATUS_1_IRQ BIT4
427
435#define MFRC522_BIT_STATUS_1_T_RUNNING BIT3
436
444#define MFRC522_BIT_STATUS_1_HI_ALERT BIT1
445
453#define MFRC522_BIT_STATUS_1_LO_ALERT BIT0
454
455
456
461#define MFRC522_BIT_STATUS_2_TEMP_SENS_CLEAR BIT7
462
469#define MFRC522_BIT_STATUS_2_I2C_FORCE_HS BIT6
470
478#define MFRC522_BIT_STATUS_2_MF_CRYPTO_1_ON BIT3
479
497#define MFRC522_BITMASK_STATUS_2_MODEM_STATE_2 0x07
498
499
500
508#define MFRC522_BITMASK_FIFO_DATA 0xFF
509
510
511
517#define MFRC522_BIT_FIFO_LEVEL_FLUSH_BUFFER BIT7
518
526#define MFRC522_BITMASK_FIFO_LEVEL_FIFO_LEVEL 0x7F
527
528
529
542#define MFRC522_BITMASK_WATER_LEVEL_WATER_LEVEL 0x3F
543
544
545
550#define MFRC522_BIT_CONTROL_T_STOP_NOW BIT7
551
556#define MFRC522_BIT_CONTROL_T_START_NOW BIT6
557
564#define MFRC522_BITMASK_CONTROL_RX_LAST_BITS 0x07
565
566
567
572#define MFRC522_BIT_BIT_FRAMING_START_SEND BIT7
573
590#define MFRC522_BITMASK_BIT_FRAMING_RX_ALIGN 0x70
591
599#define MFRC522_BIT_BIT_FRAMING_TX_LAST_BITS 0x07
600
601
602
607#define MFRC522_BIT_COLL_VALUES_AFTER_COLL BIT7
608
613#define MFRC522_BIT_COLL_COLL_POS_NOT_VALID BIT5
614
627#define MFRC522_BITMASK_COLL_COLL_POS 0x1F
628
629
630
637#define MFRC522_BIT_MODE_MSB_FIRST BIT7
638
642#define MFRC522_BIT_MODE_TX_WAIT_RF BIT5
643
651#define MFRC522_BIT_MODE_POL_MFIN BIT3
652
666#define MFRC522_BITMASK_MODE_CRC_PRESET 0x03
667
668
669
674#define MFRC522_BIT_TX_MODE_TX_CRC_EN BIT7
675
687#define MFRC522_BITMASK_TX_MODE_TX_SPEED 0x70
688
692#define MFRC522_BIT_TX_MODE_INV_MOD BIT3
693
694
695
700#define MFRC522_BIT_RX_MODE_RX_CRC_EN BIT7
701
713#define MFRC522_BITMASK_RX_MODE_RX_SPEED 0x70
714
719#define MFRC522_BIT_RX_MODE_RX_NO_ERR BIT3
720
736#define MFRC522_BIT_RX_MODE_RX_MULTIPLE BIT2
737
738
739
743#define MFRC522_BIT_TX_CONTROL_INV_TX2_RF_ON BIT7
744
748#define MFRC522_BIT_TX_CONTROL_INV_TX1_RF_ON BIT6
749
753#define MFRC522_BIT_TX_CONTROL_INV_TX2_RF_OFF BIT5
754
758#define MFRC522_BIT_TX_CONTROL_INV_TX1_RF_OFF BIT4
759
765#define MFRC522_BIT_TX_CONTROL_TX2_CW BIT3
766
771#define MFRC522_BIT_TX_CONTROL_TX2_RF_EN BIT1
772
777#define MFRC522_BIT_TX_CONTROL_TX1_RF_EN BIT0
778
779
780
785#define MFRC522_BIT_TX_ASK_FORCE_100_ASK BIT6
786
787
788
802#define MFRC522_BITMASK_TX_SEL_DRIVER_SEL 0x30
803
821#define MFRC522_BITMASK_TX_SEL_MF_OUT_SEL 0x0F
822
823
824
836#define MFRC522_BITMASK_RX_SEL_UART_SEL 0xC0
837
847#define MFRC522_BITMASK_RX_SEL_RX_WAIT 0x3F
848
849
850
858#define MFRC522_BITMASK_RX_THRESHHOLD_MIN_LEVEL 0xF0
859
868#define MFRC522_BITMASK_RX_THRESHHOLD_COLL_LEVEL 0x07
869
870
871
882#define MFRC522_BITMASK_DEMOD_ADD_IQ 0xC0
883
888#define MFRC522_BIT_DEMOD_FIX_IQ BIT5
889
903#define MFRC522_BIT_DEMOD_T_PRESCAL_EVEN BIT4
904
911#define MFRC522_BITMASK_DEMOD_TAU_RCV 0x0C
912
918#define MFRC522_BITMASK_DEMOD_TAU_SYNC 0x03
919
920
921
928#define MFRC522_BITMASK_MF_TX_TX_WAIT 0x03
929
930
931
937#define MFRC522_BIT_MF_RX_PARITY_DISABLE BIT4
938
939
940
947#define MFRC522_BITMASK_SERIAL_SPEED_BR_T0 0xE0
948
955#define MFRC522_BITMASK_SERIAL_SPEED_BR_T1 0x1F
956
957
958
965#define MFRC522_BITMASK_CRC_RESULT_MSB_CRC_RESULT_MSB 0xFF
966
974#define MFRC522_BITMASK_CRC_RESULT_LSB_CRC_RESULT_LSB 0xFF
975
976
977
985#define MFRC522_BITMASK_MOD_WIDTH 0xFF
986
987
988
1005#define MFRC522_BITMASK_RF_CFG_RX_GAIN 0x70
1006
1007
1018#define MFRC522_BITMASK_GS_N_CW_GS_N 0xF0
1019
1029#define MFRC522_BITMASK_GS_N_MOD_GS_N 0x0F
1030
1031
1032
1041#define MFRC522_BITMASK_CW_GS_P_CW_GS_P 0x3F
1042
1043
1044
1054#define MFRC522_BITMASK_MOD_GS_P_MOD_GS_P 0x3F
1055
1056
1057
1068#define MFRC522_BIT_T_MODE_T_AUTO BIT7
1069
1082#define MFRC522_BITMASK_T_MODE_T_GATED 0x60
1083
1090#define MFRC522_BIT_T_MODE_T_AUTO_RESTART BIT4
1091
1108#define MFRC522_BITMASK_T_MODE_T_PRESCALER_HI 0x0F
1109
1125#define MFRC522_BITMASK_T_PRESCALER_T_PRESCALER_LO 0xFF
1126
1127
1128
1136#define MFRC522_BITMASK_T_RELOAD_MSB_T_RELOAD_VAL_HI 0xFF
1137
1145#define MFRC522_BITMASK_T_RELOAD_LSB_T_RELOAD_VAL_LO 0xFF
1146
1147
1148
1154#define MFRC522_BITMASK_T_COUNTER_VAL_MSB_T_COUNTER_VAL_HI 0xFF
1155
1161#define MFRC522_BITMASK_T_COUNTER_VAL_LSB_T_COUNTER_VAL_LO 0xFF
1162
1163#ifdef __cplusplus
1164}
1165#endif
1166
1167#endif /* MFRC522_REGS_H */
Helper functions for bit arithmetic.
mfrc522_pcd_command_t
Command definitions.
@ MFRC522_CMD_MEM
Stores 25 bytes into the internal buffer.
@ MFRC522_CMD_NO_CMD_CHANGE
No command change, can be used to modify the CommandReg register bits without affecting the command,...
@ MFRC522_CMD_MF_AUTHENT
Performs the MIFARE standard authentication as a reader.
@ MFRC522_CMD_TRANSMIT
Transmits data from the FIFO buffer.
@ MFRC522_CMD_CALC_CRC
Activates the CRC coprocessor or performs a self test.
@ MFRC522_CMD_RECEIVE
Activates the receiver circuits.
@ MFRC522_CMD_SOFT_RESET
Resets the MFRC522.
@ MFRC522_CMD_TRANSCEIVE
Transmits data from FIFO buffer to antenna and automatically activates the receiver after transmissio...
@ MFRC522_CMD_GENERATE_RANDOM_ID
Generates a 10-byte random ID number.
@ MFRC522_CMD_IDLE
No action, cancels current command execution.
mfrc522_picc_command_t
PICC command definitions.
@ MFRC522_PICC_CMD_MF_PERS_UID_USAGE
Set anti-collision, selection and authentication behaviour.
@ MFRC522_PICC_CMD_MF_AUTH_KEY_B
Authentication with Key B.
@ MFRC522_PICC_CMD_ISO_14443_SEL_CL1
Anti collision/Select, Cascade Level 1.
@ MFRC522_PICC_CMD_MF_UL_READ
Read one block of 16 bytes.
@ MFRC522_PICC_CMD_MF_UL_WRITE
Transfers 16 bytes, but only writes least significant 4 bytes.
@ MFRC522_PICC_CMD_MF_SET_MOD_TYPE
Set load modulation strength.
@ MFRC522_PICC_CMD_ISO_14443_HLTA
HLTA command, Type A.
@ MFRC522_PICC_CMD_ISO_14443_WUPA
Wake-UP command, Type A.
@ MFRC522_PICC_CMD_ISO_14443_REQA
REQuest command, Type A.
@ MFRC522_PICC_CMD_MF_TRANSFER
Write the value from the Transfer Buffer into destination block.
@ MFRC522_PICC_CMD_MF_WRITE
Write one block of 16 bytes.
@ MFRC522_PICC_CMD_ISO_14443_SEL_CL3
Anti collision/Select, Cascade Level 3.
@ MFRC522_PICC_CMD_MF_READ
Read one block of 16 bytes.
@ MFRC522_PICC_CMD_ISO_14443_RATS
Request command for Answer To Reset.
@ MFRC522_PICC_CMD_ISO_14443_SEL_CL2
Anti collision/Select, Cascade Level 2.
@ MFRC522_PICC_CMD_MF_INCREMENT
Increment: Adds the operand to the value of the addressed block, and stores the result in the Transfe...
@ MFRC522_PICC_CMD_MF_UL_COMPAT_WRITE
Write one block of 16 bytes.
@ MFRC522_PICC_CMD_MF_DECREMENT
Decrement: Subtracts the operand from the value of the addressed block, and stores the result in the ...
@ MFRC522_PICC_CMD_MF_AUTH_KEY_A
Authentication with Key A.
@ MFRC522_PICC_CMD_MF_RESTORE
Restore: Copies the value of the addressed block into the Transfer Buffer.
mfrc522_pcd_register_t
Register definitions.
@ MFRC522_REG_RF_CFG
Configures the receiver gain.
@ MFRC522_REG_DIV_IRQ
Interrupt request bits.
@ MFRC522_REG_CRC_RESULT_LSB
Shows the lower 8 bits of the CRC calculation.
@ MFRC522_REG_T_MODE
Defines settings for the internal timer.
@ MFRC522_REG_TEST_PIN_EN
Enables pin output driver on pins D1 to D7.
@ MFRC522_REG_TEST_PIN_VALUE
Defines the values for D1 to D7 when it is used as an I/O bus.
@ MFRC522_REG_DEMOD
Defines demodulator settings.
@ MFRC522_REG_T_RELOAD_MSB
Defines the higher 8 bits of 16-bit timer reload value.
@ MFRC522_REG_TX_ASK
Controls the setting of the transmission modulation.
@ MFRC522_REG_ERROR
Error bits showing the error status of the last command executed.
@ MFRC522_REG_T_COUNTER_VAL_MSB
Shows the higher 8 bits of 16-bit timer value.
@ MFRC522_REG_COMMAND
Starts and stops command execution.
@ MFRC522_REG_ANALOG_TEST
Controls the pins AUX1 and AUX2.
@ MFRC522_REG_COM_IRQ
Interrupt request bits.
@ MFRC522_REG_RX_THRESHHOLD
Selects thresholds for the bit decoder.
@ MFRC522_REG_BIT_FRAMING
Adjustments for bit-oriented frames.
@ MFRC522_REG_TEST_BUS
Shows the status of the internal test bus.
@ MFRC522_REG_TX_SEL
Selects the internal sources for the antenna driver.
@ MFRC522_REG_STATUS_2
Receiver and transmitter status bits.
@ MFRC522_REG_MF_TX
Controls some MIFARE communication transmit parameters.
@ MFRC522_REG_SERIAL_SPEED
Selects the speed of the serial UART interface.
@ MFRC522_REG_T_PRESCALER
Defines settings for the internal timer.
@ MFRC522_REG_CRC_RESULT_MSB
Shows the higher 8 bits of the CRC calculation.
@ MFRC522_REG_TEST_SEL_1
General test signal configuration.
@ MFRC522_REG_RX_MODE
Defines reception data rate and framing.
@ MFRC522_REG_RX_SEL
Selects internal receiver settings.
@ MFRC522_REG_TX_MODE
Defines transmission data rate and framing.
@ MFRC522_REG_GS_N
Selects the conductance of the antenna driver pins TX1 and TX2 for modulation.
@ MFRC522_REG_VERSION
Shows the software version.
@ MFRC522_REG_STATUS_1
Communication status bits.
@ MFRC522_REG_TEST_DAC2
Defines the test value for TestDAC2.
@ MFRC522_REG_T_COUNTER_VAL_LSB
Shows the lower 8 bits of 16-bit timer value.
@ MFRC522_REG_CONTROL
Miscellaneous control registers.
@ MFRC522_REG_TEST_ADC
Shows the value of ADC I and Q channels.
@ MFRC522_REG_CW_GS_P
Defines the conductance of the p-driver output during periods of no modulation.
@ MFRC522_REG_FIFO_DATA
Input and output of 64 byte FIFO buffer.
@ MFRC522_REG_TEST_DAC_1
Defines the test value for TestDAC1.
@ MFRC522_REG_TX_CONTROL
Controls the logical behavior of the antenna driver pins TX1 and TX2.
@ MFRC522_REG_WATER_LEVEL
Level for FIFO underflow and overflow warning.
@ MFRC522_REG_MODE
Defines general modes for transmitting and receiving.
@ MFRC522_REG_AUTO_TEST
Controls the digital self test.
@ MFRC522_REG_T_RELOAD_LSB
Defines the lower 8 bits of 16-bit timer reload value.
@ MFRC522_REG_MOD_WIDTH
Controls the ModWidth setting.
@ MFRC522_REG_COLL
Bit position of the first bit-collision detected on the RF interface.
@ MFRC522_REG_MF_RX
Controls some MIFARE communication receive parameters.
@ MFRC522_REG_MOD_GS_P
Defines the conductance of the p-driver output during periods of modulation.
@ MFRC522_REG_FIFO_LEVEL
Number of bytes stored in the FIFO buffer.
@ MFRC522_REG_DIVL_EN
Enable and disable interrupt request control bits.
@ MFRC522_REG_COML_EN
Enable and disable interrupt request control bits.
@ MFRC522_REG_TEST_SEL_2
General test signal configuration and PRBS control.
mfrc522_pcd_rx_gain_t
Receiver gain definitions.
@ MFRC522_RXGAIN_MIN
18 dB, minimum, convenience for MFRC522_RXGAIN_18_DB
@ MFRC522_RXGAIN_AVG
33 dB, average, convenience for MFRC522_RXGAIN_33_DB
@ MFRC522_RXGAIN_33_DB
33 dB, average, and typical default
@ MFRC522_RXGAIN_48_DB
48 dB, maximum
@ MFRC522_RXGAIN_43_DB
43 dB
@ MFRC522_RXGAIN_38_DB
38 dB
@ MFRC522_RXGAIN_23_DB
23 dB
@ MFRC522_RXGAIN_23_DB_2
23 dB, duplicate for MFRC522_RXGAIN_23_DB
@ MFRC522_RXGAIN_18_DB
18 dB, minimum
@ MFRC522_RXGAIN_MAX
48 dB, maximum, convenience for MFRC522_RXGAIN_48_DB
@ MFRC522_RXGAIN_18_DB_2
18 dB, duplicate for MFRC522_RXGAIN_18_DB