Notifications
Clear all

[Solved] Advice on debugging: i2c drops when switching to external power

53 Posts
4 Users
8 Likes
449 Views
AllocsB
(@allocsb)
Member
Joined: 1 month ago
Posts: 11
Topic starter  

Greetings,

I am looking for help using the pn532 NFC card reader in a project. I have been having more trouble communicating with it than I've expected.

It seems that the pn532 only enumerates under i2c for me when it's connected to the pi's 3.3v source. This is a problem because this repository advises users to supply external power or else suffer a spotty connection. I'm using the power supply from this electronics kit with a 1.5A adapter. Here's a simple comparison of the pn532 enumerating over the rpi's power and not doing so over external power. In both cases the status LED on the device turns on.

Spoiler
i2cdetect -y 1 # rpi / internal power
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- 24 -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
Spoiler
i2cdetect -y 1 # external power
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         

Generally I am pretty confused about why the reader would stop working with external power. Am I just using a garbage power supply and this is what I should expect? More generally, how can I debug / rule out such power issues like this in the future?

Thank you

Extra info:

I am communicating with it via Raspberry Pi 4B rev 1.2 on RPi OS (Linux).

The device's operating range is 2.7v - 5v


   
Quote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7001
 

@allocsb The general rule is to NOT power much of anything via pins on an MPU/MCU. There are devices that only sip power and will work, but as a general rule it is ill advised.

I can't tell for sure, but my gut feel is the device will be more stable using a 5V supply as opposed to 3.3V. Yes both are 'in-range', but my experience is that I have less trouble when I choose the high end of the range.

Without the same setup to test, these are just my best guesses based on experience and a quick look at the data sheet.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1122
 

@allocsb  When the card reader is externally powered are you connecting the ground of the reader and rpi together?


   
ReplyQuote
AllocsB
(@allocsb)
Member
Joined: 1 month ago
Posts: 11
Topic starter  

Thanks for the responses everyone!

@zander That makes sense. This supply has a 5V mode so I tried switching to that with the same result unfortunately.

@byron I'm not connecting the grounds. Should I be?

I'm just wiring the supply's power and ground to the reader directly. I don't think I can upload pictures here yet so here's a link to my google drive with my setup.

https://drive.google.com/file/d/1D-XioecOhomjSbXFjtA2j_-s6RotGIjV/view


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1691
 

Hi @allocsb,

   I think your best way forward is to post a sketch of your connections. This is a similar, though more extensive request, to that made by @byron (Hand drawn sketch is fine.)

I am not familiar with the specific product, but I don't mind doing a little data sheet digging, when I know exactly what you are connecting up. So, please provide links to the NFC card reader data sheet and any other bits beyond the R-Pi.

Note, most such devices are often sold on PCBs, which are widely available, but not always identical. So please indicate the particular source and version you have.

Also, if you are using an available project design, such as the excellent ones provided by Bill (@dronebot-workshop), or others, please provide the reference, together with a description as to how your circuit is the same or different.

-----------------

Sorry to contradict you Ron (@zander), but my 'gut feeling' does not agree with yours.

I am concerned that 5V supply might indirectly damage the R-Pi. However, until I have the circuit details, I can't be sure, as sometimes circuits provide appropriate interfacing.

Hence, my advice at the moment to @allocsb is to provide as much information as possible, before doing any changes. Hopefully, someone on the forum will be able to assist.

------------------

Best wishes, Dave


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7001
 

@davee He provided a link to the data sheet, that is how I got it. As I said I am using experience and gut so like many other sensors or devices meant to connect to a Pi that I have used the 5V is isolated from the Pi so no worries there.

I just looked at the data sheet again, and I am still fairly sure, but of course I will defer to your abilities to get every last bit of trivial information from a datasheet.

If you can't spot the link, try this https://www.nxp.com/docs/en/nxp/data-sheets/PN532_C1.pdf

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
AllocsB
(@allocsb)
Member
Joined: 1 month ago
Posts: 11
Topic starter  

@davee Here's a basic Fritzing diagram. I've also taken a picture of my physical setup in my last post.

Image: https://drive.google.com/file/d/1xTYxqFmFFlYoMV9vzAxUnCe9hXroPjG9/view?usp=sharing

Fritzing file: https://drive.google.com/file/d/1BMgOftImfiR_tY-RnQURSeGDLMZdKKm9/view?usp=sharing

Posted by: @davee

So please indicate the particular source and version you have.

I bought it off of amazon (link). I may be able to pull a version number from it if I can start sending it commands.

Thank you


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1691
 

Hi Ron @zander,

The potential problem is the 5V supply may (accidentally) get to the R-Pi GPIO pins.

And, knowing that R-Pi 4s do not come cheap, I think it is better to see the whole picture first, so we can try to minimise the risk.

------------

