Learn how to interface the EM18 RFID module with STM32 microcontrollers in this comprehensive article. Find step-by-step instructions and sample firmware code to get you started on developing RFID-based applications with STM32.

Disclaimer:

Electricity poses inherent risks. Adequate skills are crucial for handling it safely. Undertake tasks at your own risk; the author disclaims responsibility for misuse, harm, or errors. Website content is unique and copyrighted; refrain from unauthorized copying. Most articles are open-source for your benefit. Feel free to use the knowledge freely, and consider purchasing available resources. For assistance or guidance, comment below; the author aims to help. Some articles may contain affiliate links, having no impact on you but supporting the author with a commission. Thank you for your understanding.

Advertisements

Table of Contents

Introduction to EM18 RFID with STM32:

RFID (Radio Frequency Identification) is a popular technology used for the automatic identification of objects. It is widely used in applications such as access control, inventory management, and payment systems. In this article, we will explore how to interface EM18 RFID with STM32 microcontrollers.

EM18 RFID Reader:

EM18 is a low-cost RFID reader module that operates at 125KHz frequency. It is easy to interface with microcontrollers and can read RFID tags from a distance of up to 10cm. The EM18 module has two output pins, Data0 and Data1, which are used to send the tag ID to the microcontroller.

Interfacing EM18 RFID module with STM32

Interfacing EM18 RFID with STM32:

To interface EM18 RFID with STM32, we need to connect the Data0 and Data1 pins of the EM18 module to two GPIO pins of the STM32 microcontroller. We also need to connect the VCC and GND pins of the EM18 module to the corresponding pins of the STM32 microcontroller.

Interfacing EM18 RFID module with STM32

Here is the pin configuration:

  • EM18 VCC – STM32 VDD
  • EM18 GND – STM32 GND
  • EM18 Data0 – STM32 GPIOx Pin 0
  • EM18 Data1 – STM32 GPIOx Pin 1

We can use any GPIO pins of the STM32 microcontroller, but we need to configure them as input pins in the firmware. We will use the Keil ┬ÁVision IDE for firmware development.

Firmware Development:

  1. Create a new project in Keil ┬ÁVision for STM32 microcontroller.
  2. In the project settings, select the correct microcontroller and clock frequency.
  3. Configure the GPIO pins for the EM18 module as input pins.
  4. Implement the firmware code to read the tag ID from the EM18 module.

Here is the sample firmware code:

#include "stm32f4xx.h"

int main(void)
{
    // Configure GPIO pins
    GPIO_InitTypeDef GPIO_InitStruct;
    GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1;
    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(GPIOx, &GPIO_InitStruct);

    // Read tag ID
    uint8_t tag_id[10];
    while(1)
    {
        if(HAL_GPIO_ReadPin(GPIOx, GPIO_PIN_0) == GPIO_PIN_RESET)
        {
            // Data0 is low, start reading tag ID
            for(int i=0; i<10; i++)
            {
                tag_id[i] = 0;
                for(int j=0; j<8; j++)
                {
                    if(HAL_GPIO_ReadPin(GPIOx, GPIO_PIN_1) == GPIO_PIN_SET)
                    {
                        // Bit is 1
                        tag_id[i] |= (1 << j);
                    }
                    else
                    {
                        // Bit is 0
                    }
                }
            }
        }
    }
}

This code reads the tag ID from the EM18 module when the Data0 pin is low. It reads 10 bytes (80 bits) of data from the Data1 pin and stores it in the tag_id array.

Conclusion:

In this article, we have learned how to interface EM18 RFID with STM32 microcontrollers. We have also implemented a sample firmware code to read the tag ID from the EM18 module. This can be used as a starting point for developing RFID-based applications with STM32 microcontrollers.

You can read more on:

For Professional Designs or Help:

Loading

MKDas

Mithun K. Das; B. Sc. in EEE from KUET; Head of R&D @ M's Lab Engineering Solution. "This is my personal blog. I post articles on different subjects related to electronics in the easiest way so that everything becomes easy for all, especially for beginners. If you have any questions, feel free to ask through the contact us page." Thanks.

2 Comments

J Venkata Ramana · 11/04/2023 at 1:55 pm

You are a great person with lot knowledge and interest in electronics. In fact used your clock project which is excellent. I also attached a GPS for auto correction of time. We acknowledge your dedication to the subject of electronics. I also like the way you present your projects for the people. They are clear and everyone can easily understand. Great Bro God bless you.
With love
J. Venkata Ramana

    MKDas · 11/04/2023 at 8:36 pm

    Thank you for your good comment

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *