So, hello to all viewers and welcome back to Gettobyte Platform. In This blog you are going to know about RFID Reader MFRC522, which is designed by NXP Semiconductors. Objective would be to interface this module with Host MCU’s like of NXP Semiconductors, STMicroelectronics or other vendors MCU’s. Will make the driver to interface the RFID Reader with any MCU, not unlike just with Arduino and Arduino IDE environment. To make the driver of RFID reader at first, we need to dig into its datasheet, to understand its various sub parts. And that’s all about this blog is gotten going to be, to make the datasheet understand in easy way-out.
Table of Contents
Next & Previous Blog
RFID Technology
RFID modules is a wireless sensing technology which is used to track/identify/monitor the objects.
MFRC522 RFID Reader/PCD
MFRC522 is a highly integrated reader/writer IC for contactless communication at 13.56 MHz. These reader supports the ISO 14443 A protocol for communicating with RFID Tags. They are used to detect the MIFRAME RFID tags.
MFRC522 has internal RF transceiver, which provides a robust and efficient implementation for demodulating and decoding signals from MIFRAME compatible cards using ISO 14443 A protocol. The digital module of MFRC522 manages the complete ISO/IEC 14443 A framing and error detection (parity and CRC) functionality.
MFRC522 supports 3 tags of MIFRAME family, that are MF1xxS20, MF1xxS70 and MF1S50 products.
MFRC522 features
MFRC522 though quite old RFID reader and in today’s time many new advance RFID readers have come up. But so as to get started with this technology as a hobbyist/student/DIY project, it is perfect module to lay your hands on this Technology.
- MFRC522 has highly integrated analog circuitry to demodulate and decode responses when RFID tags are brought in close proximity of these devices.
- RFID readers are connected with some host MCU, where the processing of data which is received via RFID tags happens according to the application. MFRC522 can connect with host MCU, using SPI, Serial UART and I2C -bus interface.
- It supports ISO 14443 A protocol and can be used with MIFRAME family of RFID tags. And in MIFRAME family it supports only MF1xxS20, MF1xxS70 and MF1xxS50 products.
- It has internal CRC-coprocessor.
- Internal FIFO buffer which can handle 64 bytes of sending and receiving.
- It uses the Crypto-1 cipher for authenticating.
- It supports Internal oscillator for connection to 27.12 MHz quartz crytsal.
- It is low power device, need 2.5 V to 3.3 V power supply.
- It also has flexible interrupt modes when some RFID tags are detected and trigering events too. In addition to flexible interrupt, it has programmabe I/O pins and timer.
- It can perform Internal self-test too.
MFRC522 Functional description
MFRC522 Host Interfaces
MFRC522 can be connected to Host MCU using 3 serial protocols: UART, I2C or SPI.
MFRC522 checks the current host interface type.
automatically after performing a power-on or hard reset. The MFRC522 IC identifies the host
interface by sensing the logic levels on the below pins after the reset phase. 
The MFRC522 is equipped with a series of registers that allow the Host MCU to access its functional description blocks. To ensure the proper functioning of the MFRC522, the Host MCU must initialize and configure these functional blocks by sending the corresponding register addresses.
Each register is essentially an address byte that is transmitted from the Host MCU. Depending on the function described in the register section, read/write operations are performed on the corresponding address byte.
It is crucial to properly initialize and configure these functional blocks to ensure the optimal performance of the MFRC522. By understanding the purpose of each register and its corresponding function, the Host MCU can effectively communicate with the MFRC522 and achieve the desired results.
–> MFRC522_write_register()
–> MFRC522_Read_register()
MFRC522 Interrupts
MFRC522 can trigger the interrupts, when certain events occur. There are 8 events as shown in below table when interrupt can be triggered.
When above event occurs, IRQ pin is used to interrupt the host. IRQ pin signal is asserted and host MCU can use its interrupt handling capabilities (basically NVIC if we are talking about ARM based MCU) on what to do when corresponding interrupt has occurred.
- Status1Reg Register IRq bit is used to indicate if any interrupt source has been triggerered.
- Which interrupt has been triggered is indicated by ComIrqReg and DivIrqReg Register. 
- Which interrupts to be configured and behavior of IRQ pin is configured by ComIEReg and DivIEReg Register.
MFRC522 Time Unit
There is a Timer unit in MFRC522, that is used for multiple purposes. Timer unit is essential for maintaing the configuring the clock and analog interfaces. Also timer unit can be used for following features:
- Timeout counter
- Watchdog counter
- Stopwatch
- Programmable one shot
- Periodical trigger
Timer has an input clock of 13.56 MHz derived from the 27.12 MHz quartz crystal oscillator. The timer consists of 2 stages: prescaler and counter.
- The prescaler(TPrescaler) is a 12-bit counter. That can be configured using TModeReg register’s TPrescaler_Hi[3:0] and TPrescalerReg register’s TPrescaler[7:0] bits.
- The Reload value for the counter is defined by 16 bits between 0 & 65535 in the TReloadReg register.
- The current value of the timer is indicated in the TCounterVAlReg Register.
MFRC522 FIFO
FIFO overview
The MFRC522 contains an internal FIFO buffer of 64 bytes, which is equivalent to 8 x 64 bits. This buffer is utilized for both input and output data streams. The host MCU has the capability to perform both Read and Write operations on this FIFO. The host MCU sends commands to PCD for communication with PICC. these commands are specified in ISO14443 A standard, which is then inputted into the FIFO. When the PICC responds to these commands, the response is also stored in the FIFO. The host MCU can then read the FIFO to obtain the response from the PICC.
The FIFO buffer is a crucial component in the communication process between the host MCU and the PICC. It allows for efficient data transfer and ensures that all responses are stored in a centralized location. The ability to perform both Read and Write operations on the FIFO provides flexibility and control to the host MCU. By utilizing the FIFO buffer, the communication process is streamlined and optimized for maximum efficiency.
About FIFO registers
FIFO buffer input and output data bus is connected to the FIFODataReg register. Writing to this register stores one byte in the FIFO buffer and increments the internal FIFO buffer write pointer. Reading from this register shows the FIFO buffer contents stored in FIFO read pointer and decrements the FIFO buffer read pointer.
Only one FIFO buffer has been implemented which can be used for input and output. The microcontroller must
ensure that there is not any unintentional FIFO buffer accesses.
The FIFOLevelReg is utilized to determine the number of bytes stored in the FIFO. This register is particularly useful in checking the number of bytes received in the FIFO buffer when the PICC sends a response to the PCD command. By using the FIFOLevelReg, you can easily keep track of the amount of data stored in the FIFO, which is essential in ensuring the smooth operation of your system.
One can also get the status of FIFO buffer using status and error registers.
- FIFO buffer almost full warning can be got to know from Status1Reg register’s HiAlert bit.
- FIFO buffer almost empty warning can be got to know from Status1Reg register’s LoAlert bit.
- FIFO buffer overflow warning, using ErrorReg register’s BufferOvfl bit.
MFRC522 CRC
MFRC522 has a Cyclic Rebudency Check (CRC) coprocessor to check the integrity of the data when data from PICC is received or when data is wriiten to PICC.
- CRC has preset value 0000h, 6363h, A671h or FFFFh. We can configure the preset values using ModeReg CRCPreset[1:0].
- CRC polynomial for the 16-bit CRC is fixed to x^16 + x^12 + x^5 + 1.
- CRCResultReg register indicates the result of the CRC calculation.
- CRC algorithm which is used is according to ISO/IEC 14443 A and ITU-T.
To perform the CRC calculation refer its state machine in below section.
MFRC522 Command Set
MFRC522 operation is determined by certain commands. According to these commands, correspondingly MFRC522 would be performing some action.
So, it’s like at first, we will configure the FIFO, CRC, Interrupts and timer unit. After that Host MCU will instruct the commands to MFRC522 in order to tell what it has to do. Host MCU will write the command code to the CommandReg Register.
Main commands that would be used are Idle, Transceive, CalcCRC and Transmit commands. Transceive command is the one which has to be sent from Host MCU to MFRC522 to send the FIFO buffer data to the antenna, which is further propagated to the RFID readers. And according to the data which we have written in FIFO RFID readers would act and give response.
Each command that needs a data bit stream (or data byte stream) as an input immediately processes any data in the FIFO buffer. An exception to this rule is the
Transceive command. Using this command, transmission is started with the BitFramingReg register’s StartSend bit.
MFRC522 Block Diagram
Above is the simplified block diagram of MFRC522 module. MFRC522 has an internal memory, power supply, interrupt pins, FIFO buffer, Antenna and analog interface, digital module for communicating with Host MCU.
Analog Interface handles the modulation and demodulation of the analog signals. FIFO Buffer ensures fast and convenient data transfer.
Register bank are the set of registers through which MFRC522 would be configured and initialized to use. Parameters like Clock, Interrupts, status of errors while communicating with RFID readers, CRC calculation, FIFO configuration and etc need to be configured before using the MFRC522.
How the MFRC522 Internal system works?
Host MCU will send PCD Commands to MFRC522, according to which it will perform some operations. MCU will send these commands by writing into one of the registers of PCD.( For MFRC522 CommandReg is register)
Operations like:
- Activation of CRC Coprocessor
- Transmission of data from FIFO buffer of MFRC522 and activation of receiver circuits to get the response from PICC
- transfer of data from FIFO to an internal buffer
- soft reset and authentication-based operations
Further MFRC522 will emit the commands for communicating with PICC, here referred to as PICC Commands, according to which operation with PICC takes place, like scanning of PICC, selecting the PICC, reading and writing the data on PICC. MFRC522 emits these commands via electromagnetic induction and electric coupling. ( That is the main working principle behind the RFID technology)
Host MCU to PCD
Host MCU will send the commands to PCD, according to which PCD will perform the operations like activation of FIFO buffer or CRC coprocessor, and transmission of data from FIFO. We will name these commands as MFRC522 Commands sets. Host MCU will send those commands to PCD (here MFRC522) by writing into the CommandReg Register using low level Host Interface write API.
- Idle Command: Places the MFRC522 in Idle mode.
- Mem Command: Transfers the 25 bytes from the FIFO Buffer to the internal buffer. This command is used when, we want to read the data from PICC( As described in ISO-14443-4 doc), as PICC response is always recorded in PCD FIFO.
- Generate RandomID: generates a 10-byte random ID number.
- CalcCRC: Activates the CRC coprocessor or performs a self test.
- Transmit: transmit data from the FIFO buffer
- NoCmdChange: no command change, can be used to modify the CommandRef register bits without affecting the command
- Receive: activates the receiver circuits
- Transceive: Transmit data from the FIFO buffer to antenna and automatically activates the receiver after transmission.
- MFAuthent: performs the MIFARE standard authentication as a reader
- SoftReset: This command performs a reset of the device. The configuration data of the internal buffer remains unchanged. All registers are set to the reset values. This command automatically terminates when finished.
PCD to PICC
Further there are also command set which PCD have to emit to communicate with PICC and enter the PICC into some state machine.
PICC States:
- Power-off State: In the POWER-OFF state, the PICC is not powered by a PCD operating field
- Idle State: In the IDLE state, the PICC is powered. It listens for commands and shall recognize REQA and WUPA commands.
- Ready State: Cascade levels are handled inside this state to get the complete UID. PICC enters the ACTIVE state when it is selected with its complete UID.
- Active State: PICC complies with ISO-14443-4 to accept protocol activation commands (RATS)
- HALT State: In this state PICC only responds to WUPA command.
- Protocol State: PICC behaves according to 1s014443-4 specifications.
We will name these commands as PICC commands. Host MCU will write these PICC command into the PCD FIFO (refer the MFRC522 FIFO section on how to write the data on FIFO). PCD would transmit the FIFO data when it enters the Transceiver state machine (refer above topic).
PCD would transmit these commands via the electromagnetic induction and communicates with PICC via electronic coupling. PCD’s have RF transceivers through which it emits the electromagnetic waves with commands sets encoded in them. PICC have antenna and small circuitry, which gets energized via electromagnetic waves emitted by PCD and then further both PCD and PICC get coupled together to have 2 way wireless communication. How PCD would send commands to PICC and in return how PICC would respond, that is done according to IS014443 protocol. ISO14443 specifies all the frame formats,PICC command and their format , modulation schemes for RFID technology. 
PICC Frame formats:
- Short Frame:
- Standard Frames
PICC Command Set:
- REQA/WUPA Command: This command is send by PCD to scan the valid and IS014443 compatible PICC’s. This command is in short frame format. Host MCU will write this command into the PCD FIFO, from where this command is transmitted and emitted wirelessly. Response to this command is with ATQA. PICC are in Idle state when listening to this command and after successfully transmitting the ATQA response they enter into Ready State. These commands consist of 7 bits, as specified below:
- ANTICOLLISION/SELECT Command: PICC are in ready state when listening to this command and after this command they enter into ACTIVE STATE. This Command is used to get the UID of the scanned PICC and further select the corresponding PICC for Reading and writing data from it. For the MF1S503 PICC’s UID is of 4 bytes, for that only 1 cascade level is needed.
These commands need to be configured and then these bytes are written into The PCD FIFO for transmission and emission of signal to PICC wirelessly. This Command consists of:
- Select code SEL(1byte): Specify the cascade level.
- No of valid bits NVB (1 byte): specify number of bytes that would be transmitted by PCD to PICC (including SEL, NVB and below point)
- 0 to 40 data bits of UID according to value of NVB.
ANTICOLLISION Command consist of:
- Select Code: Cascade level 1= 0x93
- No of valid bits NVB = 0x20
Response to ANTICOLLISION Command is with the UID of the Scanned PICC(0xEA, 0x24, 0x77, 0x15) and its CRC(0xAC).
- SELECT Command consists of:
- Select code: Cascade level 1 = 0x93
- No of valid bits NVB – 0x70
- 0 to 40 data bits of UID that has been received in ANTICOLLISION Command( 0xEA, 0x24, 0x77, 0x15)
- CRCA(1 byte) : CRC of SELECT Command would be calculated by PCD and then it would be sent to PICC. And When PICC receives the SELECT Command it will check this CRCA and then will send the ACK.(0xAC)
Response to SELECT Command is with the Select Acknowledge:
MFRC522 Hardware and Pinout
MFRC522 IC has 32 pins in total and it comes in SOT617-1 package.
Pin description can be found from the datasheet of MFRC522. To use the MFRC522 IC its module is widely available and quite inexpensive. Can be brought from Robu at cost of 150 rupees. With the module an RFID tag and a key fob tag of MIFRAME Classic 1KB comes in.
In MFRC522 module, IC has 8 pins exposed out for connection and connecting to host MCU.
- The module has 4 pins exposed out for connecting it to host MCU using either SPI, I2C or UART. By default, reader can communicate with a microcontroller over a 4-pin SPI with a maximum data rate of 10 Mbps. It also supports I2C and UART protocols. As told in MFRC522 functional description part, MFRC522 checks the host interface type automatically depending on the signals on it’s control pins.
- MFRC522 module has 1 interrupt pin also exposed out, which can be used to trigger interrupts to alert the microcontroller when a RFID tag is in the vicinity.
- And remaining 3 pins are power supply pins and a reset pin. Reset pin is used for power down mode and reset signal. Module requires the power supply of 3.3 V, that is provided via VCC and GND pins.
Other vendor RFID readers
STMicroelectronics
Texas Instruments
Infenion technologies
Sensor & Modules to explore
Technologies to Explore
Other Blog to Explore
Getting Started with S32 Design Studio Part 3
How to build and debug a Project in S32 Design Studio IDE
PWM Driver of Autosar MCAL Layer
PWM Driver of Autosar MCAL layer Explanation, Understanding and tutorial using ElecronicsV3 Development board
TIMER Peripheral in Microcontroller’s
Explore basics of TIMER Peripheral in Microcontroller!!
STM32F103 & ADC: Single Channel Conversion
In the last post, we have gotten to know about the features of ADC Peripheral that we have in STM32 MCU. Now in this blog with the series of bare Metal Programming for Blue Pill, we will understand different register bytes and bits of ADC Peripheral to be used for using it in different features, configurations, and modes as we get to know about in the Previous Post. In this blog, we will be going through how to use ADC Peripheral for converting a Single Channel of ADC (only one ADC pin) and see its bare metal code. Single Channel Conversion Mode: Only one ADC pin is used, this mode is like when we have say connected only one analog sensor to one of the ADC pins of MCU like the Potentiometer is connected at PA0 pin. ADC Registers In depth for: Let\’s get into an in-depth understanding of which registers and their bits are used for configuring the ADC peripheral of Blue Pill in Single Channel Configuration. We will focus on bits and will give an explanation of why those bits are used for the 1. ADC_SR(ADC status Register) –>This register tells the status of ADC channel Conversion, as it name says. STM32F103 ADC Status Register: 11.12.1 Bit 1[EOC ]: This bit is set by hardware when a single channel of any group (Regular or Injected) is converted successfully. So this bit is used for monitoring when the ADC conversion is completed by using it inside the while loop if interrupts are disabled. 0: ADC Channel Conversion is not completed 1: ADC Channel Conversion is completed When hardware set this bit, we can clear this bit from the firmware end by setting the bit to 0 or by reading ADC_DR(ADC Data Register) Bit 4[STRT]: This bit is set by hardware when regular channel conversion has begun. So when we start the Regular Channel Conversion, we will use this bit inside the while loop to check that whether Regular Channel conversion has started or not. 0: No regular Channel Conversion has started 1: Regular Channel Conversion has started When hardware sets this bit, we can clear this bit from the firmware end by setting the bit to 0. Even if we don\’t clear this bit it will cause no effect during ADC Conversion. But its good practise to clear all bits of Status Register before starting the new conversion 2. ADC_DR(ADC Data Register) –> This register stores the converted digital data at a 12-bit resolution of the converted ADC channel. STM32F103 ADC Data Register 11.12.14 Bit 15:0 [DATA 15:0]: The ADC_DR is divided into two 16 bits groups. The first 16 bits from 0-15 contain the Converted value of the configured ADC Regular Channel. As our ADC is of 12-bit resolution, so this is left aligned or right aligned to 4 bits so as to get the 12 ADC converted data . Left Aligned or Right alignment of ADC Data Depends on ALIGN bit of ADC_CR2 So we will have following code and algorithm for ADC_SR & ADC_DR register:while(!(ADC1->SR & ADC_SR_STRT)) while(!(ADC1->SR & ADC_SR_EOC)); // wait till a group channel converstion has completed adc_data = ADC1->DR; //clear the EOC bit by reading DR register ADC1->SR &= ~ADC_SR_STRT; 3. ADC_CR1(ADC Configuration register 1) –> This register is used for the Configuration of ADC peripheral for Analog Watchdog Discontinuous Mode Interrupt Enable/disable Dual Mode configuration Scan Mode As we are not using any of these features, so all the bits for these registers will be set to zero, and to know about these features and their bit functions, u can navigate to corresponding blogs for those. STM32F103 ADC Configuration Register 1. 11.12.2 Bits 19:16 [DUALMODE 3:0]: These bits are used to configure the type of operating mode. In the blue pill, we have two ADC peripherals: ADC1 & ADC2. We can use these 2 ADC peripherals simultaneously by configuring the respective ADC in different modes or in independent modes. We are going to use these ADC in independent mode as will be using only ADC1 peripheral, so DUALMODE[3:0] will be set to 0. Bit 8[SCAN]: This bit is used to enable/disable the SCAN Mode feature in the ADC peripheral of BLUEPILL. Scan Mode is used when we convert more than 1 channel to scan all the configured channels in a Regular Group. As we are using only a single channel, means only one ADC pin is used so SCAN mode is not used and this bit will be set to 0. 0: Scan Mode disabled. 1:Scan Mode Enabled. So we will have following code and algorith for ADC_CR1 register:ADC1->CR1 &= ~(ADC_CR1_SCAN); // SCAN DISABLED, if using scan mode then dma must be enabled ADC1->CR1 &= ~(ADC_CR1_JDISCEN | ADC_CR1_DISCEN); // Discontinous mode disabled for both injected and regular groups ADC1->CR1 &= ~(ADC_CR1_DISCNUM_2 | ADC_CR1_DISCNUM_1 | ADC_CR1_DISCNUM_2 ); // no channels are configured in discontinous way. // if discontinous mode is enabled then number of //conversions to be done by discontinous mode has to be configured // DISNUM bits ADC1->CR1 &= ~(ADC_CR1_DUALMOD_0 | ADC_CR1_DUALMOD_1 | ADC_CR1_DUALMOD_2); // INDEPENDENT MODE SELECTED ADC1->CR1 &= ~(ADC_CR1_AWDEN | ADC_CR1_JAWDEN); // Analog watchdog disabled for both groups: regular and ibnjected 4. ADC_CR2(ADC Configuration Register 2) –> This register is used for the configuration of ADC Peripheral for: ADC Conversion enables/disabled for regular and injected groups and ADC peripheral enable/disable. Trigger source configuration for regular and injected groups. ADC Data Alignment, DMA, Continous, temperature sensor setting. STM32F103 ADC Configuration Register 2 11.12.3 Bit 0 [ADON]: ADC Peripheral On/OFF. This bit will be set to 1 to enable the ADC peripheral. All channel configurations and ADC Peripheral configurations have to be made before setting this bit to 1. 0: Disable ADC Peripheral 1: Enable ADC Peripheral Bit 1 [CONT]: This bit configures between Single Conversion mode and Continous Conversion mode. Continuous Conversion mode is selected when we have more than 1 ADC channel to be converted. As in this blog, we have
Implementation of keypad module(4*3) with stm32f103
In the last blog we discussed what a keypad module is . In this blog we will be discussing how to interface a 4×4 membrane type keypad module with stm32 microcontroller. Although the keypad module can be configured using both polling and interrupt methods , in this blog we will be discussing the interrupt method as it takes less CPU cycles , also since interrupt doesn’t require constant CPU attention. Keypad module along with stm32 microcontroller finds applications in industrial machines as well various projects such as bluetooth door lock , scientific calculator etc. Hardware description The keypad module consists of 3 layers:- The top layer is made of polymer which usually is the printed graphic overlay . It defines the function of each button in the keypad module . It is heat and water resistant and also prevents from electric discharge. The middle layer that usually consists of dome shaped stainless buttons which upon touch makes contact with the bottom layer completing the circuitry. The bottom layer consists of printed circuitry made of conductive material such as silver or copper oxide. When a key is pressed the dome shaped buttons make contact which completes the circuit and this information is conveyed to microcontroller in the form of signal by the external ribbon. The 4×4 keypad module chosen by us consists of numbers from 0 to 9 along with 2 characters ‘*’ and ‘#’ in the first 3 columns while the last column consists of alphabets A, B ,C , D. The internal circuit diagram of the keypad module Internal Circuit Working Circuit Diagram As can be seen one end of each button is connected to a wire that is then connected to the connector pin as row and other end is connected to another wire which is the column wire. Both the row and column wires helps us pinpoint the button that is pressed. The connection are then made to the MCU in which the row part is configured as GPIO output and written high in our case this will be PA15, PB3, PB4 , PB5 pins the column part is then written as GPIO EXTI interrupt which will get triggered in case of a button push , this will be PB6,PB7,PB8,PB9 in our case . As can be seen in the figure since each row from one side is already HIGH once the connection is made by pressing the button this is read by the MCU pins PB6,PB7,PB8,PB9 and the interrupt is raised which is detected in the rising edge. Besides the keypad module connection UART1 is also enable as PA9 as TX and PA10 as RX This will be used to display the button pressed when the interrupt is fired using teraterm or similar software. ALGORITHM Configure pins PA15,PB3,PB4,PB5 as output pins with no pull up and low frequency Configure pins PB6, PB7,PB8, PB9 as interrupt pins with no pull up and interrupt detection on the rising edge Set the NVIC priority as 0 and enable IRQ Incoming interrupts are handled using EXTI callback function Initialize the UART1 function , configure the parameters and select PA9 as tx and PA10 as RX Hal tick function is called to use key debouncing and prevent unwanted input noise from the buttons 2 variables currentMillis and previousMillis are declared which prevents extra activations or slow functions from triggering the interrupts this is done by subtracting the former from latter and the difference should be greater than 10 Each row is written GPIO 1 and checked if the corresponding column is gpio 1 as well. in case both the conditions are satisfied the interrupt is raised and a keypress is detected The keypressed is displayed on Teraterm or similar software using UART1 SOFTWARE CONFIGURATION Open the stm32cube ide and configure the sys mode, select the debug as serial wire and time base source as systick . In the GPIO section select the pins PA15, PB3,PB4, PB5 as output pins set parameters to default which is GPIO pins to no pull and operations at low frequency . Next select the pins PB6,PB7,PB8,PB9 as EXTI interrupt pins also in the NVIC section enable the line EXTI line [9:5] interrupts .Also configure the GPIO EXTI as interrupt rising which would read the occurrence of the interrupt on the rising edge of the wave and operation as low frequency . The NVIC priority is set to 0 (the highest) and the IRQ is enabled. All the button or key presses are handled by HAL_GPIO_EXTI_Callback function in which the keydebouncing is applied and each row is written GPIO HIGH incase a button press the respective column goes high as well raising the interrupt and the corresponding key is displayed using UART .for eg-The button press such as key 9 is detected when both PB3 and PB7 is HIGH as due to the press a connection is made and an interrupt is raised. Also in the connectivity section select the UART1 set the parameters such as mode to asynchronous , baud rate 115200, Word-length as 8 bits , Stop bits as 1 , mode as TX and RX , hardware flow control as none and oversampling rate as 16 . The UART1 has pin PA9 as TX and PA10 as RX . The uart is used to display the key that is pressed on a teraterm or similar software with baud rate set to 115200 SOFTWARE CONFIGURATION CODE #include “main.h” #include #include /* Private includes ———————————————————-*/ char buffer[32]={0}; /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Private typedef ———————————————————–*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ————————————————————*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro ————————————————————-*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ———————————————————*/ UART_HandleTypeDef huart1; /* USER CODE BEGIN PV */ GPIO_InitTypeDef GPIO_InitStructPrivate = {0}; uint32_t previousMillis = 0; uint32_t currentMillis = 0; uint8_t keyPressed = 0;
Author: Kunal Gupta
Author