Without knowing the actual board circuit/specification the NFC device is fixed on, I can't tell what the interfacing situation is. Just looking at the chip datasheet is only half the story.

I can see that the chip includes an LDO voltage regulator, so that it can be supplied by a battery or other supply at 5V, but it is vital to ensure this supply voltage can never get to the R-Pi.

The data sheet also suggests that it accept a range of power voltages from 2.7V to 5.5V. IF it will work with 3.3V, then I would feel happier suggesting a solution on that basis, as a small error is less likely to destroy the R-Pi.

But without looking at the board design details, I can't advise how to connect it.

You may have a valid point in suggesting the NFC board may need more power than an R-PI can 'donate', but this needs carefully checking out before wiring up, as a mistake may destroy the R-PI processor.

Sorry, if you feel I am being over-cautious, but I prefer to be that way.

Best wishes, Dave


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7001
 

@davee @allocsb Absolutely, be cautious. I did look at the block diagram and it looks well isolated, but didn't he say it worked at 3.3V powered from the Pi, it was when he switched to the breadboard power supply that it didn't. I am confused, and besides he is one of your people, and he uses words I don't understand like enumerate, isn't that some sort of math word? I will leave you two engineers to figure it out, I have a garden to plant tomorrow.

OOPS, forgot to mention, make sure all the grounds are connected together.

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7001
 

@allocsb YES, connect the grounds. That was mentioned by a couple of us.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1691
 

Hi @allocsb,

  Thank you for your reply.

   I have just started to look at this, as I have other things to do as well, but my initial impressions, which may be mistaken, are suggesting this needs handling rather carefully.

I should say, I don't have an R-PI 4, nor the NFC board you referenced, so I am relying on what I can Google, etc., but the first words I can read suggest they are not directly compatible as I2C. That is not to say there are not methods to deal with this situation, but I would prefer to clarify the situation, before rushing into solutions, as I fear that not all that I can see printed is both unambiguous and accurate.

-----------------------------------

I am also concerned with the Fritzing system you are showing. The first link, I can see directly, which is ok, but the other entry seems to require me to share my Google Drive details with a third party, before it will let me see more than a list of filenames. Sorry, but when it is with companies I have never heard of, that makes me rather nervous. Could you please arrange a different mechanism to share information that is less intrusive?

------------------------------------

Initial impressions:

The Fritzing diagram I can see appears to show a power source, presumed to be 5V (??), connected to the NFC board, and two wires connecting SDA & SCL pins of NFC board to SDA & SCL pins of R-Pi.

There is no mention of how the R-Pi is powered, or how the R-Pi ground (0V) is connected to the ground (0V) of the NFC board. The 0V (grounds) must be connected for I2C or SPI to work.

------------------

The photos in the Amazon advert you pointed to shows the NFC board is ELECHOUSE + NFC MODULE V3
------------------------------
Elechouse manual for the board is at

https://www.elechouse.com/elechouse/images/product/PN532_module_V3/PN532_%20Manual_V3.pdf

----------------------------

The PN532 data sheet says:

8.3.1.2 Configuration modes of the host interface pins.
In I 2 C mode, P50_SCL and SDA are configured in Open Drain mode.
In HSU mode, HSU_RX is in input mode and HSU_TX is in push-pull mode.
In SPI mode, NSS, MOSI and SCK are in inputs mode. MISO is in push-pull mode.

An Open drain output means the chip's transistors can only pull down to 0V. The interface requires a pull up resistor to show a 'signal'. Tracking down the one or more resistors in an I2C system can be tricky if the documentation is sparse or unfriendly. The danger is that there will be a pull up to 5V in one place (e.g. on the NFC board) which gets connected to an 3.3V pin on another board (e.g. the R-Pi).

HSU mode, which appears to be the same as 'UART', and SPI both seem to actively drive the same pins.

The Amazon advert for the board says:

"Standard 5V TTL for I2C and UART, 3.3V TTL SPI"

which suggests it expects to be 5V levels for both I2C and HSU/UART modes.

So if the board is connected to an R-Pi, HSU/UART mode might damage the R-Pi, and I2C seems to have a mismatch, and possibly be a danger to the R-PI (if there are any pull ups to 5v).

Whether this mismatch and/or danger exists, is what I am still trying to track down.

------

So far, I am not convinced either way on this point, but it is not a good omen.

Unfortunately, all of the examples I have seen so far, have used 5V Arduinos, for which the point would be moot.

----------------

I can imagine that generic tools for searching out I2C interfaces wil be available for R-Pi s, but do you have software libraries etc. to actually use the NFC, or are you aiming to do the whole software design from scratch?

Did you choose to start with an R-Pi when the board seems to have been aimed at the Arduino market?

----------------

I'll take a break now, and aim to continue this story in another message.

Best wishes, Dave


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7001
 

