Notifications
Clear all

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

53 Posts
4 Users
8 Reactions
540 Views
(@davee)
Member
Joined: 3 years ago
Posts: 1725
 

Hi @allocsb,

   I am pleased to see you have had some progress.

Having figured out how your PCN532 board is wired, albeit by a mixture of looking at the photos, and guessing, I think I have also tracked down a circuit diagram from another supplier. Of course, there maybe other differences, but hopefully they are close enough to confirm my guesses regarding the I2C interface.

Obviously, a guess is just that ... so if you find some definitive evidence to contradict what I am about to say, I will be 'surprised', but at this moment, a guess is the best I can offer, and I apologise in advance for any confusion.

-----

Recapping the position, and introducing new evidence:

  • R-Pi 4 (and its close relatives) are all 3.3V logic devices ... they may be powered from a 5V source, usually via a USB socket, but that 5V is promptly reduced to 3.3V to drive microcontroller, etc., so putting above 3.3V (e.g. 5V) on to any of the GPIO pins (and others) , risks destroying the device. Under some circumstances, the R-Pi may survive a 'small' voltage overdrive, but it will almost certainly be overstressing it, and premature failure may occur at any time.
  •  
  • The PN532 chip that does 99% of the work on the NFC board you have acquired, is also 'essentially' a 3.3V device, in that its pins for connections to microcontrollers, and its internal logic are all based around 3.3V. The major 'exception' to this rule is that it was designed to be usable when powered from a battery, which might be up to 5.5V, so to save the board designer adding an external voltage regulator, there is one built-in to the chip, which simply accepts voltages up to 5.5V and reduces it to 3.3V, which is then available to power the rest of the chip.
  •  
  • IF the board manufacturer had simply put the PCN532 chip on the board, and provided accessible pins for connections, it would have matched up to R-Pi s, ESP32s and many other development boards without a problem. However .... (and this is where my guesses started)
  •  
  • In the case of the SPI interface, I think the accessible pins (MISO & MOSI), etc. for the external connections probably go directly to the PCN532, so that these pins are '3.3V logic'. (There maybe small additional parts in the intervening circuit, like low value resistors, but these do not affect the voltages present.) Hence in the board description, it says SPI is 3.3V logic levels.
  •  
  • But I note the I2C (and probably the UART) uses a group of 4 pins on a different side of the board:
  • image
  • And the there is small 6 pin chip beside it, plus there is VCC and GND pins. So here, I am guessing that this chip is a 'logic level converter', and it is intended to convert the 3.3V logic data into 5V logic data ... which is great for an Arduino UNO but not an R-Pi!!! Of course, I can't see a part number on the chip, nor are the photos sufficient to track the wiring, so I could be wrong!
  • I also note that there are two pins on the board labelled VCC ... from the circuit diagram about to be introduced, these are intended for (about) 5V in, whilst most of the circuit will use a VCC 3.3 V supply, provided by the PCN532 voltage regulator.
  •  
  • The circuit I found comes from a manual at https://osoyoo.com/2017/07/19/pn532-nfc-rfid-module-for-arduino/
  •  
  • And the circuit is:
  • image
  • This part shows the logic level converter, which is almost the only part of the circuit that is powered by an incoming VCC at 5V. The other connections go to the voltage regulator input of the PCN532 chip, and the reset pin, via a potential divider to reduce the chip sees on that pin to 3.3V
  • image
  • Note the MISO/MOSI pins for SPI go straight to chip, not via the logic level converter.

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

So where do you go from here?

Late edit: I have just realised your recent test was powering the PCN with 5V from the R-Pi, not via the separate power board. Using the separate power board Fritzing circuit you showed, also ensure you have

1/ Linked the GND connection between the "3.3V power to PCN532 board" to one of the GND pins on the RPi connector

2/ and ensured the power supply output is set to 3.3V.

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

The first thing is to ensure the power going to the VCC pin on the PCN532 board is 3.3V, NOT 5V. The power supply board you have, can probably choose between 3.3V and 5V. Use a voltmeter to double check as well!

If this voltage is 3.3V, then the logic connections (SDA/SCK) to the R-Pi cannot exceed 3.3V, so the R-Pi is 'safe'.

And if the test in your video can be repeated with 3.3V supply to the board, then hopefully you can continue to use it in this form, even though there is an unnecessary 'logic level converter' in the path.

---

If you are lucky, it will continue working at 3.3V ...

         but if it stops working when the voltage is reduced to 3.3V, then we need to figure out the best way of removing that converter.

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

It's late now for me, so once again, I am stopping for a break. Please have a read through this, and report back whether it works with the power set to 3.3V or not.

Obviously, include any questions or queries.

