0
\$\begingroup\$

I have a microcontroller that enables an IC. This IC would be enabled when a logic 0 is set in its enable input pin. So, one microcontrollers' GPIO is connected to that pin. My question is, before initialization of all the GPIOs, they are not set to any value. So, maybe, before setting a logic 1 in that GPIO to start with disabled state of my system before GPIO initialization there is another default value. If that value is a low level value, the MCU would enable the IC during a short period of time. How can I know which is the default state of GPIO (before initialization)? How can I find this in the MCU's datasheet? And how I avoid this to happen in case the default state is a logic 0.

Datasheet

\$\endgroup\$
3
  • \$\begingroup\$ During power-up there is always an unmanaged period where design thresholds can't be and aren't within management by the design. At some point, things are managed fairly well and the behavior can be better specified. But before that point, nothing much can be said about the instantaneous impedance. It's likely (I think most MCU designers work towards this shared goal) that general purpose I/O pins do, once within design management, exhibit a high-z prior to being configured by software. Before that point of management though, there may be unspecified and erratic-z. \$\endgroup\$ Sep 28 at 6:52
  • \$\begingroup\$ You are saying they leave them as HiZ (with erratic behaviour in any design during power-up), other comment is saying they leave them as inputs and another says they leave it like an output with logic 0 hahaha I am bit lost now. Thank you anyways. \$\endgroup\$ Sep 28 at 7:11
  • \$\begingroup\$ Nothing to be confused about. Most people just take them as high-z prior to configuration and move on. But at the microscopic level and when looking closely during the early part of power-up, the reality is vastly more complex. Oh, well. What else did you expect? \$\endgroup\$ Sep 28 at 7:20

4 Answers 4

5
\$\begingroup\$

Figure 8.5 on page 62 of your data sheet shows 'GPIO pins as inputs with pullups disabled' after power up when \$\overline{XRS}\$ (the active low system reset) is asserted, before the user code starts running.

enter image description here

However, immediately following power up, there is a short period when the I/O pins are undefined, shown by the cross hatching. This does not guarrantee that they are Hi-Z, or outputting any particular state, so this diagram does not give you the assurance you want. However ...

\$\overline{XRS}\$ is stated on page 34 to be an output, and this diagram shows it staying low for the whole duration of power being applied. You can therefore use this low state to qualify the I/O, so that it's in a known state at all times.

Use a pulldown on your MCU output pin 'GPIO_peripheral_enable' so that it's low when powered off, low during most of the MCU powering-on state, and low when still not yet configured as an output. It only goes high when your code configures it as an output, and sets it high.

Now put \$\overline{XRS}\$ and 'GPIO_peripheral_enable' into a NAND gate, with its output going to your peripheral's \$\overline{ENABLE}\$ pin.

\$\endgroup\$
3
  • \$\begingroup\$ This is exactly what I was looking for. Just two things. Why when the MCU is not powered there is no HiZ in the GPIOs? And if you use an inverter (with a pull down in this case as you first stablished) the output of the inverter chip could be 0 again before power-up (due to ESD diodes or whatever, like you said for the microcontroller), enabling the IC again. I mean, the problem still be the same adding or not the inverter, right? \$\endgroup\$ Sep 28 at 7:23
  • \$\begingroup\$ @DevelopingElectronics answer now modified somewhat \$\endgroup\$
    – Neil_UK
    Sep 28 at 9:52
  • \$\begingroup\$ @Neil_UK Thanks for doing the legwork. +1 I was way too lazy to bother. \$\endgroup\$ Sep 28 at 21:35
3
\$\begingroup\$

How can I find this in the MCU's datasheet?

You could try Ctrl + F for 'initial state' or 'startup state' and similar terms.

I think it is usual for pins to come up tristated or as inputs, i.e. neither high nor low, but driven from the periphery.

And how I avoid this to happen in case the default state is a logic 0.

You could place a pull-up resistor. Also consider an additional pull-up capacitor. The latter helps keeping static current consumption low when on, because it will guarantee that the line stays high during startup even with very large pull-up resistors (e.g. >1 MΩ).

\$\endgroup\$
3
  • \$\begingroup\$ This is the datasheet: ti.com/lit/ds/symlink/… Those filters in Ctrl+F did not work for me. I couldn't find anything. Im scared that the GPIO starts like a logic 0, so even a pullup wouldn't avoid undesired enabling. \$\endgroup\$ Sep 28 at 6:46
  • 1
    \$\begingroup\$ And I did not understand really well the need of a pull-up capacitor. Thanks \$\endgroup\$ Sep 28 at 6:46
  • \$\begingroup\$ A large pull-up capacitor forces the line to VDD, even if the pin boots as a LO output (which is unusual), because it will have to charge the capacitor first to bring the line LO. @DevelopingElectronics \$\endgroup\$
    – tobalt
    Sep 28 at 10:01
3
\$\begingroup\$

All registers in all microcontrollers have a default value out of reset. This is described in the specific register documentation. You cannot possibly miss it if you ever read any MCU manual about any specific register. Here's from a random manual for an SAM Cortex M:

enter image description here

The "Reset: 0" unsurprisingly meaning that the corresponding bit is set to zero out of reset. 0 is the overwhelmingly most common reset value for GPIO ports and data direction registers, because it is the setup leading to the lowest current consumption (even though leaving the pins as inputs make them more vulnerable to EMI).


How can I find this in the MCU's datasheet?

Please note that it is not uncommon that the manufacturer creates two documents:

  • The datasheet, intended for the electrical engineer doing the PCB design
  • The user manual, intended for the software engineer writing the program.

In case the manufacturer of your specific part chose the above way of documentation, then you can stare at the datasheet as long as you like because the information isn't there - it is in the user manual.

Generally it is the software engineer's responsibility to make signal pin-outs and determine which pins that need external pull resistors, external ground etc.

\$\endgroup\$
2
  • \$\begingroup\$ So, I understand that in the first instance (before initialization or after reset) they usually are set like a 0, like you said. One reason is that leaving them as inputs by default during that tiny period of time would result in worse behaviour in terms of EMI. I understood that, but, why is not better to leave them (I mean, the designers from the MCU) as high impedance? If they are a logic 0, as you said, that would enable my IC during nanoseconds even with an external pullup as other member answered before. \$\endgroup\$ Sep 28 at 7:09
  • \$\begingroup\$ Not sure about the SAM Cortex M, but most MCUs have a mode register as well and you have to consider that reset value before looking at the out register - the out register is meaningless if the pins are configured as input in the mode register. But essentially this answer is right - you are looking at the wrong document, you need to look at the Technical Reference Manual, there you will find the reset for the DIR registers, which are all 0 and so input, so just place a pull-up and make sure your initialization code never switches it to output 0, when you don't want it. \$\endgroup\$
    – Arsenal
    Sep 28 at 7:57
2
\$\begingroup\$

You don't say which microcontroller you use, but there must be a section in the datasheet that explains how GPIO pins work and what are the defaults, not all pins are equal as some may be used for e.g. debugging so they are already initialized to certain use during and after reset. Sometimed the detailed settings are in another document such as reference manual.

Generally you would look for GPIO pin section in the data sheet index and failing to find that you use the search functionality of the PDF reader to find keywords such as "gpio" or the specific pin name.

Most general pins are inputs so they don't have any state unless defined by external circuit so pins are not outputs that drive high or low. So floating pins are undefined.

So if you want to be sure what the state is before the MCU initializes the pin as output with correct state, you add external circuit such as a resistor to keep the pin at required level until MCU takes control of the pin.

\$\endgroup\$
2
  • \$\begingroup\$ This is the URL for the datasheet: ti.com/lit/ds/symlink/… I couln't find anything there. So, your reply means that almost all GPIO are inputs, so, before initialization they are in HiZ state, right? \$\endgroup\$ Sep 28 at 6:44
  • \$\begingroup\$ @DevelopingElectronics I can't say if that is true to your MCU and your IO pin, but generally it is safe to assume that MCU IO pins are in high-impedance state and are not outputs. In some cases they are not even inputs until you configure them, they are just completely disconnected and floating. \$\endgroup\$
    – Justme
    Sep 28 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.