Using an oscilloscope makes my I²C-bus work. - Page 1
Forum section: electronics / general

author: Mercator
author_rank: Contributor
timestamp: November 07, 2016, 07:38:11 pm
content: Hi,I have a weird problem. I would like to measure the ambient temperature using an MCP9808 and a PIC 24FJ64GB004. Both are connected via an I²C Bus (Pins SDA2 and SCL2 on the PIC). I'm using MPLAB's Code Configurator for generating some driver code.When I first tested the project, the I²C-Bus didn't work. So, I connected my oscilloscope to the SDA and SCL lines and suddenly it worked!Actually, quite reliably. So, it can't be the code. I know, I probably added some capacitance to the circuit by connecting the probes. But why does it work at all and how can I fix it? How can I troubleshoot it if the problem is gone as soon as the oscilloscope is connected?I attached a screenshot of the schematic and layout. There are two MCP9808 in two different packages, but only one will be placed (the MCP9808 is in short supply every now and again).Thank you for your help!

author: nctnico
author_rank: Super Contributor
timestamp: November 07, 2016, 07:53:08 pm
content: Are the pins on the PIC properly configured for I2C?

author: tatus1969
author_rank: Super Contributor
timestamp: November 07, 2016, 08:04:19 pm
content: could you post some scope shots showing the traffic? maybe somedetail rising/falling edges. maybe try using slower speed for a test.

author: rstofer
author_rank: Super Contributor
timestamp: November 07, 2016, 08:40:47 pm
content: I think I would have put the pull-up resistors at the far end of the bus relative to the uC.

author: wraper
author_rank: Unknown
timestamp: November 07, 2016, 09:01:33 pm
content: Likely not a source of the problem but thermal pad of MCP9808must beconnected to GND according to the datasheet (may beaccording to other part of the datasheet).

author: Ice-Tea
author_rank: Super Contributor
timestamp: November 07, 2016, 09:20:54 pm
content: Keep in mind that the probe represents a small capacitive load. So, you may try to put a 20pF cap to GND on both traces (without the probe) and see see what happens...

author: wraper
author_rank: Unknown
timestamp: November 07, 2016, 09:32:56 pm
content: May also be, that what is affecting the operation is not necessarily probe capacitance but the fact you are connecting GND of the PCB to the mains earth through the scope.

author: LA7SJA
author_rank: Regular Contributor
timestamp: November 08, 2016, 06:58:37 am
content: Read thishttp://ww1.microchip.com/downloads/en/DeviceDoc/70000195f.pdfThis doc suggest 2K2 pull-up and you should test:bit 9 DISSLW: Disable Slew Rate Control bit1 = Slew rate control is disabled0 = Slew rate control is enabledJohan-Fredrik

author: Feynman
author_rank: Regular Contributor
timestamp: November 08, 2016, 09:39:17 am
content: Quote from: wraper on November 07, 2016, 09:32:56 pmI would consider a grounding problem aswell.I think it is very unlikely that the probe's capacitive load affects I²C operation. With a 10X-Probe the majority of the probe's capacitance is isolated with a 9MOhm resistor and I strongly doubt that the tip capacitance does any harm (or in this case good) to a I²C-Bus, that is not even near anything "high-speed" where such effects would matter.Also 2k2 vs. 3k3 pull-up resistors should not make that much of a difference.

author: tatus1969
author_rank: Super Contributor
timestamp: November 08, 2016, 10:07:25 am
content: Quote from: Feynman on November 08, 2016, 09:39:17 amThere is always a capacitor in parallel with then 9M that is in the range of 10-15pF depending on the probe. Connecting it to one of the I2C signals will increase its rise time, and by this change the relative timing of the two. If timings are too tight (the reason why I asked to lower the I2C speed), this can make the difference.

author: Ice-Tea
author_rank: Super Contributor
timestamp: November 08, 2016, 10:12:03 am
content: Quote from: Feynman on November 08, 2016, 09:39:17 amA 400kHz clock on a high speed input double clocks just as easily as a 400MHz clock.

author: 22swg
author_rank: Frequent Contributor
timestamp: November 08, 2016, 10:16:46 am
content: QuoteI would suspect a bus collision on I2C start , how you configuring the I2C pins.?

author: tatus1969
author_rank: Super Contributor
timestamp: November 08, 2016, 10:35:58 am
content: Quote from: Ice-Tea on November 08, 2016, 10:12:03 amI would agree to that when we would be talking about push-pull outputs, but this is open-drain with pull-up. Capacitances do matter here, even at such low speed.

author: Mercator
author_rank: Contributor
timestamp: November 08, 2016, 11:47:13 am
content: Wow. Thanks for all the answers. You are awsome!Quote from: nctnico on November 07, 2016, 07:53:08 pmI think so. Used MPLAB Code Configurator (nice, simple GUI) for that. Since it works with the probes attached, the configuration should be fine. Attached some pictures of the configuration.Quote from: tatus1969 on November 07, 2016, 08:04:19 pmI tried 400kHz and 100 khz speed. I will post a scope picture shortly.Quote from: rstofer on November 07, 2016, 08:40:47 pmI'm not an electronics engineer. Can you explain to me why this might be better? Is it just good practice or absolutely vital?Quote from: wraper on November 07, 2016, 09:01:33 pmYes, I noticed when I got the PCB's made. Forgot to do it. Stupid me.I will keep that in mind for the next revision. However, the datasheet says"There is an internal electrical connection between the Exposed Thermal Pad (EP) and the GND pin. The EP may be connected to the system ground on the Printed Circuit Board (PCB).". So it's not a must. As I understood it, its only to reduce the effects caused by self heating.Quote from: Ice-Tea on November 07, 2016, 09:20:54 pmYes, but typically the I²C-Bus doesn't require adding capacitance. There is even a maximum of 400pF.Quote from: wraper on November 07, 2016, 09:32:56 pmThere is an extra USB-port on the board. I used it as a serial interface to get a temperature reading. So it should be connected to mains earth through the computer, right (used a desktop PC)?Quote from: LA7SJA on November 08, 2016, 06:58:37 amGood idea, tried it with a 100khz speed, with DISSLW enabled and disabled. No change. Doesn't work. The doc doesn't say anything about 2.2k. It just gives you some rough formulas. In fact, I²C should work with anything between 2.2k and 4.7k.Quote from: 22swg on November 08, 2016, 10:16:46 amThere's only one device on the bus. So there shouldn't be any collisions. The bus is configured as shown in the screenshots attached.Quote from: tatus1969 on November 08, 2016, 10:35:58 amYes, but shouldn't the circuit fail rather than work by adding capacitance through the scope? I will post a scope image shortly.

