View unanswered posts | View active topics It is currently Wed Apr 23, 2014 10:44 pm






Reply to topic  [ 10 posts ] 
NXP PN532 using I2C bus 
Author Message
Rookie

Joined: Thu Dec 22, 2011 6:33 pm
Posts: 7
Post NXP PN532 using I2C bus
I am trying to connect a NFC chip (NXP PN532) to the I2C bus of the NXT.
But programming seems to be a hell as I don't understand the working of I2C.

A datasheet is available here:
http://www.adafruit.com/datasheets/pn532um.pdf

And a Arduino driver is available here:
https://github.com/adafruit/Adafruit-PN532

Code:
#pragma config(Sensor, S2,     ,               sensorI2CCustom)

char replyMsg[6];

task main()
{
   char GetFirmwareVersion[10] = {0x48 >> 1, 0x00, 0x00, 0xFF, 0x02, 0xFE, 0xD4, 0x02, 0x2A, 0x00};
   sendI2CMsg(S2, GetFirmwareVersion, 6);
   Sleep(200);
   readI2CReply(S2, replyMsg, 6);
   nxtDisplayTextLine(2, "1: %x", replyMsg[0]);
   nxtDisplayTextLine(3, "2: %x", replyMsg[1]);
   nxtDisplayTextLine(4, "3: %x", replyMsg[2]);
   nxtDisplayTextLine(5, "4: %x", replyMsg[3]);
   nxtDisplayTextLine(6, "5: %x", replyMsg[4]);
   while(1)
   {
   }
}


The first byte is the I2C address, which needs to be bit shifted (I think...)
Am I in the right direction?


Mon Jan 21, 2013 3:10 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3116
Location: Rotterdam, The Netherlands
Post Re: NXP PN532 using I2C bus
Do you have the appropriate pull-ups on the lines? They should be about 81kOhm for 5V and about 43kOhm for 3V3.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Jan 21, 2013 3:32 pm
Profile WWW
Rookie

Joined: Thu Dec 22, 2011 6:33 pm
Posts: 7
Post Re: NXP PN532 using I2C bus
Hmm, why do I need pull ups?

EDIT:
http://hubcitylabs.org/nfc-on-raspberry ... b-and-i2c/
Do you mean something like this?

EDIT2:
http://www.elechouse.com/elechouse/imag ... Manual.pdf
"On-board level shifter, Standard 5V TTL for I2C and UART"
Does this mean that a pull up is already applied on the board? The PDF is the datasheet of the chip I'm using, ElecHouse NFC Module v2.0


Mon Jan 21, 2013 4:01 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3116
Location: Rotterdam, The Netherlands
Post Re: NXP PN532 using I2C bus
The NXT has a bit of a crappy I2C implementation and requires a very high pull-up on both the SCL and SDA lines or it simply won't work with most devices.
As for the RasPi image, yes, that's what I mean, except you'll need 82kOhm instead. I can't see any pull-ups on the images in that other PDF, but you may want to verify with the manufacturer.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Jan 21, 2013 4:27 pm
Profile WWW
Rookie

Joined: Thu Dec 22, 2011 6:33 pm
Posts: 7
Post Re: NXP PN532 using I2C bus
So if I understand you correctly, it's possible that a device that works well on a Arduino (out-of-the-box) may fail on NXT without the proper pull up?

I've already written a BT UART driver in RobotC which works lovely when the PN532 is connected to a HC-05 Linvor bluetooth chip, but I screwed the chip up while soldering...
So now I don't have any option than to use I2C, since those HC-05 ship from Hong Kong.. it will at least take 2 weeks before a new ordered one will arrive :(

Anyway, I'll e-mail Elechouse to ask them about the pull up :)
Hopefully they answer quick. I was hoping to get this fixed before 1 feb for a school project.

Btw, I just found out something else. I found a I2C scanner demo in the RobotC example folder.
It scans really quick, but the port that the PN532 is connected to scans a lot slower, although it doesn't find my chip.
Should the I2C scanner demo find every I2C device? Or is it made to find Lego sensors?

EDIT: I use the 4.2V power supply from the NXT, do you think it provides enough power?


Mon Jan 21, 2013 4:47 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3116
Location: Rotterdam, The Netherlands
Post Re: NXP PN532 using I2C bus
sander.ashwin wrote:
So if I understand you correctly, it's possible that a device that works well on a Arduino (out-of-the-box) may fail on NXT without the proper pull up?

Indeed.

Quote:
I've already written a BT UART driver in RobotC which works lovely when the PN532 is connected to a HC-05 Linvor bluetooth chip, but I screwed the chip up while soldering...

The BT connection will probably be significantly faster than I2C, which can only go as fast as about 30kHz at high speed. Another option is to use a MAX485 chip to interface with the UART of your reader.

Quote:
Btw, I just found out something else. I found a I2C scanner demo in the RobotC example folder.
It scans really quick, but the port that the PN532 is connected to scans a lot slower, although it doesn't find my chip.
Should the I2C scanner demo find every I2C device? Or is it made to find Lego sensors?

It is not really made to find anything other than LEGO "compliant" sensors, as in ones with registers in specific places that contain manufacturer info, that sort of thing.

Quote:
EDIT: I use the 4.2V power supply from the NXT, do you think it provides enough power?

By the looks of it, that thing can consume a fair amount of power, up to 140mA, it seems. You may want to consider an external power supply.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Jan 21, 2013 5:02 pm
Profile WWW
Rookie

Joined: Thu Dec 22, 2011 6:33 pm
Posts: 7
Post Re: NXP PN532 using I2C bus
Ahh thanks for all help :)

I only have 2 more questions:
Can I wire everything like this? http://lackawanna.hackhut.com/2011/10/10/easy-i2c/
Is this possible? Can I just wire the PN532 and the 2 resistors to the same 5V power supply?

I think they might have those resistors at school :)


Mon Jan 21, 2013 5:54 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3116
Location: Rotterdam, The Netherlands
Post Re: NXP PN532 using I2C bus
Yeah, that should be fine. You could also pull them up the NXT's Vout lines on the sensor port.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Tue Jan 22, 2013 3:44 am
Profile WWW
Rookie

Joined: Thu Dec 22, 2011 6:33 pm
Posts: 7
Post Re: NXP PN532 using I2C bus
I got the resistors, but the PCB manufacturer replied to my message, this is what they wrote:

Dear Sir:
Thanks for your mail.
As you could see from this schematic: http://www.elechouse.com/elechouse/imag ... D_V2.0.pdf
We use 2N7002DW to shift the 3V3 TTL to other MCU's TTL. Pull-up resisters are not necessary.

Best Regards
Wilson Shen


Is it still worth trying with the 82 kOhm resistors?


Tue Jan 22, 2013 10:11 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3116
Location: Rotterdam, The Netherlands
Post Re: NXP PN532 using I2C bus
You can try without but I don't know if it'll work.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Tue Jan 22, 2013 10:17 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 10 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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 post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.