7 years, 5 months ago.

LPC1678 SPI interface with RC522

Hello ,

i am trying to interface LPC1768 with RFID reader RC522 over the SPI port.

i am getting response as 0x21 . i have attached code for your reference.

i am unable to read the RFID.

  1. include "mbed.h"

SPI spi(p5, p6, p7); mosi, miso, sclk DigitalOut cs(p8); int main() { Chip must be deselected cs = 1;

Setup the spi for 8 bit data, high steady state clock, second edge capture, with a 1MHz clock rate spi.format(8,3); spi.frequency(1000000);

Select the device by seting chip select low cs = 0; while(1){ Send 0x8f, the command to read the WHOAMI register int whoami= spi.write(0x8F);

whoami = spi.write(0x00); printf("WHOAMI register = 0x%X\n", whoami);

} Deselect the device cs = 1; }

1 Answer

7 years, 5 months ago.

Please use <<code>> <</code>> tags to make your code easier to read.

Try again with:

spi.format(8,0); replace your spi.format(8,3);

reviewing this detail from here:

https://developer.mbed.org/users/AtomX/code/MFRC522/docs/63d729186747/MFRC522_8cpp_source.html

Please also study this example:

https://developer.mbed.org/users/kirchnet/code/RFID-RC522/

Do you have the RESET pin mapped on the RC522 ?

include "mbed.h" 

SPI spi(p5, p6, p7); // mosi, miso, sclk 

DigitalOut cs(p8); 

int main()
{ 

//Chip must be deselected 
cs = 1;

//Setup the spi for 8 bit data, high steady state clock, second edge capture, with a 1MHz clock rate 
spi.format(8,3);  // test with spi.format(8,0); 

spi.frequency(1000000);

//Select the device by seting chip select low 
cs = 0; 

while(1)
{ 

//Send 0x8f, the command to read the WHOAMI register 
int whoami= spi.write(0x8F);

whoami = spi.write(0x00); 

printf("WHOAMI register = 0x%X\n", whoami);

} 

//Deselect the device 
cs = 1; 

}