Search code examples
carduinorfidmifarenxp-microcontroller

Initialing MFRC522 RFID chip in UART interface


I'm using this arduino library to initial & communicate with my MFRC522 chip,library initially used SPI interface for communicating between MCU & RC522.When I'm using it in the SPI interface every thing is OK & correctly operate. Now I'm trying to change interface to the UART mode. Based on the MFRC522 datasheet from NXP,I setted pin status for UART mode. Also reading & writing sequences & UART framing address are based on datasheet. Also when I read VersionReg register of RC522 it successfully returned me 0x92 which mean it is V 2.0 but it can't detect presence of RFID tags. Is there any other differences between SPI & UART interface or any extra setting I must do? Has any one experiences with using this chip in UART mode?

My changes in register read & write functions:

unsigned char ReadRawRC(unsigned char Address)
{
     unsigned char ucAddr;
     unsigned char ucResult=0;

     ucAddr = Address | 0x80;

     UART_SendBlocking(USART0, &ucAddr, 1);
     UART_ReadBlocking(USART0, &ucResult, 1);

     return ucResult;
}

/////////////////////////////////////////////////////////////////////
//@ Function: write RC522 register
//@ Parameter Description: Address [IN]: register address
//Value [IN]: write value
/////////////////////////////////////////////////////////////////////
void WriteRawRC(unsigned char Address, unsigned char value)
{
        unsigned char ucAddr;
        unsigned char ucValu;

        ucAddr = Address & 0x7F;
        ucValu = value;
        UART_SendBlocking(USART0, &ucAddr, 1);
        UART_SendBlocking(USART0, &ucValu, 1);

}

Solution

  • The problem was about differences in address byte in UART mode and SPI mode, as you can see in this picture new modified read /write functions act very well:

    unsigned char ucAddr;
    unsigned char ucValu;
    uint8_t IncomingData;
    
        /////////////////////////////////////////////////////////////////////
        //@ Function: Reading RC522 register
        //@ Parameter Description: Address [IN]: register address
        //@ Return: The value read
        /////////////////////////////////////////////////////////////////////
        unsigned char ReadRawRC(unsigned char Address)
        {
    
             ucAddr = Address | 0x80;
    
                 dataSign=false;
             Chip_UART_SendBlocking(LPC_USART0, &ucAddr, 1);
                 StopWatch_DelayMs(3);
    
                 if(dataSign==true)
                 return IncomingData;
    
                 return 0;
        }
    
        /////////////////////////////////////////////////////////////////////
        //@ Function: write RC522 register
        //@ Parameter Description: Address [IN]: register address
        //Value [IN]: write value
        /////////////////////////////////////////////////////////////////////
        void WriteRawRC(unsigned char Address, unsigned char value)
        {
                ucAddr = Address & 0x7F;
                ucValu = value;
            Chip_UART_SendBlocking(LPC_USART0, &ucAddr, 1);
            Chip_UART_SendBlocking(LPC_USART0, &value, 1);
        }