{"id":22141,"date":"2018-02-10T19:28:13","date_gmt":"2018-02-10T12:28:13","guid":{"rendered":"http:\/\/tom.ji42.com\/?p=22141"},"modified":"2018-02-10T19:28:13","modified_gmt":"2018-02-10T12:28:13","slug":"bi-directional-logic-level-converter-hookup-guide","status":"publish","type":"post","link":"https:\/\/tom.tomwork.net\/?p=22141","title":{"rendered":"Bi-Directional Logic Level Converter Hookup Guide"},"content":{"rendered":"<div class=\"section tutorial-page\">\n<h2 id=\"introduction\">Introduction<\/h2>\n<p>Do you have a 3.3V I<sup>2<\/sup>C or SPI sensor that might go up in smoke if connected to a 5V Arduino? Or a 5V device that needs a workaround to be compatible with your 3.3V\u00a0<a href=\"https:\/\/www.sparkfun.com\/products\/11546\">Raspberry Pi<\/a>,\u00a0<a href=\"https:\/\/www.sparkfun.com\/products\/11589\">Arduino Due<\/a>\u00a0or\u00a0<a href=\"https:\/\/www.sparkfun.com\/products\/11712\">pcDuino<\/a>?<\/p>\n<p>To get over this obstacle you need a device that can shift 3.3V up to 5V or 5V down to 3.3V. This is called logic level shifting. Level shifting is a dilemma so common we designed a simple PCB assembly to make interfacing devices a little easier: the\u00a0<a href=\"https:\/\/www.sparkfun.com\/products\/12009\">Bi-Directional Logic Level Converter<\/a>.<\/p>\n<p><a href=\"https:\/\/cdn.sparkfun.com\/assets\/3\/a\/a\/6\/4\/52683b97757b7fcf098b4569.png\"><img decoding=\"async\" src=\"https:\/\/cdn.sparkfun.com\/assets\/3\/a\/a\/6\/4\/52683b97757b7fcf098b4569.png\" alt=\"Iso of Bi-Directional Logic Level Shifter\" \/><\/a><\/p>\n<p><!--more--><\/p>\n<p>Though they\u2019re share the same shape and size, this bi-directional logic level converter shouldn\u2019t be confused with the more\u00a0<a href=\"https:\/\/www.sparkfun.com\/products\/11978\">\u201cuni-directional\u201d version<\/a>. This converter can pass data from high to low\u00a0<em>and\/or<\/em>\u00a0low to high on\u00a0<strong>all channels<\/strong>. It\u2019s perfect for level-shifting between devices that are sharing a data wire, like\u00a0<a href=\"https:\/\/learn.sparkfun.com\/tutorials\/i2c\">I<sup>2<\/sup>C<\/a>\u00a0or a one-wire interface.<\/p>\n<h3>Covered In This Tutorial<\/h3>\n<p>In this tutorial we\u2019ll take an in-depth look at the Bi-Directional Logic Level Converter. We\u2019ll examine the schematic and board layout \u2013 explaining what each pin on the board does. At the end we\u2019ll go over some hookup examples to show how you might hook the board up for various interfaces.<\/p>\n<h3>Suggested Reading<\/h3>\n<ul>\n<li><a href=\"https:\/\/learn.sparkfun.com\/tutorials\/logic-levels\">Logic Levels<\/a><\/li>\n<li><a href=\"https:\/\/learn.sparkfun.com\/tutorials\/how-to-use-a-breadboard\">How to Use a Breadboard<\/a><\/li>\n<li><a href=\"https:\/\/learn.sparkfun.com\/tutorials\/what-is-an-arduino\">What is an Arduino?<\/a><\/li>\n<li><a href=\"https:\/\/learn.sparkfun.com\/tutorials\/how-to-solder-through-hole-soldering\">How to Solder<\/a><\/li>\n<li><a href=\"https:\/\/learn.sparkfun.com\/tutorials\/working-with-wire\">Working with Wire<\/a><\/li>\n<\/ul>\n<\/div>\n<p>&nbsp;<\/p>\n<div class=\"section tutorial-page\">\n<h2 id=\"board-overview\">Board Overview<\/h2>\n<p>If you take a peek at the board\u2019s\u00a0<a href=\"https:\/\/cdn.sparkfun.com\/datasheets\/BreakoutBoards\/Logic_Level_Bidirectional.pdf\">schematic<\/a>, you\u2019d find that the bi-directional logic level converter (let\u2019s shorten that to BD-LLC) is actually a very simple device. There is basically one level-shifting circuit on the board, which is repeated four times to create four level-shifting channels. The circuit uses a single N-channel MOSFET and a couple pull-up resistors to realize bi-directional level shifting.<\/p>\n<p><a href=\"https:\/\/cdn.sparkfun.com\/assets\/f\/3\/3\/4\/4\/526842ae757b7f1b128b456f.png\"><img decoding=\"async\" src=\"https:\/\/cdn.sparkfun.com\/r\/400-400\/assets\/f\/3\/3\/4\/4\/526842ae757b7f1b128b456f.png\" alt=\"MOSFET logic level shifting circuit\" \/><\/a><\/p>\n<p><em>The bi-directional level-shifting circuit used on all four channels of the BD-LLC.<\/em><\/p>\n<p>Through some semiconductor magic, this circuit can shift a low voltage signal to high\u00a0<em>and\/or<\/em>\u00a0shift a high-voltage signal to a low voltage. A 0V signal on one end remains a 0V signal on the other. For a complete analysis of this circuit, check out this excellent\u00a0<a href=\"http:\/\/cdn.sparkfun.com\/tutorialimages\/BD-LogicLevelConverter\/an97055.pdf\">Philips Application Note AN97055<\/a>.<\/p>\n<h3>The Pinout<\/h3>\n<p>There are 12 total pins on the BD-LLC \u2013 two parallel rows of six headers. One row contains all of the high voltage (e.g. 5V) inputs and outputs, the other row has all things low voltage (e.g. 3.3V).<\/p>\n<p><a href=\"https:\/\/cdn.sparkfun.com\/assets\/f\/d\/5\/8\/4\/526842ae757b7f5c108b456b.png\"><img decoding=\"async\" src=\"https:\/\/cdn.sparkfun.com\/r\/600-600\/assets\/f\/d\/5\/8\/4\/526842ae757b7f5c108b456b.png\" alt=\"Annotated BD-LLC\" \/><\/a><\/p>\n<p>The pins are labeled on both the bottom and top sides of the board, and organized into groups. Let\u2019s look closer at some of the pin groups:<\/p>\n<h4>Voltage Inputs<\/h4>\n<p>The pins labeled\u00a0<strong><em>HV<\/em><\/strong>,\u00a0<strong><em>LV<\/em><\/strong>, and two\u00a0<strong><em>GND<\/em><\/strong>\u2019s provide high and low\u00a0<strong>voltage references<\/strong>\u00a0to the board. Supplying a steady, regulated voltage to both of these inputs is\u00a0<strong>required<\/strong>.<\/p>\n<p>The voltage supplied to the\u00a0<em>HV<\/em>\u00a0and\u00a0<em>GND<\/em>\u00a0inputs should be higher than that supplied to the\u00a0<em>LV<\/em>\u00a0side. For example, if you\u2019re interfacing from 5V to 3.3V, the voltage on the\u00a0<em>HV<\/em>\u00a0pin should be 5V, and the voltage on\u00a0<em>LV<\/em>\u00a0sould be 3.3V.<\/p>\n<h4>Data Channels<\/h4>\n<p>There are four separate data channels on the BD-LLC, each capable of shifting data to and from high and low voltages. These pins are labeled\u00a0<strong><em>HV1<\/em><\/strong>,\u00a0<strong><em>LV1<\/em><\/strong>,\u00a0<strong><em>HV2<\/em><\/strong>,\u00a0<strong><em>LV2<\/em><\/strong>,\u00a0<strong><em>HV3<\/em><\/strong>,\u00a0<strong><em>LV3<\/em><\/strong>,\u00a0<strong><em>HV4<\/em><\/strong>, and\u00a0<strong><em>LV4<\/em><\/strong>. The number at the end of each label designates the channel of the pin, and the\u00a0<em>HV<\/em>\u00a0or\u00a0<em>LV<\/em>\u00a0prefix determines whether it\u2019s on the high or low side of the channel.<\/p>\n<p>A low-voltage signal sent in to\u00a0<em>LV1<\/em>, for example, will be shifted up to the higher voltage and sent out\u00a0<em>HV1<\/em>. Something sent in\u00a0<em>HV3<\/em>\u00a0will be shifted down and sent out of\u00a0<em>LV3<\/em>. Use as many of these channels as your project requires. You don\u2019t have to use every single one.<\/p>\n<p>Keep in mind that these level shifters are\u00a0<strong>purely digital<\/strong>. They can\u2019t map an analog voltage from one max voltage to another.<\/p>\n<\/div>\n<div class=\"section tutorial-page\">\n<h2 id=\"hookup-examples\">Hookup Examples<\/h2>\n<h3>Assembly<\/h3>\n<p>Before you can plug the converter into your system, you\u2019ll need to\u00a0<a href=\"https:\/\/learn.sparkfun.com\/tutorials\/how-to-solder-through-hole-soldering\">solder<\/a>\u00a0something into it. There are a lot of options here. You could solder\u00a0<a href=\"https:\/\/www.sparkfun.com\/products\/116\">straight male headers<\/a>\u00a0in, and plug it right into a breadboard. Or perhaps you want to solder\u00a0<a href=\"https:\/\/www.sparkfun.com\/products\/11375\">wires<\/a>directly into it. Pick an assembly method that melds with how you intend to use the board.<\/p>\n<p><a href=\"https:\/\/cdn.sparkfun.com\/assets\/9\/d\/3\/3\/d\/52684977757b7f873b8b4567.png\"><img decoding=\"async\" src=\"https:\/\/cdn.sparkfun.com\/r\/600-600\/assets\/9\/d\/3\/3\/d\/52684977757b7f873b8b4567.png\" alt=\"BD-LLC soldered up\" \/><\/a><\/p>\n<p>Once your BD-LLC is soldered up, it\u2019s time to hook it up. Your hookup will probably vary depending on which communication interface you\u2019re using. Below we\u2019ll show how to hook the level converter for three of the most common communication protocols.<\/p>\n<h3>Using the BD-LLC for Serial<\/h3>\n<p>Although you won\u2019t be taking advantage of the BD-LCC\u2019s bi-directional abilities, it\u2019s perfectly fine to use the board to shift\u00a0<a href=\"https:\/\/learn.sparkfun.com\/tutorials\/serial-communication\">serial communication<\/a>. Serial usually requires two signal wires \u2013\u00a0<em>RX<\/em>\u00a0(receive) and\u00a0<em>TX<\/em>\u00a0(transmit) \u2013 which both have a defined direction. These signals can be passed through any of the four channels on the BD-LLC.<\/p>\n<p>Let\u2019s say, for example, you want to hookup an\u00a0<a href=\"https:\/\/www.sparkfun.com\/products\/11400\">Electric Imp Breakout Board<\/a>\u00a0(which has a 3.6V maximum input voltage) to an\u00a0<a href=\"https:\/\/www.sparkfun.com\/products\/11021\">Arduino Uno<\/a>\u00a0via their UARTs. Here\u2019s one possible hook up:<\/p>\n<p><a href=\"https:\/\/cdn.sparkfun.com\/assets\/learn_tutorials\/1\/4\/7\/LogicLevelFixed.png\"><img decoding=\"async\" src=\"https:\/\/cdn.sparkfun.com\/r\/600-600\/assets\/learn_tutorials\/1\/4\/7\/LogicLevelFixed.png\" alt=\"Arduino to Electric Imp serial via BD-LLC\" \/><\/a><\/p>\n<p><em>Please note that the Arduino and the Electric both have their own power supplies in this example.<\/em><\/p>\n<p>Make sure\u00a0<em>LV<\/em>\u00a0is powered at 3.3V, and\u00a0<em>HV<\/em>\u00a0is at 5V. Double-check that the channels match up, and a-shifting you will go! You\u2019ve even got two extra channels to shift as you please.<\/p>\n<h3>Using the BD-LLC for SPI<\/h3>\n<p>The BD-LLC\u2019s four channels are a perfect match for most\u00a0<a href=\"https:\/\/learn.sparkfun.com\/tutorials\/serial-peripheral-interface-spi\">SPI communications<\/a>. SPI usually requires four wires: MOSI (master out, slave in), MISO (master in, slave out), SCLK (serial clock), and CS (chip select). These four wires can each be routed through a channel on the BD-LLC.<\/p>\n<p>For example, if you wanted to connect an Arduino to an\u00a0<a href=\"https:\/\/www.sparkfun.com\/products\/9836\">ADXL345 Breakout Board<\/a>, which has an operating range of 2.0-3.6V, here\u2019s how the BD-LLC could be spliced in:<\/p>\n<p><a href=\"https:\/\/cdn.sparkfun.com\/assets\/learn_tutorials\/1\/4\/7\/spi-example_bb-02.png\"><img decoding=\"async\" src=\"https:\/\/cdn.sparkfun.com\/r\/600-600\/assets\/learn_tutorials\/1\/4\/7\/spi-example_bb-02.png\" alt=\"SPI ADXL345 to Arduino via BD-LLC\" \/><\/a><\/p>\n<p>Since each of the channels on the BD-LLC are bi-directional any of the four SPI lines can go through any of the BD-LLC\u2019s four channels.<\/p>\n<h3>Using the BD-LLC for I<sup>2<\/sup>C<\/h3>\n<p><a href=\"https:\/\/learn.sparkfun.com\/tutorials\/i2c\">I<sup>2<\/sup>C<\/a>\u00a0is the communication standard where the BD-LLC really shines, because it requires that both data and clock signals \u2013 SDA and SCL \u2013 be bi-directional. Each of those lines can be passed through any of the BD-LLC\u2019s level-shifting channels.<\/p>\n<p>For this example, let\u2019s keep using the ADXL345 breakout but instead swap over to the I<sup>2<\/sup>C interface. We can even add another I<sup>2<\/sup>C device\u2026how about the\u00a0<a href=\"https:\/\/www.sparkfun.com\/products\/10612\">L3G4200D Gyroscope Breakout<\/a>. Since I<sup>2<\/sup>C is only a two-wire interface, we have room on the BD-LLC to fit in a couple of extra signals, like the interrupt outputs from each board<\/p>\n<p><a href=\"https:\/\/cdn.sparkfun.com\/assets\/b\/5\/9\/f\/c\/5266e578757b7fe84c8b456f.png\"><img decoding=\"async\" src=\"https:\/\/cdn.sparkfun.com\/r\/600-600\/assets\/b\/5\/9\/f\/c\/5266e578757b7fe84c8b456f.png\" alt=\"I2C ADXL345, L3G4200D to Arduino via BD-LLC\" \/><\/a><\/p>\n<p>The two 3.3V I<sup>2<\/sup>C devices can both share the same level shifted SDA and SCL lines. Even more I<sup>2<\/sup>C device can be added, as long as they have unique addresses.<\/p>\n<\/div>\n<div class=\"section tutorial-page\">\n<h2 id=\"resources--going-further\">Resources and Going Further<\/h2>\n<p>Here are some resources related to the LLC and level-shifting in general:<\/p>\n<ul>\n<li><a href=\"https:\/\/cdn.sparkfun.com\/datasheets\/BreakoutBoards\/Logic_Level_Bidirectional.pdf\">Bi-Directional Logic Level Converter Schematic<\/a><\/li>\n<li><a href=\"https:\/\/cdn.sparkfun.com\/datasheets\/BreakoutBoards\/Logic_Level_Bidirectional.zip\">Bi-Directional Logic Level Converter Eagle Files<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/sparkfun\/Logic_Level_Bidirectional\">Bi-Directional Logic Level Converter GitHub Repo<\/a><\/li>\n<li><a href=\"http:\/\/cdn.sparkfun.com\/tutorialimages\/BD-LogicLevelConverter\/an97055.pdf\">Philips AN97055<\/a>\u00a0\u2013 An awesome application note covering bi-directional level shifting circuits.<\/li>\n<\/ul>\n<h3>Going Further<\/h3>\n<p>If you\u2019re looking for a place to use the LLC, these tutorials might spark some ideas:<\/p>\n<ul>\n<li><a href=\"https:\/\/learn.sparkfun.com\/tutorials\/retired---electric-imp-breakout-hookup-guide\">Electric Imp Breakout Hookup Guide<\/a>\u00a0\u2013 The Electric Imp works at 3.3V max, so if you interface it with any 5V systems you may need an LLC.<\/li>\n<li><a href=\"https:\/\/learn.sparkfun.com\/tutorials\/pcduino-hookup-guide\">Getting Started with pcDuino<\/a>\u00a0\u2013 The pcDuino is another 3.3V-based system. This is a powerhouse compared to the Electric Imp, though. It can run Linux or Android, and has all sorts of awesome functionality.<\/li>\n<li><a href=\"https:\/\/learn.sparkfun.com\/tutorials\/using-the-arduino-pro-mini-33v\">Using the Arduino Pro Mini 3.3V<\/a>\u00a0\u2013 If you want to stick with Arduino, and want to use 3.3V sensors, consider using an Arduino that runs at 3.3V. That way you won\u2019t even need to bother with an LLC!<\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Do you have a 3.3V I2C or SPI sensor that might go up in smoke if connected to a 5V Arduino? Or a 5V device that needs a workaround to be compatible with your 3.3V\u00a0Raspberry Pi,\u00a0Arduino Due\u00a0or\u00a0pcDuino? To get over this obstacle you need a device that can shift 3.3V up to 5V or [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[13],"tags":[],"class_list":["post-22141","post","type-post","status-publish","format-standard","hentry","category-13"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6cOVM-5L7","_links":{"self":[{"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/posts\/22141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=22141"}],"version-history":[{"count":1,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/posts\/22141\/revisions"}],"predecessor-version":[{"id":22142,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=\/wp\/v2\/posts\/22141\/revisions\/22142"}],"wp:attachment":[{"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=22141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=22141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tom.tomwork.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=22141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}