Interfacing RFID with STM32

84 Views Asked by At

I am trying to interface an YHY502CTG RFID reader module with an STM32H7A3ZITQ using STM32CubeIDE. But I am not able to set the interaction between the host and the module. Could someone please help me with it's hardware connection and the hex commands related to the code?

I was trying to set UART communication between STM32 board and YHY502CTG reader module.

Here is my code:

uint8_t CMD[]={0XAA,0XBB,0X03,0X14,0X13,0X04}; // command for reading module type
uint8_t RxData[30];//will store response

HAL_UART_Transmit(&huart4, CMD, sizeof(CMD), HAL_MAX_DELAY);
HAL_Delay(1000);
HAL_UART_Receive(&huart4, RxData, sizeof(RxData), HAL_Max_Delay);
HAL_Delay(1000);
1

There are 1 best solutions below

2
pmacfarlane On

There is nothing in the datasheet for the YHY502CTG that indicates that you need to wait for 1000ms before it will send a reply. The implication is that it will send a reply immediately.

Therefore, remove the delay between your transmit and receive.

Note that the STM32 does not have some kind of internal buffer that can store received UART characters until you choose to read them. If the RFID module sends a response while you are delaying (as seems likely), the response will just be lost completely.

The datasheet also suggests that command 0x01 should be used to read the module type, whereas you are using command 0x14. So either your array, or the comment on it, or both, are wrong. Command 0x14 is a "Beep" command.

enter image description here