If it looks like the converter needs to be removed, please indicate whether you are confident about modifying the board by soldering, etc.

----------

Best wishes and good luck, Dave


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

@davee Excellent sleuthing as usual Dave, but unless I missed it how does this help explain why the setup does not work with an external power supply.

If I am remembering correctly, the common ground may have been missing in all the tests up until the most recent so perhaps another test with an external power supply might work now.

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.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


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

Hi Ron @zander,

   Lack of a common ground would almost certainly stop I2C working ... it is indeed plausible, but I can't be sure if it applies in this case, as I don't have direct visibility of the hardware.

I did not do the 'sleuthing' to try to prove or disprove the specific grounding point, but rather because I suspected, it was not the only problem. Had I thought grounding was the only problem, I would not have taken any interest, as @byron had already raised the issue.

 My thoughts agreed with Byron that the grounds needed to be joined, but I did not want to just endorse the point in public, without first looking into the possibility of driving 5V into R-Pi GPIOs, as ironically, leaving the grounds disconnected, would (probably) have prevented the R-Pi GPIOs actually experiencing the 5V, so they would have been 'protected' from possible damage, even though the I2C communications could not function.

--------

As I have described and mentioned before, in several different threads, grounding issues (and other issues) can become quite complicated when there is more than one power source, and can catch out 'professionals' as well as amateurs. Hence, whilst some projects (with high power loads, like substantial motors), obviously require two or more sources, I usually view multiple sources as something to be avoided if possible, on account of the extra complexity and opportunities for errors involved.

Best wishes, Dave


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

@davee That would be ironic if the lack of proper grounding saved the Pi from destruction.

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.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


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

@davee @allocsb This is going to sound confusing. Not being argumentative, just my observations and noting what appear to be inconsistencies.

Dave, I am not sure if you mis-spoke or did not see the diagrams, but both the I2C JP1 4 pin hdr and the SPI J2 CON8 are labelled VCC5V

I am sure you looked at the datasheet for the PN532/CN and saw that 5V is required on both pin 40 as input to the LDO that then feeds several 3.3V pins, and pin 38 via a voltage divider to put 3.3V on what appears to be a reset/power down pin. I do not see any other use of 5V. The power description part of the datasheet shows how the LDO output fans out to several other rails.

The problem is I at least have not seen the connections between the PN532/CN and the carrier board. If the OSOYOO board spec is indeed the same as the OP's board, then I am confident that VCC is meant to be 5V.

I think this is the OP's board https://www.elechouse.com/product/pn532-nfc-rfid-module-v4/

and it says VCC can be 3.3 to 5V in one place, and everywhere else it says 5V. Maybe I am misremembering, but if I put 3.3V into an LDO I will get LESS than 3.3V out.

  1. On-board level shifter, Standard 5V TTL for I2C and UART, 3.3V TTL SPI

NOTE in the above it says 5V for I2C.

My recommendation is try an external power supply of 3.3V and test. If it works then you are done, if it doesn't, then try 5V. It is clear to me at least that using 5V on either the I2C hdr or the SPI hdr (labelled VCC) is safe.

 

I propose the following as the direct answer to OPs original query.

The external power must have been just a bit less than 3.3V at times resulting in inconsistent results. Changing that to 5V will fix the problem, or indeed something like 3.5V if you have an adjustable external supply.

I forgot, here is the manual

 

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.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
AllocsB
(@allocsb)
Member
Joined: 2 months ago
Posts: 11
Topic starter  

It seems that connecting the grounds solved the issue! I will report back later today with some more information when I have some more time but just wanted to put everyone's curiosity to rest. Thank you for the assistance!


   
Ron reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7140
 

@allocsb Do you have 5V or 3.3V on the VCC pin?

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.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
AllocsB
(@allocsb)
Member
Joined: 2 months ago
Posts: 11
Topic starter  

@zander 3.3v


   
Ron reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7140
 

@allocsb External?

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.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
AllocsB
(@allocsb)
Member
Joined: 2 months ago
Posts: 11
Topic starter  

@zander Yes. The same as the Fritzing diagram I've posted. 3.3v external with connected ground over i2c.


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

@allocsb Great. Keep an eye on it, the VCC pins are labelled as 5V and connect to an LDO that coverts 5V to 3.3V. If your external is actually only 3.3V it may not work well, it needs to be a bit higher but I forget how much. If you start to get sporadic results, at least up it to 3.5 or so if you don't want to go all the way to 5V. I am attaching a screen grab from the manual for your board.

Screenshot 2024 04 17 at 15.41.24

 

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.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


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

