[SOLVED] [PN532 NFC] Cabling to use I2C?

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
__Vinz__
 
Posts: 17
Joined: Sat Jan 16, 2016 3:54 am

[SOLVED] [PN532 NFC] Cabling to use I2C?

Post by __Vinz__ »

Hi there,

I am trying to use the PN532 breakout board in I2C mode using a Sparkfun Redboard. The PN532 tutorial is not very detailed on these connections so I figured I'd ask my questions here:
1. As for SPI, I am using the level shifter for SDA, SCL and the IRQ pin. Is that correct?
2. Should the pullup resistors be put on the breakout side (i.e after the level shifter) or before (i.e on the Arduino side)? I have actually tried both and see no change.

The board works fine in SPI mode, I have set the jumpers correctly for I2C AFAIK and am using the correct nfc() object in the sketch (i.e the one for I2C with only two parameters). RESET pin is not connected (not even sure which one this is; is this RSTOUT_N?).

My logic analyzer shows that there is a byte sent to 0x48 but no device answers (NAK). Then another request comes on 0x49, again with a NAK. Then the readMifare sketch reports the board as not found. This is confirmed by running the I2C scanner code which does not find anything :

Code: Select all


I2CScanner ready!
starting scanning of I2C bus from 0 to 127...
addr: 0x0		addr: 0x1		addr: 0x2		addr: 0x3	
addr: 0x4		addr: 0x5		addr: 0x6		addr: 0x7	
addr: 0x8		addr: 0x9		addr: 0xA		addr: 0xB	
addr: 0xC		addr: 0xD		addr: 0xE		addr: 0xF	
addr: 0x10		addr: 0x11		addr: 0x12		addr: 0x13	
addr: 0x14		addr: 0x15		addr: 0x16		addr: 0x17	
addr: 0x18		addr: 0x19		addr: 0x1A		addr: 0x1B	
addr: 0x1C		addr: 0x1D		addr: 0x1E		addr: 0x1F	
addr: 0x20		addr: 0x21		addr: 0x22		addr: 0x23	
addr: 0x24		addr: 0x25		addr: 0x26		addr: 0x27	
addr: 0x28		addr: 0x29		addr: 0x2A		addr: 0x2B	
addr: 0x2C		addr: 0x2D		addr: 0x2E		addr: 0x2F	
addr: 0x30		addr: 0x31		addr: 0x32		addr: 0x33	
addr: 0x34		addr: 0x35		addr: 0x36		addr: 0x37	
addr: 0x38		addr: 0x39		addr: 0x3A		addr: 0x3B	
addr: 0x3C		addr: 0x3D		addr: 0x3E		addr: 0x3F	
addr: 0x40		addr: 0x41		addr: 0x42		addr: 0x43	
addr: 0x44		addr: 0x45		addr: 0x46		addr: 0x47	
addr: 0x48		addr: 0x49		addr: 0x4A		addr: 0x4B	
addr: 0x4C		addr: 0x4D		addr: 0x4E		addr: 0x4F	
addr: 0x50		addr: 0x51		addr: 0x52		addr: 0x53	
addr: 0x54		addr: 0x55		addr: 0x56		addr: 0x57	
addr: 0x58		addr: 0x59		addr: 0x5A		addr: 0x5B	
addr: 0x5C		addr: 0x5D		addr: 0x5E		addr: 0x5F	
addr: 0x60		addr: 0x61		addr: 0x62		addr: 0x63	
addr: 0x64		addr: 0x65		addr: 0x66		addr: 0x67	
addr: 0x68		addr: 0x69		addr: 0x6A		addr: 0x6B	
addr: 0x6C		addr: 0x6D		addr: 0x6E		addr: 0x6F	
addr: 0x70		addr: 0x71		addr: 0x72		addr: 0x73	
addr: 0x74		addr: 0x75		addr: 0x76		addr: 0x77	
addr: 0x78		addr: 0x79		addr: 0x7A		addr: 0x7B	
addr: 0x7C		addr: 0x7D		addr: 0x7E		addr: 0x7F	

done

Could you help me out here?

Thanks !
Last edited by __Vinz__ on Mon Feb 08, 2016 1:36 pm, edited 2 times in total.

User avatar
__Vinz__
 
Posts: 17
Joined: Sat Jan 16, 2016 3:54 am

Re: [PN532 NFC breakout] Cabling to use I2c?

Post by __Vinz__ »

Upping. Are there any suggestions here?

