PSoC 4 RC522 module

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
UyNg_4645201
Level 1
Level 1

Hello friends!

I'm recently exposed to the PSoC environment, and I'm currently working on a project that involves using the RC522 module with PSoC pioneery kit 4.

I have thoroughly looked through these two posts in which people have tried to make the RC522 work with the PSoC 4. I have tried to incorporate their suggestions but still couldn't get any successful read of the UID. If you have successfully extract the UID, I would really appreciate your guidance in trying to get my system to work.

I have included my project in the attachments.

Re: RFID-RC522 with PSOC4 verification system

mfrc522 library for psoc 5lp?

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.

I replaced these while with a delay:

CyDelayUs (500); // while (! (SPI_ReadTxStatus () & SPI_STS_SPI_IDLE));

This made it possible to read the version (VersionReg) but no more.

I reassembled the project with other components and contacts.

The project is tested (I used other contacts and Character LCD)

In the beginning - you need to make sure that you can read and write to registers.

For example, read the device version and turn on / off the antenna bit.

I am using a logic analyzer or LCD_PrintInt8 ()
rc522.jpg

View solution in original post

0 Likes
9 Replies
Rakshith
Moderator
Moderator
Moderator
250 likes received 1000 replies posted 750 replies posted

Hi UyNg_4645201​,

In your function PCD_Write_Register(), while (0u == (SPI_ReadTxStatus() & SPI_STS_SPI_DONE)); is added before any SPI transaction occurs. So the code gets stuck in an infinite loop. Can you please change the code to -

SPI_ClearFIFO(); SPI_ClearRxBuffer();

SPI_WriteTxData((addr<<1)&0x7E);//Equivalente a SPI.transfer((addr<<1)&0x7E);

SPI_WriteTxData(value);// Equivalente a  SPI.transfer(val);

while (0u == (SPI_ReadTxStatus() & SPI_STS_SPI_DONE));

SPI_WriteTxData() is a blocking function and it will poll till there is space in the Tx buffer.

Also, can you please let me know why 0xFF is sent 4 times in the PCD_Read_Register() function -

pastedImage_8.png

After this, an SPI write is performed. But the Rx buffer is not cleared. So please clear the Rx buffer before SPI write.

Can you please let me know why you have added the code SPI_WriteTxData((addr<<1)&0x7E); instead of SPI_WriteTxData(addr); ?

In the MFRC522.cpp Arduino library code​, this is the implementation -

pastedImage_10.png

Hope this helps,

Thanks and Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B
0 Likes
lock attach
Attachments are accessible only for community members.

Hello RakshithM_16! Thank you for taking your time to help me out!

1. I have tried out what you suggested to fix about the PCD_WriteRegister()

2. About the 0xFF being sent 4 times, I was trying to implement what was suggested in this post: RFID-RC522 with PSOC4 verification system in ensuring that there's always data in the TxBuffer.

3. As for SPI_WriteTxData((addr<<1)&0x7E);,  This came directly from the psoc library I found online. I'm new to using SPI so in short, I don't really know how this works

I am including the changes that I've made in the RC522.c file. There's alot of of SPI_WriteTx before RxBuffer is cleared, and I'm not sure if if the RxBuffer should be cleared everytime there's an SPI_WriteTX. I have compiled and downloaded these changes to the PSOC and still I couldn't get any successful read of the UID.

pastedImage_0.png

It seems to always be repeating this PCD_ReadRegister().

Thank you, Uyen

0 Likes

Hi UyNg_4645201​,

About the 0xFF being sent 4 times, I was trying to implement what was suggested in this post: RFID-RC522 with PSOC4 verification system in ensuring that there's always data in the TxBuffer.

Actually, the way it works is, when the SPI master writes data to the slave it also receives data from the slave and the data is stored in the Rx buffer. So, when you write data 4 times you also get 4 bytes of data into the Rx buffer. When you again write data the Rx buffer overflows and the data received will be lost. For this reason, I suggested clearing the Rx buffer before writing additional data to the Tx buffer.

As for SPI_WriteTxData((addr<<1)&0x7E);,  This came directly from the psoc library I found online. I'm new to using SPI so in short, I don't really know how this works

Can you please share the library that you have found. It will help us in debugging the issue.

Do you have access to a Logic Analyzer? If you do, then you can probe the SPI lines and check the data transactions between the SPI master and the RFID module. If the code finished executing PCD_WriteRegister or PCD_ReadRegister, then the PSoC 4 device would have sent at least a byte to the slave. I want to check the response received from the slave.

Thanks and Regards,

Rakshith M B

Thanks and Regards,
Rakshith M B
0 Likes

Thank you for getting back to me!

The library on Github at this link: RC522/RC522.c at master · LASER-UD/RC522 · GitHub

I'm not sure if this library is specifically written for PSoC 5LP and that's why it doesn't work on PSoC 4.

Unfortunately I don't have a logic analyzer so I can't verify the SPI communication.

0 Likes

it seems you forgot to run SPI   (   SPI_Start();  )
Evgeniy

0 Likes

SPI_Start() is called within PCD_Init(), which I have called on in main()

Uyen

0 Likes
lock attach
Attachments are accessible only for community members.

I replaced these while with a delay:

CyDelayUs (500); // while (! (SPI_ReadTxStatus () & SPI_STS_SPI_IDLE));

This made it possible to read the version (VersionReg) but no more.

I reassembled the project with other components and contacts.

The project is tested (I used other contacts and Character LCD)

In the beginning - you need to make sure that you can read and write to registers.

For example, read the device version and turn on / off the antenna bit.

I am using a logic analyzer or LCD_PrintInt8 ()
rc522.jpg

0 Likes

Hello EvPa_264126

I saw you did something similar in a different post, but have you successfully extracted the UID? Assuming that the ReadRegister() and WriteRegister() work properly, does this mean that PICC_IsNewCardPresent(void) and bool PICC_ReadCardSerial(void) work as well since these functions mainly rely on the read and write to register funcitons?

Thank you for putting in the effort to help me with my project.

-Uyen

0 Likes

I have not tested the library. Just created a project - a workpiece for checking the work

ReadRegister () and WriteRegister ().

To read the Serial Number, I used the USB-Serial (UART / I2C / SPI) Bridge on the CY7C65211

and LaVIEW. 

Evgeniy

0 Likes