Hi Ron @zander (and copied to @allocsb for information)

  Sorry Ron, there is no easy way to say this, but I think you are completely misunderstanding, and hence misleading @allocsb, with regard to the acceptable voltage supply for the PCN532 board he has. In short, supplying a voltage higher than 3.3V puts the R-Pi at risk of failure, if the R-Pi GPIO pins are connected to the SCL and SDA pins.

I think you are trying to fix an unfortunate PCB design decision, by applying a second mistaken change. The old saying 'Two wrongs do not make a right' comes to mind.

Your arguments about the VCC markings on the PCB also have flaws. This is a maximum voltage indication, not an acceptable range specification. More importantly, just because 5V to 5.5V may be fine for the chips on this board, that does not mean they do not have the potential to fry chips on other boards, like R-Pi s!!

Of course, if @allocsb could use the SPI interface, this issue would 'disappear'.

The risk of applying too high a voltage to the R-Pi interface pins is impossible to quantify. 'Evidence' that it has been tried, and not apparently damaged the chip, is misleading. Nearly all signal pins of chips have 'hidden' diodes connected to them to reduce the chance of damage by static electricity during handling. These diodes are only intended for the very brief charge flows caused by static electricity, but they will try to 'absorb' any other voltages outside of the 'Gnd to VCC' range, which for a chip like the R-Pi microcontroller will be 0V to 3.3V when it is powered. Depending on how much current flows, these diodes can be damaged in a number of ways. In some cases, the damage will be obvious, such as short to ground, but other times it results in leakage currents, open circuit pins, removal of static protection and so on. In some cases, there is also collateral damage to the device near to the diode area, including breaks and shorts to the interconnecting aluminium. In many cases, only a microscope view of the chip will reveal the immediate damage, but the device may then completely fail in the future.

Hence, the basic rule is to ensure the pin is never driven outside of the specified range.

From the R-Pi datasheet: https://datasheets.raspberrypi.com/rpi4/raspberry-pi-4-datasheet.pdf

image

-----------

The simple problem is that this PN532 circuit board design is not intended for, and is "unsuitable" for connection to microcontrollers like R-Pi and ESP32, via either the I2C or UART interface, because it is producing 5V logic levels, and these microcontrollers are only compatible with 3.3V logic levels. It says this in the adverts, including the Amazon listing, albeit in a rather 'quiet' fashion that is easily overlooked.

The simple answer is to advise @allocsb to change direction, such as find another board or use the SPI interface, but knowing forum members are usually spending their own money, etc., I have been trying to find a compromise ... but I don't accept compromises that I believe put other components at risk, especially if they are relatively expensive, like R-Pi 4s.

-----

I haven't done a 'full market survey', but this PN532 board design is the only one I found using the PN532 chip, that inserts a 'logic level converter' into the I2C interface lines. Others, like Adafruit's pn532 board, simply output the 3.3V logic levels provided by the PN532 chip, which would be fine.

Also, this board should be fine it the user adopts the SPI interface, using the MOSI and MSIO pins, as they too are 3.3 logic.

The schematic I found is dated 2017, when microcontrollers from Arduino were 5V logic type, and the PN532 chip would have required a 'logic level conversion' to connect to it ... so a designer 'thoughtfully' included it on the board for the I2C interface. Unfortunately, they did not foresee that all 'new' microcontrollers were soon going to move to 3.3V, and hence they omitted to provide an easy way of avoiding the voltage converter.

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

Contrary to suggestions, the PN532 chip is specified to work over a wide voltage input range -

image

On this basis, I see no reason to supply it with more than 3.3V. (Obviously, the part of the range below 3.3V is too low to meet the R-PI logic level requirements, and hence is not relevant.)

The only problem is the external 'logic voltage level converter', which is creating the risk to the R-Pi!!

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

I realise LDO regulators normally have a small voltage drop, and in more conventional situations, the input voltage will be arranged to be a little above the regulated output voltage. However, the combination of the external 'logic level converter' and the R-PI absolute requirement of keeping below 3.3V makes this a practical impossibility. (This is not a 'conventional' situation for a voltage regulator.)

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

I haven't had time to analyse how much the 'logic level converter' will attenuate the I2C signal, if it is only supplied with 3.3V. Hence, I suggested trying that, as it will not harm the R-Pi or the PN532 board, and it might actually work. Hence, a very simple fix, if it works!

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

If that doesn't work, an alternate solution is required.

It is possible, though 'balmy', to try putting an external logic level converter in the path, to undo the problem the first one is causing. I only mention it, because I think someone will. It is a very ugly 'solution' and I don't know if it will work.

The bidirectional 1 FET per line converter, that Philips originated, is 'rather clever', but this 'cleverness' can easily catch out engineers who do not carefully analyse its mechanism and characteristics.

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

