CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

RC522 RFID module SPI
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 12835

View user's profile Send private message

PostPosted: Wed May 31, 2017 12:57 am     Reply with quote

The answer has already been given. Not a software problem, but hardware.

The PIC SPI inputs are Schmitt inputs. require signals to go up to 0.8*Vdd (4v on a 5v PIC). The Arduino SPI inputs have conventional buffers.

Need buffer chips, or a 3.3v PIC to work.
Mario_KA



Joined: 16 Nov 2017
Posts: 22

View user's profile Send private message

PostPosted: Thu Nov 16, 2017 9:23 am     Reply with quote

I've got the same problem. My entire system is working on 3.3V so that shouldnt be a problem.

Does anyone have a code that is working on PIC16F887 and MFRC522 to just read the ID?
temtronic



Joined: 01 Jul 2010
Posts: 5954
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Nov 16, 2017 10:12 am     Reply with quote

That RFID reader is capable of SPI, I2C and serial interfaces so you'll need to specify which you want.
If I assume you have a premade module and NOT the chip, you'll have to post a link to the module. Some are I2C only, some SPI, some bring ALL the pins out...
Mario_KA



Joined: 16 Nov 2017
Posts: 22

View user's profile Send private message

PostPosted: Thu Nov 16, 2017 11:52 am     Reply with quote

My bad, it uses just SPI. I read the Datasheet because the module has around 60+ addresses/registers. I think it is quiet difficult to set them correct. Maybe I am blind but I did not find the address I have to access in order to get an ID whenever a card is close.

As a first try I want just to use spi_read() to read the RFIDs FIFO?!... Without even checking if the module is ready. Just to check if I can communicate correctly
temtronic



Joined: 01 Jul 2010
Posts: 5954
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Nov 16, 2017 1:33 pm     Reply with quote

Post a link to what module you have...not all modules are the same.
PCM programmer



Joined: 06 Sep 2003
Posts: 20218

View user's profile Send private message

PostPosted: Thu Nov 16, 2017 4:18 pm     Reply with quote

He probably means the Version Register. The data sheet shows it will
return one of these two numbers:
Quote:
MFRC522 version 1.0 software version is: 91h.
MFRC522 version 2.0 software version is: 92h.

See the data sheet on page 66 at the bottom:
https://www.nxp.com/docs/en/data-sheet/MFRC522.pdf
Mario_KA



Joined: 16 Nov 2017
Posts: 22

View user's profile Send private message

PostPosted: Fri Nov 17, 2017 8:20 am     Reply with quote

https://www.amazon.co.uk/UEB-MFRC-522-Radiofrequency-Inducing-Arduino/dp/B01D168X9Y/ref=sr_1_1?ie=UTF8&qid=1510928214&sr=8-1&keywords=mfrc522&dpID=41kuwWADCIL&preST=_SY300_QL70_&dpSrc=srch

I got this one, don't really know if it is Version 1 or 2 though. The only Datasheet is the one PCM Programmer posted.

Honestly there are just minor changes between the two versions. I don't think they interfere with the basic functionality for my usage.
Ttelmah



Joined: 11 Mar 2010
Posts: 12835

View user's profile Send private message

PostPosted: Fri Nov 17, 2017 8:27 am     Reply with quote

Mario_KA wrote:
I've got the same problem. My entire system is working on 3.3V so that shouldnt be a problem.

Does anyone have a code that is working on PIC16F887 and MFRC522 to just read the ID?


The 16F887, is _not_ rated to run at 20MHz and 3.3v.
10MHz max at 3.3v.

To run at 20Mhz and 3.3v, you need a different processor....
Mario_KA



Joined: 16 Nov 2017
Posts: 22

View user's profile Send private message

PostPosted: Fri Nov 17, 2017 8:39 am     Reply with quote

Ttelmah wrote:
Mario_KA wrote:
I've got the same problem. My entire system is working on 3.3V so that shouldnt be a problem.

Does anyone have a code that is working on PIC16F887 and MFRC522 to just read the ID?


The 16F887, is _not_ rated to run at 20MHz and 3.3v.
10MHz max at 3.3v.

To run at 20Mhz and 3.3v, you need a different processor....


Yes i found that information in the PIC's datasheet, anyway we always drive these processors on 8MHz for some reason.
I mean there is no issue to run the system with 8MHz, right?
Ttelmah



Joined: 11 Mar 2010
Posts: 12835

View user's profile Send private message

PostPosted: Fri Nov 17, 2017 8:44 am     Reply with quote

Mario_KA wrote:
Ttelmah wrote:
Mario_KA wrote:
I've got the same problem. My entire system is working on 3.3V so that shouldnt be a problem.

Does anyone have a code that is working on PIC16F887 and MFRC522 to just read the ID?


The 16F887, is _not_ rated to run at 20MHz and 3.3v.
10MHz max at 3.3v.

To run at 20Mhz and 3.3v, you need a different processor....


Yes i found that information in the PIC's datasheet, anyway we always drive these processors on 8MHz for some reason.
I mean there is no issue to run the system with 8MHz, right?


No 8MHz should be fine, but the original poster (who is showing 20Mhz, on this chip), either has a clock problem, or a signal voltage problem....
Mario_KA



Joined: 16 Nov 2017
Posts: 22

View user's profile Send private message

PostPosted: Fri Nov 17, 2017 9:01 am     Reply with quote

Okay gotcha, so basically to write/read to a register I have to add a 1/0 in front of the address and end the byte with a zero?
For instance register ("29") 0x29 is "0010 1001" shift left and add 1 in front
=> "1101 0010" which is 0xD2?


From that I'd write something like:

Code:

   output_low(chip_select);
   variable_x=spi_read(0xD2); //to write register 0x29?!
   variable_x=spi_read( "write some data" );
   output_high(chip_select); //end spi


Is that correct so far? That is at least what I understood from the Data Sheet.
temtronic



Joined: 01 Jul 2010
Posts: 5954
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Nov 17, 2017 9:53 am     Reply with quote

It looks like you're confusing one version of I2C protocol with the standard SPI.
The 'shifting...and ... 1/0' sounds like 7 bit I2C which is NOT the same as SPI.

In SPI if the register is 0xD2 in the datasheet, it is 0xD2 in SPI, NO shifting of bits...

There is a 'problem' in that the RFID chip actually can use 3 different protocols, I2C, SPI and serial. Which one you use and code for depends upon the 'RFID module' you're using.
According to the link to the device, it's using SPI.
Mario_KA



Joined: 16 Nov 2017
Posts: 22

View user's profile Send private message

PostPosted: Fri Nov 17, 2017 11:06 am     Reply with quote

https://www.nxp.com/docs/en/data-sheet/MFRC522.pdf

Quote:
Page 10
8.1.2.3 SPI address byte
The address byte must meet the following format.
The MSB of the first byte defines the mode used. To read data from the MFRC522 the
MSB is set to logic 1. To write data to the
MFRC522 the MSB must be set to logic 0. Bits 6
to 1 define the address and the LSB is set to logic 0


Okay I got it wrong. I think if I want to write, then I shift it to the left or just multiply it by 2.

And if I want to read from a register I use my code above, am I correct now?
PCM programmer



Joined: 06 Sep 2003
Posts: 20218

View user's profile Send private message

PostPosted: Fri Nov 17, 2017 10:20 pm     Reply with quote

Try this:
Code:

int8 MFRC522_read(int8 addr)
{
int8 retval;

output_low(MFRC522_CS_PIN);
spi_write(((addr << 1) & 0x7E) | 0x80);
retval = spi_read(0x00);
output_high(MFRC522_CS_PIN);

return(retval);
}



void MFRC522_write(int8 addr, int8 data)
{
output_low(MFRC522_CS_PIN);
spi_write((addr << 1) & 0x7E);
spi_write(data);
output_high(MFRC522_CS_PIN);
}
Mario_KA



Joined: 16 Nov 2017
Posts: 22

View user's profile Send private message

PostPosted: Sat Nov 18, 2017 4:44 am     Reply with quote

Thanks so far.
Thats exactly how I understood the datasheet. I appreciate your answer a lot.
The earliest I can try it on my PIC is next week and hopefully I will find the correct registers to setup the RFID and just read the RFID Tag.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4  Next
Page 2 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group