{"id":8989,"date":"2014-12-21T01:53:14","date_gmt":"2014-12-21T06:53:14","guid":{"rendered":"http:\/\/embedded-lab.com\/blog\/?p=8989"},"modified":"2016-12-18T19:46:16","modified_gmt":"2016-12-19T00:46:16","slug":"xmega-io-ports","status":"publish","type":"post","link":"https:\/\/embedded-lab.com\/blog\/xmega-io-ports\/","title":{"rendered":"XMega I\/O Ports"},"content":{"rendered":"<p>Any microcontroller must have I\/O pins for taking inputs and providing outputs. The ATXMega32A4U just like any other micro has 34 programmable I\/O pins divided unevenly amongst six IO ports. Most I\/O ports are 8 bit wide. XMega I\/Os have digital, analog and special purpose functions. Some I\/O pins have more than one use. A quick view of the XMega I\/O pins reveals the purpose of these pins.<\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/xmega-interior\/\" rel=\"attachment wp-att-8991\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-8991 aligncenter\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/XMega-Interior.png\" alt=\"XMega Interior\" width=\"611\" height=\"665\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/XMega-Interior.png 611w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/XMega-Interior-550x598.png 550w\" sizes=\"auto, (max-width: 611px) 100vw, 611px\" \/><\/a><\/p>\n<p><span style=\"font-size: 0.95em;line-height: 1.6em\"><!--more-->I have always admired Atmel\u2019s documentations, particularly datasheet and reference manuals. They are highly user friendly and when it comes to XMega\u2019s documentations, there is one word I can say \u201cAwesome\u201d. The reference manuals and documentations of XMega devices come in colours, legends and bookmarks and so navigating these docs is pretty easy provided that one knows how to use PDF reader like the Adobe Reader efficiently.<\/span><\/p>\n<p>XMega devices are not same as Mega\/Tiny AVRs. People who have been using Mega\/Tiny AVR will find similarities but not monotony. In Mega\/Tiny AVRs there are basically three registers to make an I\/O pin\/port work and these are <b><i>DDRx<\/i><\/b>, <b><i>PINx<\/i><\/b> and <b><i>PORTx<\/i><\/b> registers. In XMega devices this concept is expanded, allowing more options in designs and coding. People who had played with ARM micros will also find some interesting similarities. Trust me I played with STM32 and AVR micros and I found some striking similarities. These similarities are as such that I can literally anticipate what I\u2019ll find next when I proceed. One such similarity is the alternate function of an I\/O pin. This basically allows general purpose I\/O pins to do stuffs other than the basic use as a general purpose I\/O. Pin remapping is another feature that is common in both XMega and ARM micros. Unlike traditional micros which have dedicated pins for certain internal hardware modules like USART, I2C, SPI, etc. both XMegas and ARMs have an option to relocate dedicated hardware pins from one pin\/port position to another. Thus hardware designing become more flexible and easy. It is just why we feel comfortable making stuffs with embedded systems rather than using complex discrete mixed analog-digital circuits. Just imagine, by mistake you wired USART pins wrongly in your design but those I\/O port pins\u2019 can be alternatively used as USART pins. This is where you get saved by pin remapping rather than remaking the entire hardware stuff or even making cuts and rewires in the PCB. In a sense pin remapping is a hardware level coding rather than software level coding though this remapping is itself done with a few lines of code.<\/p>\n<p>Before we proceed, I would like to remind readers that in my previous post I stated that Atmel\u2019s software library support allow AVR studio users to code more easily as their header file replaces constants with meaningful names and purposes. As of now MikroC for AVR doesn&#8217;t enjoy the fruits offered by Atmel. I realized that I should adopt this feature in MikroC to save both time and efforts, and so I made my own header files containing these constants. Once we enter the code arena we\u2019ll understand how these files come to work. At the time of writing I have just made two such headers \u2013 one for the clock system which I previously explained and the other for I\/O ports as this will be needed here. I&#8217;m expanding the collection of such header files on hardware basis and hopefully I&#8217;ll share them in the upcoming posts.<\/p>\n<h2>I\/O Pin Configurations<\/h2>\n<p>I\/O pins in XMega devices have more than the usual general purpose input\/output functionality. Shown below are the six possibilities. Wired-AND, Wired-OR and Bus-keeper configurations have limited uses while Totem-pole I\/Os are mostly used.<\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/io-configurations\/\" rel=\"attachment wp-att-8992\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8992\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/IO-Configurations.png\" alt=\"IO Configurations\" width=\"624\" height=\"522\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/IO-Configurations.png 624w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/IO-Configurations-550x460.png 550w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Any XMega reference manual\/datasheet briefly describes I\/O port configurations but those descriptions are not enough to completely get ideas on how they behave in real world applications. Some people even get confused with the nomenclature of the configurations.<\/p>\n<ul>\n<li><b><b><i>Totem-pole I\/O.<br \/>\n<\/i><\/b><\/b>In general a totem-pole I\/O is a push-pull type I\/O. There is no limit for current source or sink with this configuration except the concerned I\/O pin\u2019s maximum current-handling capacity of 20mA. For better understanding on it refer to: <a href=\"http:\/\/en.wikipedia.org\/wiki\/Totem_pole_output\">http:\/\/en.wikipedia.org\/wiki\/Totem_pole_output<\/a>.<\/li>\n<li><b><b><i>Totem-pole I\/O with Pull Up or Pull Down.<br \/>\n<\/i><\/b><\/b>These are same as Totem-pole I\/Os but with internal pull resistors for input side only. These configurations are handy for taking inputs from switches and other incoming signal sources.<\/li>\n<li><b><b><i>Bus-Keeper.<br \/>\n<\/i><\/b><\/b>In this configuration an input pin latches its last known logic state-high\/low even after it went floating. For more info refer to: <a href=\"http:\/\/en.wikipedia.org\/wiki\/Bus-holder\">http:\/\/en.wikipedia.org\/wiki\/Bus-holder<\/a>.<\/li>\n<li><b><b><i>Wired-AND and Wired-OR.<br \/>\n<\/i><\/b><\/b>These two configurations form wired-logic gates which have a number of purposes. According to Atmel\u2019s documentations these configurations are useful when directly connecting two physical I\/O pins together. Suppose a GPIO pin is at high logic level and the other is at low logic level then there\u2019ll be a high short circuit current through them. To avoid this situation internal pull resistors are used instead of FET stages to reduce this current. These configurations also behave like real AND and OR gates with respect to their pins. For instance in the Wired-OR configuration, the I\/O pin will be at logic high either if it is driven externally high <i>or <\/i>if its OUT register is set <i>or<\/i> if in both ways it is set high. Similarly Wired-AND configuration behaves like an AND gate. For more info check this out: <a href=\"http:\/\/en.wikipedia.org\/wiki\/Wired_logic_connection\">http:\/\/en.wikipedia.org\/wiki\/Wired_logic_connection<\/a>.<span style=\"font-size: 0.95em;line-height: 1.6em\">\u00a0<\/span><\/li>\n<\/ul>\n<h2>Registers<\/h2>\n<p>I\/O ports are named as PORTA, PORTB, etc. while individual port pins are named as PA6, PB4, etc. There are similarities with both older AVRs and ARMs in terms of naming ports and individual I\/O pins.<\/p>\n<ul>\n<li><b><i>DIR<\/i><\/b> registers are responsible for setting data direction of a port or its individual pins. They are just like the <b><i>DDR<\/i><\/b> registers of Mega\/Tiny AVRs. Setting <b><i>DIR<\/i><\/b> register bits makes corresponding port pins outputs while clearing them makes port pins inputs. There are three more registers that can directly set, clear or toggle <b><i>DIR<\/i><\/b> register contents. These are <b><i>DIRSET<\/i><\/b>, <b><i>DIRCLR<\/i><\/b> and <b><i>DIRTGL<\/i><\/b>.<\/li>\n<li><b><i>OUT <\/i><\/b>registers are responsible for driving port pins high or low. Again these registers have set, clear and toggle registers associated with them as <b><i>OUTSET<\/i><\/b><i>,<b> OUTCLR <\/b><\/i>and<b><i> OUTTGL <\/i><\/b>to make things easier and faster.<\/li>\n<li><b><i>IN<\/i><\/b> registers can read the logic state of an I\/O port pins no matter if the pins are set as outputs or inputs unless input buffers are disabled by coding.<\/li>\n<li><b><i>PINnCTRL<\/i><\/b> registers are registers that are dedicated for individual I\/O pins. These registers control the properties of each pins individually. These properties select pull resistors, pin I\/O type, slew rate and pin inversion. Please refer to page 151 \u2013 153 of the XMega AU reference manual for details. Usually they are used in a code like this after setting <b><i>DIR<\/i><\/b> registers:<br \/>\n<i><br \/>\nPORTD_PIN1CTRL = (PORT_OPC_BUSKEEPER_gc | PORT_ISC_BOTHEDGES_gc);<br \/>\n<\/i><i>PORTC_PIN4CTRL = (PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc);<\/i><\/li>\n<\/ul>\n<ul>\n<li><b><i>MPCMASK <\/i><\/b>register is used to configure multiple pins with same properties. This ensures lesser code and swift operation. As its name suggests it a mask register and so only the bits set in this register will get configured similarly. To use it first set this register mask as per need and then configure any I\/O pin within the mask to get others configured too. Any unmasked pin can also be used and it will remain unaffected but I strongly suggest to use only the masked ones to avoid unnecessary confusion. For instance:<\/li>\n<\/ul>\n<p><i style=\"font-size: 0.95em;line-height: 1.6em\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0PORTCFG_MPCMASK = 0xFF;<br \/>\n<\/i><i>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0PORTA_PIN6CTRL = (PORT_OPC_TOTEM_gc | PORT_ISC_BOTHEDGES_gc);<\/i><\/p>\n<ul>\n<li><b><i>CLKEVOUT<\/i><\/b> register is for outputs related to clock, internal RTC and event system. I guess we already met it in my previous post on XMega. This register just sets which port pin to use to get output from those hardware.<\/li>\n<li><b><i>VPCTRLx <\/i><\/b>and realted-register pairs control virtual port mapping. The I\/O instruction set in AVR MCUs can only operate within the AVR I\/O space. Using these instructions instead of their data space equivalents is both efficient in terms of code execution time and program memory. All XMega I\/O port registers have addresses outside the I\/O space. Thus we can use virtual ports. Usually there are four such virtual ports and just like I\/O ports they too have <b><i>DIR, IN <\/i><\/b>and<b><i> OUT<\/i><\/b> registers.<\/li>\n<li>There are other register related to I\/O ports. These include interrupt-related register, event system, EBI output, etc. I\u2019ll explain them in my later posts when I deal with the related hardware.<span style=\"font-size: 0.95em;line-height: 1.6em\">\u00a0<\/span><\/li>\n<\/ul>\n<h2>Code Examples<\/h2>\n<p>As I stated earlier, I made up header files for the required hardware \u2013 clock and I\/O. In all of the code examples I used them because they make coding easier to understand rather than a bunch of meaningless hexadecimal numbers for each register to be configured and also save precious time configuring them every time when required. The codes themselves are thus self-explanatory. Please be sure to add the files <b><i>io.h<\/i><\/b> and <b><i>clock.h <\/i><\/b>with Project Manager when making new codes if you are using my header files or otherwise MikroC compiler will throw tons of errors. Of course we can use raw level coding too without using those header files. It is up to the coder. I made my header files and so can you make your too. In all examples, the CPU is running at 8MHz.<\/p>\n<p>There are six examples and these are:<\/p>\n<ul>\n<li><b><b><b><i>XMega Basic IO &#8211; Totem-pole Output<br \/>\n<\/i><\/b><\/b><\/b>In this example we just blink some LEDs and test the totem-pole output capability.<\/li>\n<\/ul>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/totem-pole\/\" rel=\"attachment wp-att-8998\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8998\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/totem-pole.png\" alt=\"totem-pole\" width=\"959\" height=\"384\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/totem-pole.png 959w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/totem-pole-550x220.png 550w\" sizes=\"auto, (max-width: 959px) 100vw, 959px\" \/><\/a><b><b>Code:<\/b><\/b><\/p>\n<p><i><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/code-1\/\" rel=\"attachment wp-att-9028\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9028\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-1.png\" alt=\"Code 1\" width=\"911\" height=\"763\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-1.png 911w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-1-550x460.png 550w\" sizes=\"auto, (max-width: 911px) 100vw, 911px\" \/><\/a><\/i><\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/20140817_190708\/\" rel=\"attachment wp-att-9000\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-9000\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140817_190708-1024x566.jpg\" alt=\"20140817_190708\" width=\"860\" height=\"475\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140817_190708-1024x566.jpg 1024w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140817_190708-550x304.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140817_190708.jpg 1369w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a> <a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/20140817_190711\/\" rel=\"attachment wp-att-9001\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-9001\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140817_190711-1024x571.jpg\" alt=\"20140817_190711\" width=\"860\" height=\"479\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140817_190711-1024x571.jpg 1024w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140817_190711-550x306.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140817_190711.jpg 1369w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<p><i>\u00a0<\/i><b>Video link:<\/b> <a href=\"https:\/\/www.youtube.com\/watch?v=r44_UjLxLmo\">https:\/\/www.youtube.com\/watch?v=r44_UjLxLmo<\/a>.<\/p>\n<ul>\n<li><b style=\"font-size: 0.95em;line-height: 1.6em\"><b style=\"font-size: 0.95em;line-height: 1.6em\"><b><i>XMega Basic IO &#8211; Inputs with Pull Resistors<br \/>\n<\/i><\/b><\/b><\/b>In this example, we&#8217;ll see the pull-up and pull-down resistors at work when I\/O pins are used as inputs.<\/li>\n<\/ul>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/resistor\/\" rel=\"attachment wp-att-8997\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8997\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/resistor.png\" alt=\"resistor\" width=\"999\" height=\"343\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/resistor.png 999w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/resistor-550x188.png 550w\" sizes=\"auto, (max-width: 999px) 100vw, 999px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/resistor\/\" rel=\"attachment wp-att-8997\"><b style=\"color: #111111;font-size: 0.95em;line-height: 1.6em\"><b>Code:<\/b><\/b><\/a><\/p>\n<p><i><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/code-2\/\" rel=\"attachment wp-att-9029\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9029\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-2.png\" alt=\"Code 2\" width=\"965\" height=\"585\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-2.png 965w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-2-550x333.png 550w\" sizes=\"auto, (max-width: 965px) 100vw, 965px\" \/><\/a> <a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/code-3\/\" rel=\"attachment wp-att-9030\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-9030\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-3.png\" alt=\"Code 3\" width=\"860\" height=\"628\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-3.png 959w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-3-550x402.png 550w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a><\/i><\/p>\n<p><b><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/20140818_214435\/\" rel=\"attachment wp-att-9002\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-9002\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140818_214435-1024x730.jpg\" alt=\"20140818_214435\" width=\"860\" height=\"613\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140818_214435-1024x730.jpg 1024w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140818_214435-550x392.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140818_214435.jpg 1369w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a> <a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/20140818_214441-2\/\" rel=\"attachment wp-att-9010\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-9010\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140818_2144411-1024x769.jpg\" alt=\"20140818_214441\" width=\"860\" height=\"645\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140818_2144411-1024x769.jpg 1024w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140818_2144411-550x413.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140818_2144411.jpg 1366w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a> <a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/20140818_214446-2\/\" rel=\"attachment wp-att-9011\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-9011\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140818_2144461-1024x780.jpg\" alt=\"20140818_214446\" width=\"860\" height=\"655\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140818_2144461-1024x780.jpg 1024w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140818_2144461-550x419.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140818_2144461.jpg 1369w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a>Video link:<\/b> <a href=\"https:\/\/www.youtube.com\/watch?v=M6M4sxEXu70\">https:\/\/www.youtube.com\/watch?v=M6M4sxEXu70<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li><b><b><i>XMega Advanced IO &#8211; Bus-keeper<br \/>\n<\/i><\/b><\/b>In this example we&#8217;ll see how the bus-keeper configuration works. Please note the latching action of the I\/O pin after setting or clearing it and then leaving it to float.<\/li>\n<\/ul>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/bk\/\" rel=\"attachment wp-att-8995\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8995\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/bk.png\" alt=\"bk\" width=\"798\" height=\"436\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/bk.png 798w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/bk-550x300.png 550w\" sizes=\"auto, (max-width: 798px) 100vw, 798px\" \/><\/a><b>Code:<\/b><b>\u00a0<\/b><i><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/code-4\/\" rel=\"attachment wp-att-9031\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9031\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-4.png\" alt=\"Code 4\" width=\"917\" height=\"705\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-4.png 917w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-4-550x422.png 550w\" sizes=\"auto, (max-width: 917px) 100vw, 917px\" \/><\/a><\/i><\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/20140819_121050-2\/\" rel=\"attachment wp-att-9012\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-9012\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_1210501-911x1024.jpg\" alt=\"20140819_121050\" width=\"860\" height=\"966\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_1210501-911x1024.jpg 911w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_1210501-550x617.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_1210501.jpg 1369w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/20140819_121101-2\/\" rel=\"attachment wp-att-9013\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-9013\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_1211011-978x1024.jpg\" alt=\"20140819_121101\" width=\"860\" height=\"900\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_1211011-978x1024.jpg 978w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_1211011-550x575.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_1211011.jpg 1369w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/20140819_121107-2\/\" rel=\"attachment wp-att-9014\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-9014\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_1211071-951x1024.jpg\" alt=\"20140819_121107\" width=\"860\" height=\"926\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_1211071-951x1024.jpg 951w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_1211071-550x591.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_1211071.jpg 1369w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/20140819_121113-2\/\" rel=\"attachment wp-att-9015\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-9015\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_1211131-979x1024.jpg\" alt=\"20140819_121113\" width=\"860\" height=\"899\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_1211131-979x1024.jpg 979w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_1211131-550x574.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_1211131.jpg 1369w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<p><b> Video Link: <\/b><a href=\"https:\/\/www.youtube.com\/watch?v=ed-EHcd5KAo\">https:\/\/www.youtube.com\/watch?v=ed-EHcd5KAo<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li><b><b><b><b><i>XMega Advanced IO &#8211; Virtual Port<br \/>\n<\/i><\/b><\/b><\/b><\/b>As said before Virtual Ports are used for memory specific instructions and are both fast and code efficient in terms of usage. In this example I mapped PORTD with Virtual Port 3 and made a simple seven segment display counter. Thus writing to Virtual Port 3 is same as writing to PORTD.<\/li>\n<\/ul>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/vp-2\/\" rel=\"attachment wp-att-9024\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9024\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/vp1.png\" alt=\"vp\" width=\"813\" height=\"483\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/vp1.png 813w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/vp1-550x326.png 550w\" sizes=\"auto, (max-width: 813px) 100vw, 813px\" \/><\/a><\/p>\n<p><b>Code:<\/b><\/p>\n<p><i><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/code-5\/\" rel=\"attachment wp-att-9032\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9032\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-5.png\" alt=\"Code 5\" width=\"969\" height=\"441\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-5.png 969w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-5-550x250.png 550w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/><\/a> <a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/code-6\/\" rel=\"attachment wp-att-9033\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-9033\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-6.png\" alt=\"Code 6\" width=\"860\" height=\"439\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-6.png 962w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-6-550x281.png 550w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a><\/i><\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/20140819_214352\/\" rel=\"attachment wp-att-9016\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-9016\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_214352-1024x914.jpg\" alt=\"20140819_214352\" width=\"860\" height=\"767\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_214352-1024x914.jpg 1024w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_214352-550x490.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_214352.jpg 1369w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<p><b> Video Link: <\/b><a href=\"https:\/\/www.youtube.com\/watch?v=cEjAGlrYgCc\">https:\/\/www.youtube.com\/watch?v=cEjAGlrYgCc<\/a>.<\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li><b><b><i>XMega Advanced IO &#8211; Wired-OR<br \/>\n<\/i><\/b><\/b>In this example we investigate Wired-OR configuration.<\/li>\n<\/ul>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/or\/\" rel=\"attachment wp-att-8996\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8996\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/or.png\" alt=\"or\" width=\"494\" height=\"485\" \/><\/a><\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/or\/\" rel=\"attachment wp-att-8996\"><br \/>\n<\/a><b>Code:<\/b><\/p>\n<p><i><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/code-7\/\" rel=\"attachment wp-att-9034\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9034\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-7.png\" alt=\"Code 7\" width=\"959\" height=\"763\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-7.png 959w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-7-550x437.png 550w\" sizes=\"auto, (max-width: 959px) 100vw, 959px\" \/><\/a><\/i><\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/20140819_224425\/\" rel=\"attachment wp-att-9017\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-9017\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_224425-958x1024.jpg\" alt=\"20140819_224425\" width=\"860\" height=\"919\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_224425-958x1024.jpg 958w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_224425-550x587.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_224425.jpg 1369w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a> <a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/20140819_224452\/\" rel=\"attachment wp-att-9018\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-9018\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_224452-992x1024.jpg\" alt=\"20140819_224452\" width=\"860\" height=\"887\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_224452-992x1024.jpg 992w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_224452-550x567.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_224452.jpg 1369w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a> <a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/20140819_224456\/\" rel=\"attachment wp-att-9022\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-9022\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_224456-962x1024.jpg\" alt=\"20140819_224456\" width=\"860\" height=\"915\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_224456-962x1024.jpg 962w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_224456-550x584.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_224456.jpg 1369w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a><\/p>\n<p><b>Video Link: <\/b><a href=\"https:\/\/www.youtube.com\/watch?v=T74fPEISz9U\">https:\/\/www.youtube.com\/watch?v=T74fPEISz9U<\/a>.<\/p>\n<ul>\n<li><b><b><i>XMega Advanced IO &#8211; Wired-AND<br \/>\n<\/i><\/b><\/b>In this example we investigate Wired-AND configuration. Please note I tested this configuration with a logic probe instead of a LED as the pull resistor\u2019s resistance is too directly drive a LED.<\/li>\n<\/ul>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/and\/\" rel=\"attachment wp-att-8994\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8994\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/and.png\" alt=\"and\" width=\"497\" height=\"456\" \/><\/a><b>Code:<\/b><\/p>\n<p><i><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/code-8\/\" rel=\"attachment wp-att-9035\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-9035\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-8.png\" alt=\"Code 8\" width=\"943\" height=\"761\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-8.png 943w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/Code-8-550x443.png 550w\" sizes=\"auto, (max-width: 943px) 100vw, 943px\" \/><\/a><\/i><\/p>\n<p><a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/20140819_232700\/\" rel=\"attachment wp-att-9021\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-9021\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_232700-1024x916.jpg\" alt=\"20140819_232700\" width=\"860\" height=\"769\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_232700-1024x916.jpg 1024w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_232700-550x492.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_232700.jpg 1369w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a> <a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/20140819_232651\/\" rel=\"attachment wp-att-9020\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-9020\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_232651-1024x918.jpg\" alt=\"20140819_232651\" width=\"860\" height=\"770\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_232651-1024x918.jpg 1024w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_232651-550x493.jpg 550w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2014\/08\/20140819_232651.jpg 1369w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><\/a> <b>Video Link: <\/b><a href=\"https:\/\/www.youtube.com\/watch?v=QbVIEtwzqqo\">https:\/\/www.youtube.com\/watch?v=QbVIEtwzqqo<\/a>.<\/p>\n<p>Before any confusion start to develop amongst readers regarding the schematic designing tool I used, I would like to inform them that all schematics in this post were made with Proteus VSM. However Proteus VSM doesn\u2019t support XMega chips and so everything that was discussed here were done with real hardware instead of software simulations. Trust me hardware level debugging is more useful than software\/simulation-based debugging.<\/p>\n<p>I hope this post helped people to clear a number of confusions and paved ways for new concepts regarding XMega I\/O port. Trust me I too had a lot of questions before exploring the XMega I\/O ports because info on XMega devices are too scattered and incomplete.<\/p>\n<p>In my final words just like any other post, I\u2019ll recommend readers to go through the XMega AU reference manual at least once. This will seriously help. Keep practicing what you have learnt so far and explore new ideas.<\/p>\n<p>Happy coding.<\/p>\n<p>Files:\u00a0<a href=\"http:\/\/embedded-lab.com\/blog\/xmega-io-ports\/xmega-io-ports-2\/\" rel=\"attachment wp-att-9038\">XMega IO Ports<\/a>.<br \/>\n<i style=\"font-size: 0.95em;line-height: 1.6em\"><br \/>\nAuthor:<\/i><\/p>\n<p>Shawon M. Shahryiar<br \/>\n<a href=\"https:\/\/www.facebook.com\/groups\/microarena\/\"><i>https:\/\/www.facebook.com\/groups\/microarena\/<\/i><\/a><i><br \/>\n<\/i><a href=\"https:\/\/www.facebook.com\/MicroArena\"><i>https:\/\/www.facebook.com\/MicroArena<\/i><\/a><i>\u00a0<\/i><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Any microcontroller must have I\/O pins for taking inputs and providing outputs. The ATXMega32A4U just like any other micro has 34 programmable I\/O pins divided unevenly amongst six IO ports. Most I\/O ports are 8 bit wide. XMega I\/Os have digital, analog and special purpose functions. Some I\/O pins have more than one use. A quick view of the XMega I\/O pins reveals the purpose of these pins.<\/p>\n","protected":false},"author":5,"featured_media":8991,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1466,792],"tags":[799,644,807,800,11,312],"class_list":["post-8989","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","category-xmega","tag-advanced-embedded-systems","tag-atmel","tag-atxmega","tag-atxmega32a4u","tag-avr","tag-mikroc-for-avr"],"_links":{"self":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/8989","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/comments?post=8989"}],"version-history":[{"count":22,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/8989\/revisions"}],"predecessor-version":[{"id":12849,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/8989\/revisions\/12849"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media\/8991"}],"wp:attachment":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media?parent=8989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/categories?post=8989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/tags?post=8989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}