The more sensible, though inconvenient, solution, is to do some simple 'surgery' to the board. I haven't yet looked at the easiest physical approach to doing that, as I haven't heard if @allocsb has soldering equipment and expertise available.

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

Concluding:

In agreement with what I wrote previously:

NEVER APPLY MORE THAN 3.3 V to the PN532 board, if you are using the I2C (or UART) interface to connect to R-PI GPIO pins.... unless you like replacing damaged R-Pi s ...

(and don't forget the grounds of two supplies need to be connected together.)

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

In the meantime, I'll wait to hear how you are getting on.

Best wishes and good luck all, Dave


   
ReplyQuote
AllocsB
(@allocsb)
Member
Joined: 2 months ago
Posts: 11
Topic starter  

@davee @zander

I enjoyed reading your discussion, I'm going to write down my takeaways and some more questions.

I have the V3 board:
https://www.elechouse.com/elechouse/images/product/PN532_module_V3/PN532_%20Manual_V3.pdf

It seems like the cause of some confusion is there is a logic level converter bringing the i2c/uart line to 5V coming out of the pn532 board, but which is not part of the pn532 itself. As @davee said, it was initially worth considering the voltages going into the pn532 and the pi, as they have different operating logic levels (3.3V) than an Arduino (5V) for which the Elechouse p532 board appeared to be designed. The board's datasheet says this:
• VCC: 3.3V~5V
• I2C/UART: 3.3V~24V TTL
• SPI: 3.3V TTL with 100 ohm resistors in series. It could be connected directly to 5V interface of microcontroller such as Arduino.

My impression is that this means the input voltage to the Elechouse pn532 board is 3.3V-5V by using a voltage regulator. As far as the logical levels for the I2C/UART/SPI, how could they provide the ranges listed?

Is it generally the case that voltage regulators are for power and logic level converters are for data?

The pn532 datasheet itself ( https://www.nxp.com/docs/en/nxp/data-sheets/PN532_C1.pdf) says the operating range is 2.7V to 5.5V, I'm sure there's more nuance to that regarding the difference pins and lines but I haven't found that yet. In the mean time, as @zander said, pin 3 of the JP1 line is called VCC5V. I am assuming that's just a "recommendation" or default since the range actual is listed elsewhere?

Posted by: @zander

If you start to get sporadic results, at least up it to 3.5 or so if you don't want to go all the way to 5V. I am attaching a screen grab from the manual for your board.

Any suggestions for trying this? Power supply or voltage regulator ic?

Finally, I'm still a little confused about what exactly differentiates i2c/uart from spi in terms of logic level on the actual pn532 device but I'll leave that for now.

Thanks


   
Ron reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7140
 

@davee @allocsb I looked at the datasheet I think you provided. I read most of it including the power section. 5V goes into an LDO and 3.3V comes out to be distributed to several 'rails'. The 5V goes NOWHERE else. Backing that up the pins are clearly labelled VCC5

One of the outputs of the LDO is VDD and that is the host interface voltage.

The following pages may be of interest. pg 6, 10, 84 and 85. Those pages show the LDO and power management. They also show the isolated HOST interface.

As the OP also just pointed out the manual for the board says 3.3 to 5.

On page

Maybe the OP would consent to disconnecting the SCL and SDA wires then apply 5VDC to the VCC pin and measure the voltage on the SDA and SCL pins.

Page 85 answers my question as to how the LDO could work at 3.3V. Here is the answer.

The regulator is used to reduce the VBAT voltage to the typical voltage rating of the PN532. It acts as a 3.0 V linear regulator with resistive feed-back, as long as the VBAT voltage is above 3.4 V. It is designed to cope with a maximum fluctuation of 400 mV on the VBAT line (due to voltage bursts exhibited by the battery).

If VBAT falls below 3.4 V, the output of the regulator tracks VBAT with a variable delta. It continues to reject any noise on the VBAT line via the use of an internal band-gap reference.

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.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


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

@davee @allocsb I think it's time to remind everyone of the original issue.

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.

Now here is the info at 'this'

The Raspberry Pi 3.3v regulator does not provide enough current to drive the PN532 chip. If you try to run the PN532 off your Raspberry Pi it will reset randomly and may not respond to commands. Instead you will need another power source (3.3v) to power the PN532. Some people have been able to run the PN532 off of the 5V rail of the raspberry pi but this is not the recommended way of powering it.

 

NOTE: The author said the Pi 3.3V was NOT adequate so either use an external 3.3V (recommended) OR you can use the Pi 5VDC but it is not recommended. I read that to mean 5V is ok, but the Pi isn't a good choice of PSU.

That answer was there since post 1. I for one am embarrassed I missed it, but all the other info I looked at and posted about was correct and in agreement with that.

Problem solved.

 

 

 

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.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Page 2 / 4