View previous topic :: View next topic |
Author |
Message |
Futterama
Joined: 17 Oct 2005 Posts: 98
|
I2C on PIC12F1840 does not work on 3.3V |
Posted: Sat Feb 18, 2017 7:42 am |
|
|
Hi,
I have a PIC12F1840 configured as an I2C slave using the I2C hardware on pins RA1 and RA2.
The I2C master device runs 3.3V and I2C clock is 100kHz. The master has built-in pull-ups but I don't know the resistor values.
Software wise this works fine, but I see problems related to the supply voltage of the PIC12F1840.
When the PIC12F1840 is at 3.3V, it sends garbage back to the master. When I up the voltage to 3.8V, the PIC12F1840 starts to send the correct data.
I haven't found any evidence in the datasheet that suggests that this PIC can't do I2C at 3.3V supply voltage.
I could just run the PIC12F1840 at e.g. 5V, this also seems to work, but according to this post from user "PCM programmer", that shouldn't work due to the MSSP inputs being special Schmitt Trigger inputs:
https://www.ccsinfo.com/forum/viewtopic.php?p=43815#43815
Running the slave at 5V also prohibits me from adding additional pull-up resistors in the slave end, and I need this as the I2C lines are 16" twisted wire which introduces some extra bus capacitance.
If I need to select another PIC device for my application, which low pin count PIC with I2C hardware could I use that will actually work with 3.3V?
Thanks.
EDIT: I have just tested the same scenario with a PIC16F1825 and it has the same problem. Same with PIC12LF1840, but that was expected. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Sat Feb 18, 2017 8:26 am |
|
|
comments..
re: master has unknown pullups... You should find out WHAT they are ! That info is kinda critical cause I2C needs correct pullups....
re: the slave. Have you disabled EVERY other peripheral that's attached to RA1 and RA2 ? That PIC has a LOT of 'stuff' on them pins !!
re: garbage. Have you proper ground between the PICs? Is the Vdd stable ? again I2C pullups ? Is it 'time' based or really random times and random data? Is the program interrupt driven, got the WDT enabled. Have proper PSU bypass caps. Can the PIC do the 1Hz LED program forever? Got the
Have to ask what is the Master?
Have you used the I2C scanner program posted in the library here ?
just some things that pop into my head...
Jay |
|
|
Futterama
Joined: 17 Oct 2005 Posts: 98
|
|
Posted: Sat Feb 18, 2017 8:35 am |
|
|
Hi temtronic,
Thanks for your reply.
The master device is a RC receiver with built-in telemetry system which can be accessed by the I2C connection.
I checked the datasheet, all the other peripherals on those pins are disabled by default.
VDD is stable, less than 100mV ripple.
In another forum, it was suggested that running the PIC12F1840 at 32MHz and 3.3V wouldn't work, but the datasheet says 32MHz is OK down to 2.5V. But I changed the internal osc to 16MHz just as a test, and what do you know, the I2C works then! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Feb 18, 2017 11:11 am |
|
|
You could run the slave PIC at +5v, but enable SMBUS in the #use i2c()
statement. This will make the slave PIC have input voltage levels on
the hardware i2c pins that are compatible with +3.3v pull-ups.
Check the Electrical Specifications section of the PIC data sheet.
SMBUS mode places the input levels at 0.8v (ViL) and 2.1v (Vih). |
|
|
Futterama
Joined: 17 Oct 2005 Posts: 98
|
|
Posted: Sat Feb 18, 2017 12:10 pm |
|
|
Hi PCM programmer,
You are correct with the voltage levels, I didn't notice that option for the #use statement.
But that still prohibits me from adding pull-up resistors unless I also include a 3.3V supply just for those. In this case, it will be easier for me to just run the PIC at 16MHz instead of 32MHz and everything works fine at 3.3V and I can add the pull-ups needed.
Do you have any idea why the I2C module fails at voltage levels below 4V when running the PIC at 32MHz internal osc? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Feb 18, 2017 12:20 pm |
|
|
No. But you have an unknown system. You don't know what the pullups
are on the master. You could probably find out by adding a pull-down
resistor and measure the voltage on the i2c line. This would create a
voltage divider. Should be easy to do.
The pull-down is only for this test. It's not to be installed while running
the i2c module.
Also, what is the master ? Is it a PIC ? |
|
|
Futterama
Joined: 17 Oct 2005 Posts: 98
|
|
Posted: Sat Feb 18, 2017 12:39 pm |
|
|
The master is either a Cypress MCU or a STM MCU, I have devices with both. I don't know more than this, the devices are too expensive to void warranty by pulling them apart to check. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Sat Feb 18, 2017 2:43 pm |
|
|
Just test what voltage is on the bus when idle. Remember that I2C 'idles high', and this is pulled up by the resistive pullups. So the voltage basically tells you the supply voltage on the master device.
I'd suspect you have a 5v master.
I2C, if properly specified, has a Vih of 70% Vdd. If your master is 5v, then a 3.3v slave, will be clamping the line below this point. 70% of 5v is 3.5v. Result garbage. When you up the supply to 3.8v, you (just) allow the rail to go high enough....
You need either to run your PIC at 5v, or have a bus transceiver that doesn't clamp the rail.
Normally the problem is the other way, with a 5v PIC and people wanting to interface to a 3.3v device. This is when the SMBUS settings help, since SMBUS has a lower Vih. |
|
|
Futterama
Joined: 17 Oct 2005 Posts: 98
|
|
Posted: Sat Feb 18, 2017 2:45 pm |
|
|
The master is definitely 3.3V, the documentation says so, so does my scope. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Feb 18, 2017 5:17 pm |
|
|
Quote: |
The master is either a Cypress MCU or a STM MCU, I have devices with
both. I don't know more than this, the devices are too expensive to void
warranty by pulling them apart to check. |
I didn't ask you to dismantle the board.
You want to determine the value of the internal pull-up resistor.
Make the master board boot up in a benign state, so its i2c bus lines
are floating high. They are not driven. They just have a pullup to 3.3v.
The 3.3v is provided by the master board since you said it's at 3.3v.
Temporarily add a known resistor value externally to the board
on the SDA line. Add it as a pull-down, as shown below.
Code: |
+3.3v
|
<
> R1
< on master
SDA | board
-------o---------------o------------ V1 (measured with
| a voltmeter
< R2 by you)
> external
< pulldown
|
-----
--- GND
-
|
Measure the voltage V1 on the SDA line and plug it into the equation
below, along with the value of your external pulldown, R2. Then solve
the equation and it will tell you the value of the internal pull-up:
Code: |
3.3 x R2
R1 = ---------- - R2
V1
|
Example: Suppose you add an external 4.7K pull-down resistor, and
then measure the SDA voltage as 1.94 volts. Solve the equation with
R2 as 4.7K, and V1 as 1.94 volts. You get a 3.3K internal pull-up:
R1 = ((3.3 x 4.7K) / 1.94) - 4.7K = 3.295 K = 3.3K internal resistor |
|
|
Futterama
Joined: 17 Oct 2005 Posts: 98
|
|
Posted: Sun Feb 19, 2017 1:56 am |
|
|
Why not just put an amp meter directly between GND and SDA/SCL? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Feb 19, 2017 2:24 am |
|
|
That would also work. |
|
|
Futterama
Joined: 17 Oct 2005 Posts: 98
|
|
Posted: Sun Feb 19, 2017 3:18 am |
|
|
Well, then the Cypress device has 10k pull-ups and the STM device has 1k1 pull-ups. Both devices pull to 3.3V as documented. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Sun Feb 19, 2017 4:16 am |
|
|
Tell us more about what the scope shows?.
Can you measure the rising edge times?.
I was querying the '3.3v' in your original statement, since though you said the master was 3.3v, your symptoms were very much as if it might actually be running at a higher voltage. This would also explain why it worked with the PIC at 5v....
One thought going through my head is that the master might actually have some form of active pull up, so simple current measurements or resistive measurements might not give the whole story. A good look at the rising edges might then show more about what is going on.
Why would you want additional pull ups?. If the master is providing pullups, then adding extras could take the bus current over spec.
If you want to run at 3.3v, why not get the LF1840?. I must admit to being very suspicious when a chip has a sheet showing supported oscillator rates that jump in big steps like the 1840 one....
One thing that obviously changes when you go down to 16MHz, is the power drawn by the PIC. Goes from a predicted 1.2mA at 16MHz, to 3.8mA at 32Mhz. Is it possible that this is creating a noise problem in your PIC circuit?. If something is absolutely borderline, a few mV droop in the PIC supply could be making all the difference.
Ouch. 10K pullups. For these you almost certainly do need more pullup. Why on earth a company would supply a unit with this size pullup is insane.
Rp(max) in I2C, is specified as:
Rp(max) = tR/(Cb * 0.8473)
Solving for Cb at 100KHz, with 10KR:
Cb(max) = (1000nSec * 0.8473)/10000
= 84E-12
Just 84pF.
So there will be timing problems on the I2C bus with 10K pullups, if the total capacitance on the bus is over 84pF. Given even a short length of wire, with the pin capacitances of the chips, it is very likely that you will have problems without some extra pullup on this device.
The minimum (for standard mode 3mA drivers), solves as 966R, so you should not use any extra resistance on the bus with 1K.
However there is a caveat. I2C, specifies that the pullups should always go to the same line. So it is actually 'illegal' to have a pull up to 3.3v on your device, and then a pull up to another 3.3v rail on the units themselves. This is why devices sending I2C busses between boards, normally have the Vdd also included in the wire. |
|
|
Futterama
Joined: 17 Oct 2005 Posts: 98
|
|
Posted: Tue Feb 21, 2017 1:24 am |
|
|
I will grab some scope shots tonight and try to explain what it is that I see when it stops working.
Why additional pull-ups? Because of the 10k in the Cypress master device.
Why not the LF version PIC? Because it does not provide any advantage at all, the only difference I can spot in the datasheet is lower max voltage, the minimum voltage is the same af the F version. I did test the PIC12LF1840 as mentioned in my first post, it does the exact same thing as the F version at 32MHz.
The current draw should not be an issue, I'm using a MCP1703 regulator and the circuit is simple with only a LED and opto output for data into the PIC.
The master does not output it's 3.3V, only GND, SCL, SDA and it's own supply voltage which is 2S LiPo voltage ~7.4V.
At the moment I'm running the PIC at 16MHz and the I2C seems quite stable, even without additional pull-ups.
So the open question is still, why does the hardware I2C work (reliably) at 16MHz MCU clock but not at 32MHz? |
|
|
|