Docs

Micro-controllers, wireless transmission and database

Head

RFID RC522 with Blue Pill using STM32CubeIDE

Prerequisites

This project assumes you have already installed STM32CubeIDE. You need to have previously done a basic blink sketch with blue-pill using STM32CubeIDE. I have made a complete video from installing STM32CubeIDE to LED blink program. You can watch it by clicking this link. https://www.youtube.com/watch?v=kXg467nVd_A

Wiring Diagram

Diagram

Image

STM32CubeIDE Settings

Click RCC → High Speed Clock (HSE) to Crystal/Ceramic Resonator

Click Clock Configuration tab → HCLK (MHz) to 72

Click Pinout and Configuration tab

Click connectivity → Click SPI1

For Mode select Full Duplex Master

Configuration → Parameter Settings

Change prescalar (for Baud rate) to 8

Set PA4 to GPIO_Output

Set PB0 to GPIO_Output

Set PC13 to GPIO_Output

Libraries

Inside Core/Inc Folder

rc522.h

Inside Core/Src Folder

rc522.c

Additional code on top of STM32CubeIDE generated code

/* USER CODE BEGIN Includes */
#include "rc522.h"
#include "string.h"
/* USER CODE END Includes */
/* USER CODE BEGIN PV */
uint8_t status;
uint8_t str[MAX_LEN]; // Max_LEN = 16
uint8_t sNum[5];
/* USER CODE END PV */
  /* USER CODE BEGIN 2 */
  MFRC522_Init();
  /* USER CODE END 2 */
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  status = MFRC522_Request(PICC_REQIDL, str);
  status = MFRC522_Anticoll(str);
  memcpy(sNum, str, 5);
  HAL_Delay(100);
  // if((str[0]==115) && (str[1]==93) && (str[2]==75) && (str[3]==22) && (str[4]==115) )
  // {
    // HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,0);
    // HAL_Delay(100);
    // }
  // else if((str[0]==199) && (str[1]==102) && (str[2]==209) && (str[3]==215) && (str[4]==167) )
    // {
    // HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,0);
    // HAL_Delay(2000);
  // }
  // else
  // {
    // HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,1);
  // }
  /* USER CODE END WHILE */
  
  /* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */