View previous topic :: View next topic |
Author |
Message |
Ttelmah
Joined: 11 Mar 2010 Posts: 19463
|
|
Posted: Wed May 31, 2017 12:57 am |
|
|
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
|
|
Posted: Thu Nov 16, 2017 9:23 am |
|
|
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: 9205 Location: Greensville,Ontario
|
|
Posted: Thu Nov 16, 2017 10:12 am |
|
|
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
|
|
Posted: Thu Nov 16, 2017 11:52 am |
|
|
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: 9205 Location: Greensville,Ontario
|
|
Posted: Thu Nov 16, 2017 1:33 pm |
|
|
Post a link to what module you have...not all modules are the same. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Nov 16, 2017 4:18 pm |
|
|
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
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19463
|
|
Posted: Fri Nov 17, 2017 8:27 am |
|
|
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
|
|
Posted: Fri Nov 17, 2017 8:39 am |
|
|
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: 19463
|
|
Posted: Fri Nov 17, 2017 8:44 am |
|
|
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
|
|
Posted: Fri Nov 17, 2017 9:01 am |
|
|
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: 9205 Location: Greensville,Ontario
|
|
Posted: Fri Nov 17, 2017 9:53 am |
|
|
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
|
|
Posted: Fri Nov 17, 2017 11:06 am |
|
|
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: 21708
|
|
Posted: Fri Nov 17, 2017 10:20 pm |
|
|
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
|
|
Posted: Sat Nov 18, 2017 4:44 am |
|
|
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. |
|
|
|