RFID on PSOC5LP

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

cross mob
RoBe_1502026
Level 4
Level 4
25 replies posted 10 replies posted 5 replies posted

Hi All,

   

I have a MFRC5222 and a PN532 board for rfid.

   

I am trying to implememnt RFID on my project using the psoc5lp but am having difficulty. I tried to search online for solution with no luck.

   

Both boards allow I2C or SPI but I have tried bot and am hitting a brisk wall.

   

Can anyone give me some advice? I have allot of experience with i2c but even with my logic analyzer with decoder I cant find the problem.

   

As for SPI, I dont really have any experience with it.

   

Best Regards,

   

Rob Berry

0 Likes
10 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I would suggest to use I2C at the beginning. When you run into timing problems, you may switch to SPI, but imho this is a bit more complicated than I2C.

   

At first you will need pullup resistors for the I2C lines in the range of ~2k. Without it will not work!

   

Byte I2C interface is quite simple: After setting up the component and starting it you use

   

    I2C_MasterSendStart(DeviceAddress,I2C_WRITE_XFER_MODE);    // Initialize a transaction for writing
    I2C_MasterWriteByte(Register);                // Indicate which register you want to write to
    I2C_MasterWriteByte(Value);                // Write to register
    I2C_MasterSendStop();                    // End of transaction

   

When you want to read from a device you use (example for reading two bytes

   

    I2C_MasterSendStart(DeviceAddress,I2C_WRITE_XFER_MODE);    // Initialize a transaction for writing
    I2C_MasterWrite(Register);                // Indicate which register you want to write to
    I2C_MasterSendRestart(DeviceAddress,I2C_READ_XFER_MODE);
    I2C_MasterReadByte(I2C_ACK_DATA);            // Read from register
    I2C_MasterReadByte(I2C_NAK_DATA);            // Read from register, last byte is NAKed
    I2C_MasterSendStop();                    // End of transaction

   

Not too difficult. Keep in mind that most of the APIs (except those for reading a byte) return a status byte which, when non-zero indicate an error condition.

   

When you get stuck, consider posting your complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

   

 

   

Happy coding!
Bob

0 Likes
lock attach
Attachments are accessible only for community members.
RoBe_1502026
Level 4
Level 4
25 replies posted 10 replies posted 5 replies posted

Hi,

   

I am still having problems. I have attached the project. you will see code from a website who has dont it with a psoc 4 pioneer board. I dont have this so cant test on one. was hoping the code would work on a 5lp but doesn't. I added the direct i2c code to see if I can see the traffic on my logic analyizer. It appeards to lockup during the read.

   

thanks for any help anyone can provide!!!

   

Rob

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

This is darn wrong!!!

   

       I2C_MasterSendStart(PN532_I2C_ADDRESS,I2C_READ_XFER_MODE);
    I2C_MasterReadBuf(PN532_I2C_ADDRESS, recBuff, n+2, I2C_MODE_COMPLETE_XFER);
    while(0u == (I2C_MasterStatus() & I2C_MSTAT_RD_CMPLT)){ }
I2C_MasterSendStop();

   

only the line

   

    I2C_MasterReadBuf(PN532_I2C_ADDRESS, recBuff, n+2, I2C_MODE_COMPLETE_XFER);
would do what you want.

   

Why n+2??

   

During testphase (at least) check the returned value of I2C_MasterReadBuf() for errors (non-zero)

   

 

   

Bob

0 Likes
RoBe_1502026
Level 4
Level 4
25 replies posted 10 replies posted 5 replies posted

I am not using the adafruit libs. 

   

I am trying to do it step by step. here is the code i am working with.

   

  I2C_MasterSendStart(PN532_I2C_ADDRESS,I2C_WRITE_XFER_MODE);    // Initialize a transaction for writing
  I2C_MasterWriteByte(0xDA);                // register with data
  I2C_MasterSendStop();
  I2C_MasterSendStart(PN532_I2C_ADDRESS,I2C_READ_XFER_MODE);
         // Read from register
   readmsg = I2C_MasterReadBuf(PN532_I2C_ADDRESS, recBuff,32, I2C_MODE_COMPLETE_XFER);  
  I2C_MasterReadByte(I2C_NAK_DATA);            // Read from register, last byte is NAKed
  I2C_MasterSendStop();      

   

I am not sure of n+2 I do know they use 64 byte blocks. I just need to get it so there is activity on the i2c bus. I get one small start then it dies. I am going to work on it some more tomorrow. I knoiw it is doable, I have done i2c with lidar devices from scratch. I am going to read the operation of the chip/card in detail maybe i have a timing issue or something. 

   

Thanks!

   

Rob

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

  I2C_MasterWriteByte(0xDA);                // register with data
  I2C_MasterSendStop();***** This will terminate the transaction, Do not use that here

   

I2C_MasterSendStart(PN532_I2C_ADDRESS,I2C_READ_XFER_MODE); *** No, use Restart!

   

// Read from register
   readmsg = I2C_MasterReadBuf(PN532_I2C_ADDRESS, recBuff,32, ***** Do not mix High-level and basic APIs

   

Use instead ReadByte in a loop and do not forget to NAK the last byte you read. That will tell the slave a "normal" end. Stick to the example I gave you.

   

Use the returned status of the APIs. When SendStart() fails, all others will fail as well and you will know it's a wrong address or an electrical problem.

   

 

   

Bob

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The high-level APIs must be used in this way:

   

Writing to slave Count bytes
I2C_MasterWriteBuf(SlaveAddress,DataPtr,Count,I2C_MODE_COMPLETE_XFER);

   

Reading from Slave sending register byte first:
I2C_MasterWriteBuf(SlaveAddress,&RegAddress,1,I2C_MODE_NO_STOP);
I2C_MasterReadBuf(SlaveAddress,DataPtr,Count,I2C_MODE_REPEAT_START);

   

 

   

Bob

0 Likes
RoBe_1502026
Level 4
Level 4
25 replies posted 10 replies posted 5 replies posted

Bob,

   

I feel SOOOOOO stupid!!! First I want to thankyou for your help. The problem was the API from adafruit uses the IRQ from the board. The stupid part is, I used their sample application to try this. They had the irq pin on the schematic but the HW box was NOT check!!! The pin list shows the pin, I had it mapped to a pin but it never actually looked at it. once I enabled the HW connection it all works!!!!

   

Best Regards,

   

Rob

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Glad that you got it working in the end.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Hi! 

   

I'm new here in the community, and totally a "noob" programing on PSOC or whatever other. I need to comunicate my 5LP to a nfc device, specifically this: https://www.itead.cc/wiki/ITEAD_PN532_NFC_MODULE

   

I think that its compatible with the adafruit nfc library, that you used in your project, but i don't know how to build the top design on my project. In your project, you haven't got assign the scl pin, why?

   

(and sorry for my english level ^^" )

   

Thanks! Sergio

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the forum, Sergio.

   

There are a couple of videos showing how to use the Creator IDE. Basically you need to decide which interface of your nfc board you'd like to use (UART is easiest) and place a corresponding interface from the component list on to the topdesign. Complete with IO pins (when required) and assign the pins to real PSoC pins.

   

 

   

Bob

0 Likes