author: pix3l
author_rank: Regular Contributor
timestamp: November 08, 2016, 11:53:57 am
content: Hi Mercator,As you can see on page 4 of this document:http://ww1.microchip.com/downloads/en/DeviceDoc/70000195f.pdf, pull up resistors of 2k2 are recommended. And they are quite vital to the working of an I2C bus...

author: 22swg
author_rank: Frequent Contributor
timestamp: November 08, 2016, 12:56:06 pm
content: Hi Mercator, Not used CC but been using I2C and PIC24 ( all flavours ) for some time, so I have a set up that works . (a) H/W 2k2 pullup (at final end device if possible but not essential ) keep I2C wire as short as practicable ( b) S/W , Bus collision can occur even with one slave device . ( I'm guessing here >) as the PIC enables I2C it needs to 'see' both clock and data high, if not collision bit set, and nothing works, So I TRISxx=0 the clock and data I/O pins as outputs , then make them high LATxx=1, then back to inputs and immediately enable I2C, seems to work especially if you have some high MIPS going on ...

author: Mercator
author_rank: Contributor
timestamp: November 08, 2016, 01:04:55 pm
content: Scope pictures, anyone?First, if I just poke the pads of the unused MCP9808 footprint, I just get a high level on both lines. There seems to be no activity.If I solder on some fine copper leads and attach the scope probes to those, it works. I stiched together I wide screen image of the complete communication. Channel 1 (yellow) is the SDA line, Channel 2 (blue) is the SCL line.Communication starts with the start condition, followed by the address of the MCP9808 (0b0011000), the write-bit (0) and an Acknowledge bit. Then, the µC selects the ambient temperature register (0b00000101). Then, there is a short period of silence on the bus and then the µC starts again with the address of MCP9808. This time with a read-bit (1), followed by an acknowledge bit, the MSB-data of the ambient temperature register, another acknowledge and the LSB-Data with the stop condition at the end.

author: Mercator
author_rank: Contributor
timestamp: November 08, 2016, 01:39:55 pm
content: Quote from: 22swg on November 08, 2016, 12:56:06 pmJust soldered in two 4.7k resistors in parallel to the 3.3k pullups. Making it an effective 1.9k which is as close to 2.2k as I can get right now. Still nothing.Then, I selected "Start High" in the pin manager of MCC to mimic what you did. And it works!Just to make sure, I desoldered the 4.7k resistors. It stopped working.So, I soldered them back in and it works again!So, in summary: The SDA and SCL pins have to be configured to start high and the pullup resistors should be around 2.2k.Thanks a lot to all of you guys!

author: tatus1969
author_rank: Super Contributor
timestamp: November 08, 2016, 08:20:34 pm
content: Quote from: Mercator on November 08, 2016, 01:04:55 pmI checked the signals carefully, cant't find anything that is even close to critical. Looks like a perfect noise-free I2C comms. Also the rise time is well within limits. You should not need to reduce the pull-up resistors to make it working. The microcontroller's I/Os are definitely in open drain configuration.Is that a picture of the exact situation that fails when you disconnect the probe?Is the I2C implementation that you use pure software based bit banging? It looks like that. Maybe there is a hidden error in the implementation, for example sampling the slaves ACK at the wrong moment in time. It must be sampled by the master *after* the rising clock edge.Although it seems to work now, I wouldn't find this fix trustworthy. You didn't tell in detail how you diagnosed the not working I2C. Was that a return value from the library, possibly indicating slave NACK? Another idea: solder 47k resistors to each of the I2C signals, and attach your 1:10 probe to these. This will bandwidth-limit your signal on the scope, but for 100kHz it should still be enough and it will eliminate the capacitive loading that causes the I2C to miraculously work (not enough for 400kHz!).

author: tatus1969
author_rank: Super Contributor
timestamp: November 08, 2016, 08:22:17 pm
content: Quote from: Mercator on November 08, 2016, 01:04:55 pmHuh??Is it possible that we are chasing a soldering problem??? I would grab a magnifying glass now...

author: 22swg
author_rank: Frequent Contributor
timestamp: November 09, 2016, 10:01:34 am
content: QuoteTatus.... The OP used MPLAB Code Configurator ?

author: nctnico
author_rank: Super Contributor
timestamp: November 09, 2016, 10:07:27 am
content: Quote from: tatus1969 on November 08, 2016, 08:22:17 pmYou might be on to something here! Redoing the solder joints with some flux is never a bad idea in case of weird problems.

author: tatus1969
author_rank: Super Contributor
timestamp: November 09, 2016, 08:20:04 pm
content: Quote from: 22swg on November 09, 2016, 10:01:34 amWhen you could look into my brain and open up the Microchip page, then you would only read "this page intentionally left blank"