User avatar
yv1hx
Posts: 372
Joined: Sat Jul 21, 2012 10:09 pm
Location: Zulia, Venezuela
Contact: Website

Interfacing Raspberry Pi with RTC1307 without level shifter?

Tue Aug 21, 2012 2:59 am

Hello everyone,

My apologize if this matter has been managed before, but I cannot find any references.

This article http://binerry.de/post/26685647322/raspberry-pi-and-i2c the author talks about interfacing directly the DS1307 I2C RTC to the R-Pi without using any level shifters (the R-Pi have 3.3Vdc levels and the RTC1307 works with 5VDC logic).

Anybody has tried this?
Marco-Luis
Telecom Specialist (Now Available for Hire!)

http://www.meteoven.org
http://yv1hx.ddns.net
http://twitter.com/yv1hx

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12351
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Tue Aug 21, 2012 6:14 am

should work, as high levels are only provided by pullups, and pullups to 3V3 levels are built into and enabled on the I2C GPIO's of the PI. Additionally the RTC1307 is comfortable with 3V3 logic levels, as it sees as "high" anything above 2,2 Volt.

ailwyn
Posts: 29
Joined: Sun Jan 08, 2012 9:52 pm

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Tue Aug 21, 2012 7:13 am

I can confirm that the DS1307 works without logic level shift (as do a few other I2C devices I've tried) whether this is recommended or not I don't know.

User avatar
yv1hx
Posts: 372
Joined: Sat Jul 21, 2012 10:09 pm
Location: Zulia, Venezuela
Contact: Website

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Thu Aug 23, 2012 4:21 am

mahjongg wrote:should work, as high levels are only provided by pullups, and pullups to 3V3 levels are built into and enabled on the I2C GPIO's of the PI. Additionally the RTC1307 is comfortable with 3V3 logic levels, as it sees as "high" anything above 2,2 Volt.
mahjongg: Thanks for your answer, my main concern is the SDA bus, because the DS1307, when "asked" from the R-Pi at 3.3vdc, will "answer" with TTL logic levels (usually 4volts high level) and this voltage exceeds the 3.3v R-Pi spec, then possibly frying my valuable R-Pi :shock:

Putting a voltage divider between the RTC and R-Pi should work OK only in the RTC >> R-Pi direction, because in the opposite direction, the voltage divider drops the R-Pi output below the 2v threshold level.
Marco-Luis
Telecom Specialist (Now Available for Hire!)

http://www.meteoven.org
http://yv1hx.ddns.net
http://twitter.com/yv1hx

User avatar
yv1hx
Posts: 372
Joined: Sat Jul 21, 2012 10:09 pm
Location: Zulia, Venezuela
Contact: Website

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Thu Aug 23, 2012 4:25 am

ailwyn wrote:.... whether this is recommended or not I don't know.
ailwyn: Good Point! :lol: I should raise my doubt to the R-Pi hardware design team, Anyone knows a way to contact them?
Marco-Luis
Telecom Specialist (Now Available for Hire!)

http://www.meteoven.org
http://yv1hx.ddns.net
http://twitter.com/yv1hx

User avatar
yv1hx
Posts: 372
Joined: Sat Jul 21, 2012 10:09 pm
Location: Zulia, Venezuela
Contact: Website

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Thu Aug 23, 2012 3:10 pm

Marco-Luis
Telecom Specialist (Now Available for Hire!)

http://www.meteoven.org
http://yv1hx.ddns.net
http://twitter.com/yv1hx

kaos
Posts: 108
Joined: Mon Mar 26, 2012 8:14 pm

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Thu Aug 23, 2012 11:51 pm

mahjongg: Thanks for your answer, my main concern is the SDA bus, because the DS1307, when "asked" from the R-Pi at 3.3vdc, will "answer" with TTL logic levels (usually 4volts high level) and this voltage exceeds the 3.3v R-Pi spec, then possibly frying my valuable R-Pi :shock:
Nope, Mahjongg is right; the I2C pins are an exception to the rule that you shouldn't connect a 5V output to a 3.3V input. The reason is that I2C uses open drain (also known as open collector) logic with pull up resistors. Open drain outputs really only ever actively output "low", by pulling the pin to ground level. When the output is supposed to be "high", the pin is left floating and the pullup resistor provides the "high" voltage. The Raspi has built-in pullups to 3.3V, so that's the highest voltage seen on the bus, and as long as the device it is communicating with accepts this as "high", it should work. (According to the datasheet, DS1307 regards everything over 2.2V as "high", so that's ok.)

--
Best regards, Kári.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Fri Aug 24, 2012 12:13 am

My understanding is that that is usually but not always the case - some slave devices will only work at 5v and also have pull-ups to their own supply :o so be sure to check and if necessary use something like this:

http://www.ebay.co.uk/itm/180881703478? ... 1497.l2649

User avatar
yv1hx
Posts: 372
Joined: Sat Jul 21, 2012 10:09 pm
Location: Zulia, Venezuela
Contact: Website

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Fri Aug 24, 2012 3:56 pm

kaos wrote:
mahjongg: Thanks for your answer, my main concern is the SDA bus, because the DS1307, when "asked" from the R-Pi at 3.3vdc, will "answer" with TTL logic levels (usually 4volts high level) and this voltage exceeds the 3.3v R-Pi spec, then possibly frying my valuable R-Pi :shock:
Nope, Mahjongg is right; the I2C pins are an exception to the rule that you shouldn't connect a 5V output to a 3.3V input. The reason is that I2C uses open drain (also known as open collector) logic with pull up resistors. Open drain outputs really only ever actively output "low", by pulling the pin to ground level. When the output is supposed to be "high", the pin is left floating and the pullup resistor provides the "high" voltage. The Raspi has built-in pullups to 3.3V, so that's the highest voltage seen on the bus, and as long as the device it is communicating with accepts this as "high", it should work. (According to the datasheet, DS1307 regards everything over 2.2V as "high", so that's ok.)

--
Best regards, Kári.
Kári, Thank you for clarifying the point.

I was having a look to the R-Pi schematics and got a pair on 1800 Ohm pulling to 3.3v the I2C lines.
Since I'm planning to add my RTC using a small breadboard, I will omit the pullups resistors and connect the RTC directly to the R-Pi..
Marco-Luis
Telecom Specialist (Now Available for Hire!)

http://www.meteoven.org
http://yv1hx.ddns.net
http://twitter.com/yv1hx

User avatar
yv1hx
Posts: 372
Joined: Sat Jul 21, 2012 10:09 pm
Location: Zulia, Venezuela
Contact: Website

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Fri Aug 24, 2012 4:04 pm

pygmy_giant wrote:My understanding is that that is usually but not always the case - some slave devices will only work at 5v and also have pull-ups to their own supply :o so be sure to check and if necessary use something like this:

http://www.ebay.co.uk/itm/180881703478? ... 1497.l2649
pygmy_giant: I agree with you, for this reason I raise this post, I'm (by far) more a hardware guy than a software guy :P

Having a look to other post in this forum I got the following:

http://www.raspberrypi.org/phpBB3/viewt ... 44&t=10301

This user connects his/her DS1307 directly to the corresponding port pin in the R-Pi, without any level converter stages...I forgot to mention, the DS1307 doesn't have any internal pullup resistors.

Thanks for the link, For another project I was looking some time ago for a device like your suggested. ;)
Marco-Luis
Telecom Specialist (Now Available for Hire!)

http://www.meteoven.org
http://yv1hx.ddns.net
http://twitter.com/yv1hx

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12351
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Fri Aug 24, 2012 4:15 pm

pygmy_giant wrote:My understanding is that that is usually but not always the case - some slave devices will only work at 5v and also have pull-ups to their own supply :o so be sure to check and if necessary use something like this:

http://www.ebay.co.uk/itm/180881703478? ... 1497.l2649
True, its only valid when the I2C device accepts 3V3 levels for its inputs, if using (normal strength i.e. > 1K) pullups to 5V my understanding is that the protection diodes present in all the GPIO's I have ever seen, and I do not believe the Broadcom SoC to be any different, will safely clamp the voltage to 3V3 plus a diode drop, that is to 3,9 Volt, so if the device can work with say 3.7 volt input levels it will still work, although with little margin. The warning about not connecting 5V to the inputs is true for 5V sources that can deliver a lot of current, (through the diode into the 3V3 power supply!) not for weak sources like pullups.

Yes, these level shifters (which contain two simple fets and a few pullup resistor) are often used, even when not strictly necessary.

re-edited, red text I no longer stand behind. Just keep the GPIO voltage well below 5V, with a voltage divider, or 3V6 zener

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Fri Aug 24, 2012 7:46 pm

I need to think about what you said - not sure I fully understand.

The device/board I am using is primarily designed for the arduino which is 5v and states in a highlighted box in the manual that it needs 5v and has pull up resistors to the SDA and SCL lines.

I have therefor decided to err on the side of caution and got me a level converter, but could ditch it if uneccesary?

My current plan is to connect the Pi on the 3v3 side as you would expect and connect the board on the 5v side in mirror image and to additionally connect the vdd on the 5v side to the 5v pin on the Pi.

Is this ok? bit unsure myself...

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12351
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Fri Aug 24, 2012 9:42 pm

Nothing wrong with that approach. Whether or not the interface is necessary or not largely depends on which the chip in this particular "Arduino" uses, normally it uses one of the many 8-bit ATmega chips, most of those (like the Atmega168) have a minimum V-High of 0.6 x VCC (60% of 5V) or 3 Volt, which suggest a 3V3 high would suffice, though with little margin.

kaos
Posts: 108
Joined: Mon Mar 26, 2012 8:14 pm

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Fri Aug 24, 2012 10:04 pm

The device/board I am using is primarily designed for the arduino which is 5v and states in a highlighted box in the manual that it needs 5v and has pull up resistors to the SDA and SCL lines.
If you do decide to connect this board directly to the Raspi, you should preferably remove those pull up resistors. Yes, the Raspi clamping diodes will *probably* handle reasonably sized pull up resistors to 5V, but I wouldn't want to rely on that.

This should make the board safe to use, but that doesn't mean it will necessarily *work*. To know if it will, you will have to study the datasheet for the I2C device(s) on the board. If it/they will accept 3V (allowing 0.3V margin) as "high", it should work. The parameter you are looking for will probably be called Vih (Voltage input high-level) minimum.

Of course, you can just use that level-shifter and avoid all this headache ;) Personally, I always try to avoid any components not absolutely needed, but then I've got something of a minimum-component-count fetish, probably contracted from old Sinclair ZX81 ads ("only four IC's!") :lol:
My current plan is to connect the Pi on the 3v3 side as you would expect and connect the board on the 5v side in mirror image and to additionally connect the vdd on the 5v side to the 5v pin on the Pi.
Are you going to power the board from the Raspi? If not, I would connect the 5V supply of the level shifter to the board supply. Remember to connect ground of both supplies together, unless your level shifter is a galvanically isolating type. If you are going to power the board from the Raspi, make sure that it doesn't draw to much current. I don't recall seeing any firm numbers for maximum current from the 5V pin of the GPIO, but I wouldn't want to go above 100 to 200 mA, and even that is probably too much if you are using both USB ports at anything near their current capacity.

--
Best regards, Kári.

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Fri Aug 24, 2012 11:12 pm

Interesting - thanks both for the detailed explanations.

I'm using the board in a display-less usb-less lipo powered robot.

Think I'll stick with my level shifter to be safe and certain and run the controller board off the pi...

User avatar
yv1hx
Posts: 372
Joined: Sat Jul 21, 2012 10:09 pm
Location: Zulia, Venezuela
Contact: Website

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Sun Jul 07, 2013 9:43 pm

After dormant a long time in my electronics parts box, I filled up with patience and assembled my DS-1307 HW clock, and worked as expected with the following exceptions:

The command i2cdetect never worked for me, always return a ugly error message:

Code: Select all

-bash: i2cdetect: command not found
Nonetheless, I was able to read & set the HWClock time, using the well documented steps in this forum.

There is any way to program the SQW/OUT pin through the control registers?

I used the DS-1307 with a PicAxe microcontroller before and I managed to send the necessary command to the DS-1307 to activate the SQW/OUT, just for hooking up a led that lit once a second. (The DS-1307 SQW/OUT pin can output a square signal at 1Hz/4.096kHz/8.192kHz/32.768KHz) for feeding in others circuit stages.
Marco-Luis
Telecom Specialist (Now Available for Hire!)

http://www.meteoven.org
http://yv1hx.ddns.net
http://twitter.com/yv1hx

pyrotuc
Posts: 10
Joined: Sat Dec 14, 2013 10:15 pm
Location: texas
Contact: Website AOL

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Sun Dec 29, 2013 3:08 am

the ds1307 is a great chip. its cool hangin out with 3v3 or 5v, is not too picky about pull-ups, and will blink an LED! it likes a battery but can chill without one present.

caution is good, but the ds1307 is a champ, you guys are worrying too much. did i mention you can get them as free samples?
/*
Kris Tucker
http://pyrotuc.com
http://pirhotech.com
alias webExposedEmail='rpiforum@pyrotuc.com'
sudo echo "1" > /sys/class/awesome
*/

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Sun Dec 29, 2013 6:11 pm

The author says this.

"The device is running at 5V, but logic levels are running at just 2V2 - so you don’t need to worry since RPi can just handle a maximum of 3V3 at logic levels..."

As a result level shifters are not needed.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

grahamed
Posts: 277
Joined: Mon Jan 30, 2012 7:01 pm

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Sat Jan 04, 2014 5:32 pm

hi

"The device is running at 5V, but logic levels are running at just 2V2 - so you don’t need to worry since RPi can just handle a maximum of 3V3 at logic levels..."

which proves what precisely?

As kaos said (and I paraphrase slightly) as far as an I2C device (the actual chip not a board which happens to gave a chip on it) the binary levels are zero and, well, not zero. The high voltage is determined by the voltage to which the pull-ups are returned. The logic is not "running at just 2V2".

On general the Pi will survive connection to 5V through a weak pull-up. I too have a minimum component obsession - in my case due to a love of minimal, simple, elegant design, oh and also of being tight.

All-in-all it comes down to case-by-case board-by-board and you either know or you don't. If you don't then do use a level shifter.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12351
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Sat Jan 04, 2014 6:18 pm

mahjongg wrote:
pygmy_giant wrote:My understanding is that that is usually but not always the case - some slave devices will only work at 5v and also have pull-ups to their own supply :o so be sure to check and if necessary use something like this:

http://www.ebay.co.uk/itm/180881703478? ... 1497.l2649
True, its only valid when the I2C device accepts 3V3 levels for its inputs, if using (normal strength i.e. > 1K) pullups to 5V my understanding is that the protection diodes present in all the GPIO's I have ever seen, and I do not believe the Broadcom SoC to be any different, will safely clamp the voltage to 3V3 plus a diode drop, that is to 3,9 Volt, so if the device can work with say 3.7 volt input levels it will still work, although with little margin. The warning about not connecting 5V to the inputs is true for 5V sources that can deliver a lot of current, (through the diode into the 3V3 power supply!) not for weak sources like pullups.
Yes, these level shifters (which contain two simple fets and a few pullup resistor) are often used, even when not strictly necessary.
as of now I learnt that using a simple "series resistor" to limit the "current flow into a GPIO" is a falsehood!
in fact no current will flow into the GPIO's unless the voltage exceeds a value far higher than 5V, but 5V can still, in time damage the GPIO)

Therefore you should always use some kind of resistor divider (or in case of I2C you are better to use a level converter) if you use pullups to 5V.

I imagine that if you combine the 5V pullups with a weaker pulldown resistor to GND, you could create a "resistor divider" that limits the "high" to say 4V. which would both satisfy the Vih of the 5V I2C device, and protect the PI. Just a thought.

I'm thinking about combining the standard 10K to 5V pull-up with a 47K pulldown to GND. When all "open collector/drain" transistors are closed, the I2C signal will float to a level determined by the 10K/470K resistor divider or to say 4.2V, and if any of the "open collector/drain" transistors/ FET's opens the level will go to 0V. It should work! Only downfall is that it will consume a fraction of a mA of current due to the two "60K" resistors connected to 5V.

grahamed
Posts: 277
Joined: Mon Jan 30, 2012 7:01 pm

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Sun Jan 05, 2014 2:40 pm

Hi

If the pullups go to 5V, the voltage applied to the GPIO pin will attempt to rise to 5V but the GPIO pin has a diode which will become forward biased and will pass current into the 3V3 rail. My limited experiments show the voltage rising to about 4V. Current flows according to Ohm's law.

If you wish to prevent the I2C pins from rising too far you can connect a 3V zener from the pullup/GPIO junction to ground.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12351
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Sun Jan 05, 2014 3:25 pm

grahamed wrote:Hi

If the pullups go to 5V, the voltage applied to the GPIO pin will attempt to rise to 5V but the GPIO pin has a diode which will become forward biased and will pass current into the 3V3 rail.
I thought so too, but sadly that doesn't seem to be true, at least not according to Gert!

Simple solution, put 3V6 zeners on both I2C signals, so the signals can never rise above 3.6 Volt, alternatively add pulldown resistors for the same purpose.

I heard from Gert, and can see from the schematic that I2C GPIO's used for the HDMI (CEC) interfacing are hardier than other GPIO, so they can withstand 5V, but I'm not at all sure that is the case for the "normal" I2C pins too.

grahamed
Posts: 277
Joined: Mon Jan 30, 2012 7:01 pm

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Sun Jan 05, 2014 3:41 pm

Hi

Well, I yield to Gert.

The voltage seemed to be plateauing at about 4V suggesting a diode but I really did not want to push it too hard.

User avatar
Burngate
Posts: 6059
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Mon Jan 06, 2014 12:24 pm

mahjongg wrote:
grahamed wrote:Hi

If the pullups go to 5V, the voltage applied to the GPIO pin will attempt to rise to 5V but the GPIO pin has a diode which will become forward biased and will pass current into the 3V3 rail.
I thought so too, but sadly that doesn't seem to be true, at least not according to Gert!
Have you any citation / reference for this?

I've looked around, but can't find him saying it.
There was a thread about the subject, which got rather aeriated, including some guy who reckoned the protection kicked in about 7v, but I can't now find it.
The pdf (http://www.raspberrypi.org/wp-content/u ... herals.pdf) doesn't seem to mention this.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12351
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Interfacing Raspberry Pi with RTC1307 without level shif

Mon Jan 06, 2014 7:22 pm

he didn't say it on this forum. And as I don't want to speak for him, I cannot comment further, as whatever I say is still my own interpretation. please ask him these kind of questions yourself, as he is still a much better source than myself.

In general I have only access to the exact same information sources as everybody else, so please don't construct my opinion to be some kind of "inside information", or the "official", (or unofficial) POV of the raspberry PI foundation.

you are probably referring to this thread: http://www.raspberrypi.org/phpBB3/viewt ... 28&t=63362

Return to “Interfacing (DSI, CSI, I2C, etc.)”