ROBOTC.net forums
http://robotc.net/forums/

NXP PN532 using I2C bus
http://robotc.net/forums/viewtopic.php?f=1&t=5409
Page 1 of 1

Author:  sander.ashwin [ Mon Jan 21, 2013 3:10 pm ]
Post subject:  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?

Author:  mightor [ Mon Jan 21, 2013 3:32 pm ]
Post subject:  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

Author:  sander.ashwin [ Mon Jan 21, 2013 4:01 pm ]
Post subject:  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

Author:  mightor [ Mon Jan 21, 2013 4:27 pm ]
Post subject:  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

Author:  sander.ashwin [ Mon Jan 21, 2013 4:47 pm ]
Post subject:  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?

Author:  mightor [ Mon Jan 21, 2013 5:02 pm ]
Post subject:  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

Author:  sander.ashwin [ Mon Jan 21, 2013 5:54 pm ]
Post subject:  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 :)

Author:  mightor [ Tue Jan 22, 2013 3:44 am ]
Post subject:  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

Author:  sander.ashwin [ Tue Jan 22, 2013 10:11 am ]
Post subject:  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?

Author:  mightor [ Tue Jan 22, 2013 10:17 am ]
Post subject:  Re: NXP PN532 using I2C bus

You can try without but I don't know if it'll work.

= Xander

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/