cancel
Showing results for 
Search instead for 
Did you mean: 

GPIO change Mode without losing the charge

THein.3
Associate II

Hello everybody,

I'm trying to get from a pulled up state / driven up state to a tristate pin without losing the charge that is on that pin.

It seems to me, that whenever a pullup is deactivated (PUPDR), that STM32 will first discharge the pin and then enter the tristate.

The same happens when changing the mode (MODER) from (high-)driven output to tristate input. Also the pin gets discharged first and then floats from 0V to some 120mV or so within some seconds...

 

I've tried STM32F401, STM32F103, STM32L152 ... they all behave the same, unfortunately.

 

Do you know of any way to get from a high pin to a tristate pin without the pin being discharged first? So that the pin floats at 3V ? 

Thank you and best regards

6 REPLIES 6
Andrew Neil
Super User

@THein.3 wrote:

It seems to me, that whenever a pullup is deactivated (PUPDR), that STM32 will first discharge the pin and then enter the tristate.

The same happens when changing the mode (MODER) from (high-)driven output to tristate input. Also the pin gets discharged first and then floats from 0V to some 120mV or so within some seconds...


Please show how you determine this - both software and hardware.

Some scope traces would help.

Be sure to use your oscilloscope's screen capture facility - rather than trying to photograph the screen.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
Ozone
Principal II

> It seems to me, that whenever a pullup is deactivated (PUPDR), that STM32 will first discharge the pin and then enter the tristate.

What exactly you mean is discharged there, and where is the problem ?

There is nothing except parasitic capacitors on the die, and what you see on the scope is almost certainly an artifact of the scope itself.

Hi Andrew,

here is the code (everything standard / untouched, except for lines 34 to 43):

int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  uint32_t pupdr_low = GPIOA->PUPDR;
  uint32_t pupdr_high = pupdr_low | 1;
  while (1)
  {
    /* USER CODE END WHILE */
    HAL_Delay(10000);
    GPIOA->PUPDR = pupdr_high;

    HAL_Delay(100);
    GPIOA->PUPDR = pupdr_low;

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

 So Pullup on PA0 gets activated for 100ms and then turned off for 10s.

Here is what Saleae (analoge) sees:

THein3_0-1759403289895.png

... no surprise there ;) 

Measuring with my multimeter, I see the same, except it is very obvious, that I'm starting at 0V and then slowly crawling to 100mV when the next pullup-cycle comes around, jumps to 3.3V and then back to 0V :(

 

Thank you.

THein.3
Associate II

Line 33 is of cause also from me ;)

You haven't shown your test hardware setup - Schematics; some good, clear photos.

The Saleae trace doesn't really show the reported "floats from 0V to some 120mV or so within some seconds" behaviour - can you show something more detailed?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
CTapp.1
Senior III

What exactly are you trying to achieve?

An output pin that's tristate will just float, unless you have something else on the line (such as a resistor network) to define the voltage.

Any leakage current (to/from the STM, a 'scope or meter, another input) will cause it to wander all over the place.

You're not going to get it to float at 3v.

All posts are made in a personal capacity
MISRA C++ Chair
MISRA C WG Member
Director The MISRA Consortium Limited (TMCL)