Thanks for the help. I'm programming in c. If you say that SPI interface is the easiest, I will you trust you on that and implement it.I'll try to help but my own RFID systems are based on HTRC110 devices which are slightly different.
Are you planning to use the SPI interface mode? It is probably the easiest to implement.
What language do you want to program in?
Brian.
Hi Brian,That's a header file, not a library but it may be useful.
I usually bit-bang SPI because the protocols are so simple. All you have to do is loop the code to send SCK and at each transition set the data bit to be sent and capture the data coming back. Basically arrange all the bits you want to send before sending them and shift them out one by one, at the same time shift in the received bits to construct the data read back from the RFID interface.
You can either send bits by repeatedly shifting the data and checking the LSB or by using a mask and logic ANDing the data with the mask to see if the result is zero or not, at each pass of the loop you shift a single '1' to the left in the mask.
Brian.
Could you perhaps tell me where to find those libraries? I can't find them anywhereYou must not necessarily use bit-bang SPI. Presuming you have a recent C compiler, e.g. XC8, it comes with complete IO libraries including SPI.
Thanks for the tip. Still new at this though. I don't fully understand how to implement that in the code. Looked online, but found nothing. Could you perhaps give me a link, or an example of code where it's explained step by step.The 16F628A is quite an old device and only has 2K of program memory and 224 bytes of RAM, it can't run code for 18F devices because the memory banking is different and some instructions are not implemented. General purpose libraries tend to include routines that are 'generic' rather than concentrating only your specific requirements so unless your compiler is clever enough to pick out only the bits it needs you tend to waste a lot of code space. Note that the 16F628A does not have an internal SPI interface module so you HAVE to implement it in software anyway.
Of all the protocols, SPI is probably easiest to implement though. It is a simple 'one data bit per one clock pulse' system. All you have to do is assign pins for the data input (from the RFID), data output (to the RFID) and clock (to the RFID) then set or read the data bits as you drive the clock line high and low. There should also be an output to the RFID (possibly the 'SS' pin on the card reader) to tell it the first bit is on its way and then afterwards to say 'the last bit has been sent'. The exact sequence of bits is in the MFRC522 data sheet. You probably only want to send a few of the many commands, most likely the one to read the tag serial number.
Brian.
//*******************************************************************************
// sends one unsigned char from the SDO output pin.
void SendSPIByte(unsigned char SPIData)
{
unsigned char Clocks = 8;
while(Clocks)
{
DataToRAM = SPIData & 0x80;
SPIData = SPIData << 1;
delay_us(1);
ClkToRAM = 1;
ClkToRAM = 0;
Clocks--;
}
}
//*******************************************************************************
// reads one unsigned char from the SDI input pin
unsigned char GetSPIByte()
{
unsigned char SPIData =0;
unsigned char Clocks = 8;
DataToRAM = 0;
while(Clocks)
{
ClkToRAM = 1;
delay_us(1);
if(DataFromRAM) SPIData |= (1 << (Clocks - 1));
ClkToRAM = 0;
Clocks--;
delay_us(1);
}
return SPIData;
}
Hello,
i used this library, easy to understand,
with a PIC18F ,
verry usefull and **broken link removed**
https://microcontrolandos.blogspot.com/2014/02/pic-rfid-mfrc522.html
Principales fonctions :
MFRC522_Init() - Initialisation du module RC522
MFRC522_Reset() - Reset du module MFRC522.
MFRC522_Halt() - Desactivation du module = Hibernation.
MFRC522_SelectTag( char *serNum ) - Selection type de carte, param servant à l'authentification. serNum = Numero de série. 5 bytes.
MFRC522_Auth ( char authMode, char BlockAddr, char *Sectorkey, char *serNum )
- Authentification et determination du bloc actif en Lecture et Ecriture
authMode: type d'autentification A ( PICC_AUTHENT1A ) ou B ( PICC_AUTHENT1B ).
BlockAddr - Numéro du block. 4 blocs de secteur.
SectorKey - Senha d'autentification 6 bytes. Generalement definit comme 0xFFFFFFFFFFFF.
serNum - Numero de série de la carte sur 5 bytes.
MFRC522_Write( char blockAddr, char *writeData ) Ecriture 16 bytes dans le numero de bloc destinataire, sert de logo d'autentification.
blockAddr - Numero do bloco. Exceto o quarto bloco do setor, que é usado para autenticar.
writeData - 16 bytes en ecriture.
MFRC522_Read( char blockAddr, char *recvData ) Lecture des 16 bytes du numéro de bloc passé, logo d' authentification.
blockAddr - Numero do bloc.
recvData - Retourne les 16 bytes lus dans le tabelau recvData.
MFRC522_isCard( char *TagType ) - Verification presence d'une carte devant le lecteur.
TagType - Retourne un type de carte.
MFRC522_ReadCardSerial( char *str ) Lecture du numero de serie de la carte
str - Retourne un pointeur sur le numero de serie : 5 bytes ( 4 bytes + checksum ).
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?