Thanks!

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: [PN532 NFC breakout] Cabling to use I2c?

Post by adafruit_support_mike »

Sorry for the late reply.

Post a photo showing your hardware and connections and we'll take a look. The PN532 board usually works well in I2C.

User avatar
__Vinz__
 
Posts: 17
Joined: Sat Jan 16, 2016 3:54 am

Re: [PN532 NFC breakout] Cabling to use I2c?

Post by __Vinz__ »

Hi Mike,

Thanks for your help. Please find attached pictures of the wiring. I have kept the level shifter and wired as follows:
Arduino SDA -> shifter pin #9
shifter pin #10 -> breakout SDA
Arduino SCL -> shifter pin #14
shifter pin #15 -> breakout SCL
I have add 1k resistors between SDA/SCL and Vcc/GND rails, as pullups (did not have 1.5K)

Arduino GND -> ground rail
Arduino 3.3V -> + Vcc rail

shifter pin #1 -> Vcc rail
shifter pin #8 -> GDN rail

breakout GND -> GDN rail
breakout 3.3V -> VCC rail

Arduino pin#8 -> shifter pin #3
shifter pin#2 -> breakout IRQ

I have specified pin #8 as IRQ pin in the code + uncommented the I2C declaration in readMifare and commented out the SPI one.
Attachments
Wiring_level_shifter2.jpg
Wiring_level_shifter2.jpg (772.32 KiB) Viewed 3483 times
Wiring_breakout2.jpg
Wiring_breakout2.jpg (850.69 KiB) Viewed 3483 times
Wiring2.jpg
Wiring2.jpg (783.87 KiB) Viewed 3483 times

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: [PN532 NFC breakout] Cabling to use I2c?

Post by adafruit_support_mike »

What chip are you using as the level shifter?

User avatar
__Vinz__
 
Posts: 17
Joined: Sat Jan 16, 2016 3:54 am

Re: [PN532 NFC breakout] Cabling to use I2c?

Post by __Vinz__ »

The one which came with the breakout board, that is a 4050.

User avatar
michaelmeissner
 
Posts: 1830
Joined: Wed Aug 29, 2012 12:40 am

Re: [PN532 NFC breakout] Cabling to use I2c?

Post by michaelmeissner »

You listed using 1k pull-up resistors. Unfortunately from what I've read, 1k is too low of a value to use for i2c. Here is an article if you want to calculate the best resistance to use for a given circuit: http://www.dsscircuits.com/articles/47- ... -resistors.

Normally 4.7K resistors are used for 5v i2c systems, and 2.2-2.4K are used for 3.3v systems. But depending on how many devices you have, you might be able to go lower.

User avatar
__Vinz__
 
Posts: 17
Joined: Sat Jan 16, 2016 3:54 am

Re: [PN532 NFC breakout] Cabling to use I2c?

Post by __Vinz__ »

Michael,

Thanks for your reply and for the very useful link! It is very possible the problem lies with the resistors indeed. I will try to change those and recheck, then report back.

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: [PN532 NFC breakout] Cabling to use I2c?

Post by adafruit_support_mike »

The HEF4050 can't transmit I2C signals.

I2C devices use open-drain pins which open or close a connection to GND. Several open-drain devices can connect to the same line because there's no chance of them fighting with each other. If all the devices have their connection to GND shut off, the pull-up resistor holds the line high. If any device turns its connection to GND on, it will pull the line low. If another device opens its connection to GND at the same time, it will just provide a redundant path to GND.

The HEF4050's outputs swap between high and low, and if the chip is holding the line high, an I2C device on the other end won't be able to pull it low (or risks shorting the HEF4050 if it does).

A regular Arduino doesn't have pull-up resistors on its I2C pins, and can read 0v-to-3.3v signals as valid high and low logic levels, so you don't need a level shifter at all. Just connect the pull-up resistors on SDA and SCL to the 3.3v rail and things will work.

I don't know if the RedBoard has pull-ups on SDA and SCL, so you'll need to check with SparkFun about that. If it doesn't, you can connect it as described above.

If the RedBoard does have 5v pull-ups, you'll need an I2C-friendly level shifter like this one: https://www.adafruit.com/product/757

User avatar
__Vinz__
 
Posts: 17
Joined: Sat Jan 16, 2016 3:54 am

Re: [PN532 NFC breakout] Cabling to use I2c?

Post by __Vinz__ »

@michaelmeissner: ok, I tried to use 2.2k resistors instead (red/red/red unless I am wrong) but that did not change anything here.

