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 is always dangerous. Proper skill is required to work with electricity. Do work at your own risk. The author will not be responsible for any misuse or harmful act or any mistake you make. The contents of this website are unique and copyright protected. Kindly don’t do any nonsensical act of copying and claiming it as yours. Most of the articles published here are kept open-source to help you. Take the knowledge for free and use it, but if you are interested you can buy the ready resources offered here. If you need any help or guidance feel free to comment below, the author will try to help you. Also, there can be affiliation links in the article. Which will not affect you anyway, but allows the author with some commission. So please don’t take it otherwise. Thanks.

Table of Contents

Advertisements

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

Also let me know what you want to get as the next article, comment below!


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.

0 Comments

Leave a Reply

Avatar placeholder

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

%d bloggers like this: