Notifications
Clear all

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

53 Posts
4 Users
8 Likes
454 Views
(@davee)
Member
Joined: 3 years ago
Posts: 1694
 

Hi @allocsb,

  I'll just pick out one point, and include a little 'history', which may help you to understand the reason for some of the problems we now see, with your board, and many others. I hope it is not too boring.

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

Voltage regulators are, indeed, generally for power. There are countless chips, boards and designs for just this very purpose, as it is almost a universal requirement, and modern chips have made it very cheap in many cases.

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

'Logic level converters' are a bit more 'contrived'. If you are a 'professional' electronics unit designer, then to make your life easy, whilst maximising the chance of units working reliably, when you design a 'new' unit, then you are likely to choose chips that are 'roughly' the same era, and have been designed to 'plug and play' together, with minimal extra 'glue'.

----

At the end of the 1960s, Texas Instruments introduced a range of 5V 'TTL' logic chips, which fitted this 'plug and play' model exactly. e.g. the SN7400, chip provided 4 NAND gates, which could be directly connected (using a little care), to every other SN74xxxx chip in the range. These chips were so successful, not only did they develop into new families for TI as technology progressed, but also a lot of competitors produced their own, usually compatible, families of chips, with similar numbering (except for the 'SN' prefix).

e.g. A few years later, a new TI suite appeared, which used less power ... starting with the SN74LS00. With a little more care, it is possible to mix and match SN74LSxxxx chips, with SN74xxxx chips, as their voltage levels are basically the same.

However, subsequent families sometimes diverged rather more. e.g. SN74HC00 and SN74HCT00 will both work with a 5V supply, but the whilst the 'decision changeover' voltages between high and low levels for a SN74HCT00 approximately match the old SN7400, the SN74HC00 will accept power voltages of 2V to 6V, with the 'changeover' voltages being "roughly" half the present power voltage, rather than fixed values. Hence, mixing SN74HCxxxx and SN74HCTxxxx chips in the same circuit is likely to be a real headache, which is best avoided!

Sometimes, the designer may have no choice; perhaps an old board design must be interfaced to a new board, so various 'converters' have appeared over the years, to allow the 'old' and 'new' worlds to talk to each other. Some converters have been specific chips, whilst others 'custom' designed from transistors, resistors, etc. as required.

-----------

A specific example of this applies to the I2C bus design. I2C originated in the early 1970s (?), from Philips, who wanted a very simple and cheap network bus to link the dozen or so chips needed to make a colour television. At this time, they specified a 5V bus, which matched the logic voltage from TI, etc. They also made provision for competitors to adopt the bus design, so it became 'ubiquitous'.

Subsequently, I2C has grown massively in scope, far beyond Colour TVs, whilst logic chips have drifted into lower voltages, with 3.3V the most common choice. Obviously, more modern chips with I2C have also moved to 3.3V. This prompted Philips to publish a paper, which shows how to link a 5V I2C bus to a 3.3V I2C bus, using just 1 MOSFET and a resistor, for each of the SDA and SCK lines. A particularly 'cute' aspect of this converter design, is that it is, automatically, bidirectional. That is, at one moment, a 5V I2C chip could be sending a packet to a 3.3V I2C chip, and then the next packet might be sent in the reverse direction.

-------

The PN532 is essentially a 3.3V logic chip, which includes 3.3V I2C and SPI buses. Philips presumably thought some of its customers would power it with a battery, so they included a 'handy' voltage regulator to convert a rather 'variable and unpredictable' voltage source of up to 5.5V, down to 3.3V to supply to the rest of the chip. In addition, the 'rest of the chip', will continue working when the available voltage is a bit less 3.3V ... they specify down to 2.7V. Thus, the I2C pins (and many others), will match up to a 3.3V I2C bus, without the need for any converters or other 'glue'. (If the voltage is slightly low, it will probably still work, but if it is a little too high, it may damage other units sharing the same bus.)

Thus, the PN532 chip will never present a higher voltage than 3.3V, which might damage other components also resident on the same bus.

Unfortunately, the PN532 board manufacturer you chose, seems to have thought the 'likely' I2C bus it would need to connect to would be the older 5V version, which may have been a reasonable thought at the time, but is now out of date. So a 3.3V to 5V logic converter was added to the I2C output ... and introduced problems for you.

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

I hope that helps to see a little of the background, and wasn't too tedious.

I wish you luck with your project ... we may not have quite 'solved' all of the issues yet, but understanding the problem is often more than 50% of the total work required to overcome it.

It is not unusual in electronics for someone to think they have 'solved' a problem, by discovering a 'workaround', which hides, but does not fix the problem. Sometimes, the workaround is enough, but commonly the original problem reappears in new guise, sometime later. Hence, I always try to discover the 'real' cause, even though it can make the job harder and more frustrating at the time.

Best wishes, Dave


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

@davee @allocsb But this board immediately converts 5V to 3.3V and the 5V is never seen again. Did you look at the pages I mentioned as well as the User Manual?

In addition, the library developer said the Pi can power the board from either the 3.3 or 5 but it performs poorly due to current demands so recommends the external supply.

 

Remember when Dave said this?

Late edit: I have just realised your recent test was powering the PCN with 5V from the R-Pi

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: 1694
 

Hi Ron @zander and @allocsb,

  Whilst I am not pretending all power supply issues are solved, I fear Ron, that you are introducing another misdirection, or at least complicating the way to finding a solution.

@allocsb said in his first message. "It seems that the pn532 only enumerates under i2c for me when it's connected to the pi's 3.3v source."

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.

In other words, his initial system was working when he used a single supply for both the R-Pi and the PN532 board.

My interpretation of this first message is that he had not actually seen a problem whilst taking power from his R-Pi at that point, but was understandably worried by the report on GitHub by others.

More importantly, his system 'stopped' working when he tried to use a separate power supply.

In other words, he had never seen the problems discussed on GitHub!!! That is not to say, he will never see them, just that it isn't the first and only issue to fix.

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

Having now spent days looking into this story, I suspect we have 3 issues to consider. They are not in order.

  1. Using the R-Pi as a 3.3V source is probably not a good idea. Looking at the data sheet shows the PN532 is generally a low current chip, but it takes a much greater 'gulp' of current to perform the RFID transmission. I am not clear on the timing/frequency of this gulp, but it is plausible that it only happens when commanded by the controlling processor. In which case, the simple I2C enumeration task, which was his 'test', would not have triggered this function, and the R-Pi power would have been sufficient.
    1. I agree power sufficiency is suspect, but we probably haven't got to the stage where it is affecting the problem diagnosis. I think we should hold fire before going down this rabbit hole.
  2. The likely reason that he could not get the external power supply to work was failing to connect the grounds. However, as I suspected from the start, and later demonstrated, connecting a 5V supply to the PN532 board puts the R-Pi at risk of damage to the GPIO ports. Leaving the ground unconnected would prevent the I2C bus working, but it would also save the R-Pi from damage. Hence, I suggested doing the research and analysis, BEFORE linking the grounds.
  3. The PN532 board is basically 'unsuitable' by design for connection to a 3.3V logic microcontroller, via the I2C bus pins, due to the 'logic volt converter'. It is plausible, but untested (and not yet analysed), as to whether sufficient 'signal' will get through the converter when the external side is powered at only 3.3V . This is easy to test and should not put the R-Pi at any risk of damage.

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

Hence, I have already suggested, and repeat here for clarity, the following steps in order that they should be performed:

  1. Power the PN532 with the separate 3.3V (NO MORE!!!!) supply, ensuring the ground from the 3.3V supply is linked to the ground connecting the R-Pi to the PN532.
    1. Repeat the enumeration test ... hopefully it will work, as I think it did when the R-PI was powering the PN532, as discussed in the first forum message
      1. If it does not work, move the power source back to the 3.3V RPi line, as per the first test, to prove nothing has been 'broken'.
    2. Report all findings so far, so we can discuss how to proceed.
  2. Consider and report from '1.' above. Depending upon findings, it may be necessary to modify the PN532, but I am hoping that will not be necessary.
  3. Review the power sources, to check if they can deliver enough current for the full functionality.

I hope that is all clear, at least to the point of achieving all of the first 'top level' step '1.' above

Best wishes and good luck, Dave


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

Hi Ron @zander,

  I looked at the board photo, and figured out the likely circuitry. Principally, I looked at the circuit diagram.

I also read the various board specs, including the Amazon one. All say 5V levels for the I2C port!!! In addition, note the manuals only show I2C connection to 'old' 5V Arduinos.

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

But this board immediately converts 5V to 3.3V and the 5V is never seen again.

This statement is half incorrect. The PN532 converts 5V to 3.3V, to power itself, but the incoming 5V also goes to the 'logic voltage converter' consisting of a pair of MOSFETs plus resistors, etc.

This converter will send a 5V logic signal out of the two I2C pins, SDA and SCK, and hence straight to two unsuspecting R-PI GPIOs, that may curl up and die at any time, if they have been connected to a 5V source.

Best wishes, Dave


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

@davee According to the library author there is no danger to the Pi by using the Pi 5V pin, it is just as not sufficient as the 3.3V pin.

The original problem was caused by the lack of proper grounding since reported by the OP.

Since the OP did try using the Pi5V supply (as you noted), I think we can agree that using 5V to supply the LDO is not a problem.