@davee @allocsb Just a quick couple of observations. The first diagram has the power supply ground connected to VCC on the board and power supply VCC to ground. I am sure that is just a drawing error, AFAIK most engineers know the difference between + and - LOL 🤣 

I also see it's an Adafruit board and I see 3.3V and ADJ printed on the power supply board.

I see no power to the Pi but it could come via USB.

Most importantly, the ground on the Pi is not connected to the ground on the sensor board.

I had a look on the Adafruit site and found the following. It appears to be a 3.3V - 5V selectable supply like the 6 I have in a drawer. https://www.adafruit.com/product/184

Screenshot 2024 04 16 at 10.50.42

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1691
 

Hi Ron @zander (& @allocsb),

  Well spotted on the diagram about the wires crossing over ... I was looking at the screen image on my elderly laptop, and I can only just read the printing. As you say, that is clearly a 'visual typo', rather than a conceptual mistake.

Embarrassingly, I didn't recognise the power supply board .. I too, have one in the spares box, but have never used it - it came in a 'bumper pack' of stuff I bought a long time ago. On mine, the voltage is jumper selectable between 3.3V and 5V. Given the general descriptions I saw about the NFC board on the web, plus some of the discussion above, I 'assumed' that connecting it to a 5V supply would occur.

I did of course realise the R-Pi may be connected via USB, but as you point out, that means 0V may well be floating, with respect to any other supply.

It is indeed essential that the 0V of the two supplies are joined for I2C (Or SPI or UART) to work.

Whilst some projects, such as an Arduino controlling a substantial motor, multiple supplies are almost inevitable, but when it is something like an Arduino connecting to a sensor, the situation is a lot simpler when only one supply is involved. However, there are enough aspects to fill a book of sermons in this area, so I'll leave it that for now.

Best wishes, Dave


   
Ron reacted
ReplyQuote
AllocsB
(@allocsb)
Member
Joined: 1 month ago
Posts: 11
Topic starter  

Posted by: @davee

I can imagine that generic tools for searching out I2C interfaces wil be available for R-Pi s

That is what the i2cdetect commands from my first post are depicting. The 24 is the response of the pn532 when it's connected to the Pi's power. That is also just a Linux command, not specific to just RPi's.
Posted by: @davee

do you have software libraries etc. to actually use the NFC, or are you aiming to do the whole software design from scratch?

Though it would be fun I'm not going to be writing any of my own software for driving the NFC reader if I can help it. When the pn532 is connected to Pi power it can actually already perform toy interactions over i2c (guide). Here is an NFC card being read. Obviously if it only works over Pi power that's cause for concern though.

pi@pokepi:~/code/nfc/py $ nfc-poll
nfc-poll uses libnfc 1.8.0
NFC reader: PN532 over I2C opened
NFC device will poll during 36000 ms (20 pollings of 300 ms for 6 modulations)
ISO/IEC 14443A (106 kbps) target:
ATQA (SENS_RES): 00 44
UID (NFCID1): 04 5a cf 42 68 19 91
SAK (SEL_RES): 00
Waiting for card removing...nfc_initiator_target_is_present: Target Released
done.

On top of that I will of course be writing my own software to use the NFC cards.

Posted by: @davee

Did you choose to start with an R-Pi when the board seems to have been aimed at the Arduino market?

Apart from nfc-poll there are linux based libraries for this chip. For instance, this library specifically appears to picture the Elechouse board that I'm using. I was torn between going to them or here first for help; I felt that for a problem even connecting the device to my Pi it may have been inappropriate to log an issue against their library. I do have an Arduino that I can use to help test this but I didn't think I would run into such big issues with this. As you said, I feel like like it's quite a "bad omen" if I can't even get i2c to communicate with my device, let alone do anything.
Posted by: @zander

The first diagram has the power supply ground connected to VCC on the board and power supply VCC to ground

Whoops! 🙂
Posted by: @zander

I see no power to the Pi but it could come via USB.

The Pi is powered with this (I believe officially supported) wall adapter
Posted by: @zander

I have a garden to plant tomorrow.

Sounds fun!

---------------------------------------------------
---------------------------------------------------
---------------------------------------------------

Ok, now that I'm done responding, it seems like the first cause of concern is the lack of combined grounds. Here's a new Fritzing with what I intend to try. Can someone give the go-ahead?

 

pn532 1713288451

 

File:

Aside from that I will be going through the rest of @davee's advice more closely today. In general I'm pretty surprised by the amount of difference you're pointing out that devices can have even among interfaces that I considered standard like i2c but your points are pretty clear so I just have to do the research now 🙂


   
ReplyQuote
AllocsB
(@allocsb)
Member
Joined: 1 month ago
Posts: 11
Topic starter  

Have some instant gratification, here I am reading a tag, just not with external power 🙂

 


   
ReplyQuote
Page 1 / 4