MFRC522

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MFRC522

1,874 Views
nedarj
Contributor I

hello

I have MFRC522 . I read datasheet and could Communicate with its registers with SPI interface in Atmel Studio but when I enable antenna and approach the tag No register changes, I checked it with Status2Reg register but just show IDLE.

I think that I must set correct frequency but I don't know how.

I put part of my programm .

status = PcdRequest( PICC_REQALL, buffer ) ;
        _delay_ms(100) ;
        str = MFRC522_read( Status2Reg ) ;
        if ( (str & 0x08) == 0x08 )
        {
            Lcd4_Clear() ;
            Lcd4_Write_String( "sMFCR" ) ;
            _delay_ms(100);
        }
        if ( (str & 0x01) == 0x01 )
        {
            Lcd4_Clear() ;
            Lcd4_Write_String( "startsend" ) ;
            _delay_ms(100);
        }
        if ((str & 0x02) == 0x02 )
        {
            Lcd4_Clear() ;
            Lcd4_Write_String( "Txwait") ;
            _delay_ms(100);
        }
        if ((str & 0x03) == 0x03)
        {
            Lcd4_Clear() ;
            Lcd4_Write_String( "Transmitting" ) ;
            _delay_ms(100);
        }
        if ((str & 0x06) == 0x06)
        {
            Lcd4_Clear() ;
            Lcd4_Write_String( "Recieving" ) ;
            _delay_ms(100);
        }
        if ((str & 0x07) == 0x00)
        {
            Lcd4_Clear();
            Lcd4_Write_String( "idle" ) ;
            _delay_ms(100);
        }

I don't know what must I do.

How can I correct it ?

Tags (3)
2 Replies

1,211 Views
nedarj
Contributor I

thank you but I read all of this datasheet but I can't Communicate with card.I changed my program but it didn't work .I attach my program please help me .

   MFRC522_HardReset ;
    _delay_ms(5) ;
    MFRC522_SoftReset();

    _delay_ms(5) ;
    
    // Reset baud rates
    MFRC522_write(TxModeReg, 0x00);
    MFRC522_write(RxModeReg, 0x00);
    // Reset ModWidthReg
    MFRC522_write(ModWidthReg, 0x26);
    
    MFRC522_write( TModeReg, 0x8D ) ;
    MFRC522_write( TPrescalerReg, 0x3E ) ;
    MFRC522_write( TReloadReg_H, 0x00 ) ;
    MFRC522_write( TReloadReg_L, 0x30 ) ;
    MFRC522_write( TxASKReg, 0x40 ) ;
    MFRC522_write( ModeReg, 0x3D ) ;
    
    SetBitMask( TxControlReg, 0x03 ) ;

    ClearBitMask( CollReg, 0x80 ) ;
     MFRC522_write( CommandReg, Idle_CMD) ;
        
     MFRC522_write( ComIrqReg, 0x7F) ;
     MFRC522_write( FIFOLevelReg, 0x80 ) ;
     MFRC522_write( FIFODataReg, PICC_REQALL ) ;

    MFRC522_write( CommandReg, Transceive_CMD) ;
    SetBitMask( BitFramingReg, 0x80 ) ;

     i = 600 ;
        do
        {
            n = MFRC522_read( ComIrqReg ) ;
            i-- ;
        }
        while ( (i!=0) && !(n&0x01) && !(n&0x30) ) ;

        ENABLE_CHIP() ;
        spi_masterInit() ;
        spi_masterTransmit( (( FIFODataReg<<1 ) & 0x7E) | 0x80 ) ;
        spi_slaveInit() ;
        for ( j = 0 ; j < 16 ; j++)
        {
            read[j] = spi_slaveRecieve() ;
        }
        DISABLE_CHIP() ;
        
        
        for ( a = 0 ; a < 4 ; a++)
        {
            USART_Transmit(read[a]) ;
        }

0 Kudos

1,211 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Providing you want to read a Mifare Classic card, there are also other steps to do, for example, anticollision and select the card, and authentication so on, please kindly refer to https://www.nxp.com/docs/en/data-sheet/MF1S50YYX_V1.pdf  for more details.

Hope that helps,


Have a great day,
Kan

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------