The VBAT 5VDC pin is the only mention of 5V on the chip and it only goes to the LDO that converts it to various 3.3V power rails. There is a second reference where a voltage divider 10/20 puts 3.3V on a Reset/PowerDown pin.

If there are others, kindly circle them on a schematic.

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: 7004
 

@davee We can ask the OP @allocsb but I am fairly sure that at one point as noted by you, he had both I2C pins plus ground to the Pi and VCC to 5VDC on the Pi.

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: 7004
 

@davee I do not see the following on the datasheet. Which page do you see it on?

but the incoming 5V also goes to the 'logic voltage converter' consisting of a pair of MOSFETs plus resistors, etc.

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: 1694
 

Hi Ron @zander,

  Sorry, it is stupidly late for me now. I am not sure if he did a test taking 5V power from R-Pi or that is a late night typo from me. Certainly, his first message says 3.3V, that was the 'sensible' first test, and I hope I made a simple typo -- I honestly can't remember!

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

Powering that PN532 board from 5V, with the I2C connections to the R-Pi, is not a good thing to do.

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

Please note, I am not saying that connecting a 5V I2C will always destroy an R-Pi or similar GPIO pin.

To me, it is like putting a new tyre on your car, and immediately hammering a nail into it. If the nail stays in place, it may keep the air in for a long time, but that tyre is compromised, and the nail could blow out at any time.

-----------

Best wishes, Dave   


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

Hi Ron @zander,

RE

@davee I do not see the following on the datasheet. Which page do you see it on?

but the incoming 5V also goes to the 'logic voltage converter' consisting of a pair of MOSFETs plus resistors, etc.

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

That is my description of what I can see, reading a circuit diagram. The circuit diagram is in the 'manual' for the board. I think I referenced it before, but in case

https://osoyoo.com/2017/07/19/pn532-nfc-rfid-module-for-arduino/

----------

Best wishes, Dave


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

@davee He started with Pi suplying 3.3v, then tried external power using a cheap PSU and it gave poor results so then he tried the Pi 5V pin as the library author said was possible but will suffer from the same problems as the 3.3V. You did see that and here is where you said that.

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. 

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: 1694
 

Hi Ron @zander,

  RE According to the library author there is no danger to the Pi by using the Pi 5V pin, it is just as not sufficient as the 3.3V pin.

This is totally out of context, since I don't know which 'Pi 5V Pin' is being referred to ... 5V power pin perhaps?

But if it is an R-Pi GPIO pin, then anything beyond 3.3V is risking damage. I am normally cautious about what I say, but that is a certainty.

I repeat, risking damage ... you may or may not see it.

Best wishes, Dave


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

Hi Ron @zander,

@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'. 

I think you are looking at the chip data sheet.

The problem 'logic voltage converter' is NOT part of the chip ... it is a 3rd party 'smart' additional parts on that particular PCB design.

Had the chosen board be one like provided by Adafruit, this would not have been a problem, as they didn't make it complicated.

Best wishes, Dave


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

@davee That is exactly the circuit diagram I am referring to. There is only two mentions of 5VDC,

pin 40 VBAT and pin  38 RSTPDN. I also note that both the I2C and SPI VCC pins are actually labelled VCC5V.

Although we can't see it, I assume that the VCC5V pins are internally connected to the pin 40.

You have also several times referred to something like an I2C logic converter out, but it is clearly labelled as VCC3.3V. Looking at the block diagrams, there is a HOST interface block, and the power block shows several 3.3V power 'rails' coming from the LDO.

I am not sure we are helping anyone anymore. The original problem is solved by the common ground. The debate over 5V or 3.3V is a bit of a sideshow. I see from several sources that either 3.3V or 5V is acceptable and you say only 3.3V.

The OP can easily prove it by simply removing the I2C wires from the Pi, connecting the board VCC to the Pi 5VDC and the board G to the Pi G as some have done and then measuring what voltage is on the board's I2C pins.

If @allocsb could do that there is no danger to either the Pi or board and it may be interesting to know for sure.

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: 7004
 

@davee Yes the Pi 5VDC power 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.
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: 7004
 

Posted by: @davee

Hi Ron @zander,

@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'. 

I think you are looking at the chip data sheet.

The problem 'logic voltage converter' is NOT part of the chip ... it is a 3rd party 'smart' additional parts on that particular PCB design.

Had the chosen board be one like provided by Adafruit, this would not have been a problem, as they didn't make it complicated.

Best wishes, Dave

I looked at the datasheets you linked to. Even if there is some data I have not seen, the fact that other folks have connected the board to the Pi 5VDC power pin makes it a moot point.

Hopefully the OP will do the little test I asked him to do so we will know the truth.

 

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
Page 3 / 4