I2C with internal pullups - possible?

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
blackcattech
Posts: 113
Joined: Mon Jan 11, 2010 10:39 pm
Location: Chesterfield

I2C with internal pullups - possible?

Post by blackcattech » Tue Jul 03, 2012 3:36 pm

Does anyone know if it is possible to avoid using external pull-up resistors on an I2C bus by using the internal pullups?

I'm using a PIC18F14K22 and I need to use one I2C device, all very low power and very slow speed. Adding pullups would mean I'd need extra vias and would mess up the ground plane on my PCB a bit. If I don't need them it would be a nicer solution but I can't find anything definitive as to whether it is possible.

The datasheet doesn't make it clear as to whether these are disabled when the MSSP module is enabled or whether they still work as normal. I know the value of the pullup is technically outside the I2C spec but we are talking about a 15mm track at anything as low as 10kHz bus speed and only one device so I'd guess the specs can be pushed in this case.

Of course I'll add external ones if I need them but I'm just wondering if this could be a 'neat' solution...

Jerry Messina
Swordfish Developer
Posts: 1470
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Tue Jul 03, 2012 5:33 pm

That's a good question. Usually the MSSP is on pins that don't have internal pullups, so I've never tried it.

If it does work, 10KHz is probably about the fastest you could run it since the weak pullups can be REALLY weak... anywhere from 100K-12K ohms (50-400uA@5V), so you could end up with rise-times in the tens of usec (the fall-times won't be an issue). Keep in mind that to get a 10KHz MSSP clock you can't run Fosc > 10MHz.

If all else fails you could use the software I2C module w/ internal pullups on those same pins. At least that way you'd be able to tweak any timing to allow for the slow signals.

Let us know how it works out.

Jerry Messina
Swordfish Developer
Posts: 1470
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Tue Jul 03, 2012 5:53 pm

Forgot to mention.

If you don't mind adding the external resistors (and have a spare pin or so) you could power the pullups from an IO pin instead of 5V. RB5 might be a good choice if you're not already using the uart. That would be easy to route w/out messing with a plane or adding vias.

blackcattech
Posts: 113
Joined: Mon Jan 11, 2010 10:39 pm
Location: Chesterfield

Post by blackcattech » Wed Jul 04, 2012 8:02 am

Good thought, Jerry, thanks. Saves me having to extend the 5V rail across the length of the PCB. Even then it has led to some less than optimal routing but better than would have been the case otherwise.

I will try experimenting with both and see if I can remove the resistors for the production units. It would be nice if Microchip could embed the pullup resistors but I guess there are so many variables when it comes to choice of value that it isn't that simple to do.

I could easily run this clock really slowly - it is only to update a DAC once very few seconds. Processor speed isn't an issue, I'm planning to clock it as slowly as I can get away with. It is a 4-20mA loop powered circuit. I was using PWM to generate the voltage to set the loop current (using an XTR115) but have found that the regulator on the XTR115 has very poor regulation so am changing to using a DAC. Moving from PWM to a separate DAC also means I can drop the clock from 4MHz which I needed to generate the PWM to something much slower and more power efficient.

SHughes_Fusion
Posts: 219
Joined: Wed Sep 11, 2013 1:27 pm
Location: Chesterfield

Re: I2C with internal pullups - possible?

Post by SHughes_Fusion » Fri Jun 06, 2014 4:14 pm

Very late reply to this...

I never actually tried using the internal pull-ups for I2C but I've just discovered that this is what the Arduino does. They actually seem to recommend against using external pullups on the SCL and SDA lines!

Mind you, having needed to use an Arduino for a quick and dirty project I have no idea why people rave about them so much... The are cheap but the language is nothing like as easy to use or powerful as Swordfish.

Jerry Messina
Swordfish Developer
Posts: 1470
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: I2C with internal pullups - possible?

Post by Jerry Messina » Sat Jun 07, 2014 2:35 pm

I always meant to check and see how this would work, and completely forgot about it.

I tried it with an 18F25K22 (VDD=5V) and used the MSSP2 peripheral which has its SCL/SDA pins on PortB RB1 and RB2 since PortB has internal pullups. The I2C2.BAS module only needed the pin definitions for SCL and SDA to be tweaked to match the 25K22.

Using the internal pullups actually worked out better than I expected. The rise time on the signals is a little out of spec... I measured about 1.5us from 0V->3.5V and the I2C spec says this should be <1us max, but more than likely this wouldn't be an issue with most devices.

This limits the max usable speed to 100KHz, which isn't too bad. The 400KHz timing is pretty far out of spec, and while "it works" in the sense that you get signals out of the chip I'd be leery of it being reliable. At 100KHz you don't really have to limit the system clock speed either. I tried it using 8MHz -> 64MHz internal osc w/no problems.

Keep in mind I didn't have much of a load on the pins, so any added capacitance would slow things down.
They actually seem to recommend against using external pullups on the SCL and SDA lines!
It's hard to image why since you have much better control over things, but after seeing what some of the Arduino crowd does that might be a good recommendation for them.

SHughes_Fusion
Posts: 219
Joined: Wed Sep 11, 2013 1:27 pm
Location: Chesterfield

Re: I2C with internal pullups - possible?

Post by SHughes_Fusion » Mon Jun 09, 2014 9:34 am

Thanks, Jerry, interesting. As you say, not something you'd do anywhere important but it can be a useful 'hack' for simple projects.

This was my first encounter with Arduino and to be honest I'm not impressed. The IDE is poor, the syntax confusing and the documentation lacking. I'm surprised it has done as well as it has and I'm really surprised Microchip haven't jumped on the bandwagon and released some good, cheap boards using something like Swordfish. I know Amicus is available but the reason I didn't follow that path is that I can buy an arduino clone for a tenner with two prototyping shields while the Amicus costs £30 alone.

Jon Chandler
Registered User
Registered User
Posts: 185
Joined: Mon Mar 10, 2008 8:20 am
Location: Seattle, WA USA
Contact:

Re: I2C with internal pullups - possible?

Post by Jon Chandler » Mon Jun 09, 2014 1:26 pm

Just for the record, Amicus isn't limited to the boards they sell. It can be used with 18F25K20 and 18F25K22 chips on any board that supports them. I'm not recommending using it, particularly as there forum tends to be hostile, suspicious and less-than-helpful. Even useful without the boot loader hardware – just program using a PICkit.
Jon

Check out the TAP-28 PIC Application board at http://www.clever4hire.com/throwawaypic/

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Re: I2C with internal pullups - possible?

Post by David Barker » Mon Jun 09, 2014 1:45 pm

The Firewing for PIC18 board will work with Swordfish and provides pin compatibility with Arduino shields

http://www.firewing.info/pmwiki.php?n=F ... wing08Beta

You can either use the built in bootloader or ICSP. The onboard USB chip is a 18F14K50, with ICSP header. This means you can re-purpose the board from serial to HID interface. 5v and 3.3v is supported. There is also a Swordfish module that enables you to easily interface to the Firewing board

http://www.sfcompiler.co.uk/wiki/pmwiki ... r.Firewing

and an article on using the loader

http://www.sfcompiler.co.uk/wiki/pmwiki ... wingLoader

Bitfogav has also been working on an interesting Swordfish development board:

http://www.bradsprojects.com/forum/view ... f=17&t=954

bitfogav
Registered User
Registered User
Posts: 169
Joined: Sat Oct 09, 2010 1:39 pm
Location: United Kingdom

Re: I2C with internal pullups - possible?

Post by bitfogav » Mon Jun 09, 2014 10:22 pm

I got to say that I've been using the Firewing PIC18 board with Swordfish and it works perfectly, I even like the fact that you can upload your programme to the board via Swordfish too.. :)

SHughes_Fusion
Posts: 219
Joined: Wed Sep 11, 2013 1:27 pm
Location: Chesterfield

Re: I2C with internal pullups - possible?

Post by SHughes_Fusion » Tue Jun 10, 2014 8:37 am

Sounds interesting, will keep an eye out once they become available.

The area where I have a feeling it might not compete is price. What I was doing was very simple - someone wanted a system to simulate the operation of 5 sets of traffic lights. Even the basic Arduino I bought was massively over-powered but the price was right as there was a limited budget for this.

Hopefully if Firewing can push a PIC alternative with a good, powerful and easy to use compiler then it can gain traction against the Arduino and other manufacturers might come in with lower end boards at better prices, suited to the more basic applications.

Daft question, but would it not have been possible to create the Firewing using something like the PIC18F25K50 - this has USB built in and doesn't need an external crystal so would save on parts. Price seems similar to the K22 but would save a few other parts on the BOM. This seems to be one of the ways the Leonardo gets the price down, it uses an AVR with USB so the board itself is very simple.

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Re: I2C with internal pullups - possible?

Post by David Barker » Tue Jun 10, 2014 9:45 am

The Firewing boards are primarily aimed at development or prototyping and give you access to many useful shield solutions. For example, I created a set of library routines to drive the FTDI FT800 using an off the shelf Firewing board (PIC18) and Gameduino shield. I got the following results in less than a day with zero hardware effort

https://www.youtube.com/watch?v=eAJSSxK ... e=youtu.be
http://www.youtube.com/watch?v=1UI2cyCC ... e=youtu.be
http://www.youtube.com/watch?v=vvVdomcX ... e=youtu.be

For me, there are three main ways to realise a client specification when using a Firewing, Amicus, Arduino etc type of system.

(a) give the client the whole board in a box or
(b) you can just remove the MCU and mount onto something cheaper or
(c) provide a very bespoke solution - in this case, main board and shield schematics can be very helpful.

The bespoke solution tends to be expensive for obvious reasons, but most people are happy to pay the going rate if it gives them what they want. I'm currently doing just, an FT800 solution for a client who wants some cool graphics to make his product stand out - Using the Firewing board and FT800 shield enabled me to provide "proof of concept" in just a few days.

The board in a box is incredibly cheap and the cost of one ready assembled and tested board is less that one hour of my contract time. That's a pretty good deal for the client and can certainly help those people who just want either a single or small production run of something. But I guess if it still doesn't work on price, there is always (b). Either way, you are free to develop on Firewing using Swordfish, PBP, PDS, "C" or use the native Firewing compiler.

It's a very flexible system but in this line of work, there is never a "one size fits all" solution and there are many alternatives...

SHughes_Fusion
Posts: 219
Joined: Wed Sep 11, 2013 1:27 pm
Location: Chesterfield

Re: I2C with internal pullups - possible?

Post by SHughes_Fusion » Tue Jun 10, 2014 9:59 am

Unfortunately in this case quoting the client a sensible price didn't go down well so I needed to cheap and cheerful way to get them something. Realistically, if I wasn't doing a favour for a friend I'd have just turned it down flat, as it was I needed to minimise my spend.

The problem I find in the Model Railway game is that most people - in the UK at least - aren't prepared to pay realistic prices for things. I needed to do something as cheap as I could. I managed to modify an old circuit to meet one requirement but needed more IOs for this one.

I see what you are saying about where Firewing is aimed and I've used an Amicus in the past for similar testing and development. All I'm thinking is that the Arduino market is more about price so offering boards at lowest cost helps gain market share. I personally think that getting the message out that there are better options will help improve the popularity of Microchip stuff and make the whole market more lucrative.

Post Reply