@adafruit_support_mike : thanks for your detailed answer. As per its schematic, the Redboard does seem to behave like a normal Arduino so I think we are OK here.

However, I don't understand what you are saying about the things I need to change:
  • the resistors are already connected between SDA/SCL (breakout board side, so 3.3V levels) and the 3.3V rail (via the two green wires plugged in the rail, which is powered via the Arduino 3.3V pin [again, green wire]), as detailed in the bottom of the tutorial page
  • my multimeter gives me 4.94V when I measure the Arduino SDA and SCL pins when powered on. I understand the Arduino can read 3.3V logic levels but I thought the shifter was to protect the breakout board, not to make the Arduino be able to read the values. My current understanding is that if I connect the SDA/SCL Arduino pins to those of the breakout board without a shifter, I will damage the board (putting 5V into a 3V-compatible pin). Could you explain what I got wrong here?
Thanks to both of you for your help!

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: [PN532 NFC breakout] Cabling to use I2c?

Post by adafruit_support_mike »

The tutorial page shows the SPI wiring. SPI doesn't use open-drain outputs, so the HEF4050 works as a level shifter for that protocol.

You're right that connecting pull-ups to the 3.3v rail is primarily to protect the PN532. The ATmega328's internal pull-ups are fairly high value (somewhere around 20k IIRC), so connecting 1k resistors to the 3.3v rail will hold the voltage on the SDA and SCL lines at levels that are safe for the PN532, but readable for the Arduino.

To make sure you're using the right resistor values, disconnect the PN532 from SDA and SCL, connect resistors from those lines to the 3.3v rail, power the Arduino, and measure the voltage on the SDA and SCL lines. If the voltage is 3.5v or lower, it's safe to connect the PN532.

User avatar
__Vinz__
 
Posts: 17
Joined: Sat Jan 16, 2016 3:54 am

Re: [PN532 NFC breakout] Cabling to use I2c?

Post by __Vinz__ »

Hi Mike,

I have unplugged the breakout board and after plugging in 2k2 resistors between SCA/SCL and the 3.3V rail and powering on the Arduino, I measured 3.3-3.2V on these lines. You were right to mention the open drain design, meaning SDA/SCL do not drive the line high, rather only pull it down. When not pulling it down, the pullup resistor pulls it up. If I plug the 2K2 resistors using the 3.3V rail, this is the voltage used since, as I understand it, those resistors take precedence over the Arduino internal pullups (20k). If I were to use the internal pullups (which IIRC the Wire library enables), they would pull the line up to 5V instead. Am I right?

I then proceeded to plug in the breakout board and the readMifare sample sketch works perfectly fine!

Many, many thanks for your continued assistance! I think this information would benefit tremendously on the tutorial page for newbies like me trying to make the board work in I2C mode. The tutorial is a little bit misleading since it says to use the resistors 'and then connect the breakout as you normally would.', which to me, referred to the SPI way (with the shifter). That should be changed I think + some info about external vs internal pullups added. I found that Sparkfun forum useful in that regard. Hopefully, this is useful to others as well.

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: [PN532 NFC breakout] Cabling to use I2c?

Post by adafruit_support_mike »

__Vinz__ wrote:If I plug the 2K2 resistors using the 3.3V rail, this is the voltage used since, as I understand it, those resistors take precedence over the Arduino internal pullups (20k)
Not quite. The 20k pull-ups to 5v are still there, but they form a voltage divider with the 2.2k pull-ups to 3.3v.

In a 2.2k-20k voltage divider, the voltage across the 2.2k will be 2.2/(2.2+20) or about 10% of the voltage between the ends. The difference between 5v and 3v is 2v, so 10% of that would be about 200mV. The 20k pull-up to 5v pulls the voltage up from 3v to about 3.2v. That's still within the PN532's safe zone.
__Vinz__ wrote:If I were to use the internal pullups (which IIRC the Wire library enables), they would pull the line up to 5V instead. Am I right?
If you only used the 5v pull-ups, yes.
__Vinz__ wrote:I then proceeded to plug in the breakout board and the readMifare sample sketch works perfectly fine!
Glad to hear it's working for you. Happy hacking!

User avatar
__Vinz__
 
Posts: 17
Joined: Sat Jan 16, 2016 3:54 am

Re: [PN532 NFC breakout] Cabling to use I2c?

Post by __Vinz__ »

Thanks Mike for the additional explanations! I am marking the thread as solved accordingly.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”