# STM32F103 PC13 on Output mode not work

I using STM32F103C8, I want to use PC13 in GPIO mode (RTC is active). The register ODR13 changes, but the logical value of the PIN does not change.

static void MX_GPIO_Init(void)
{

GPIO_InitTypeDef GPIO_InitStruct;

/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();

/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);

/*Configure GPIO pin : LED_Pin */
GPIO_InitStruct.Pin = LED_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);

}


I read manual this chip, This pin current limited

1. PC13, PC14 and PC15 are supplied through the power switch. Since the switch only sinks a limited amount of current (3 mA), the use of GPIOs PC13 to PC15 in output mode is limited: the speed should not exceed 2 MHz with a maximum load of 30 pF and these IOs must not be used as a current source (e.g. to drive an LED).

But I did not connect to the place

• Disclaimer: I never used HAL, so I don't know what I'm saying. But a bit of research brought this: community.st.com/s/feed/0D50X00009XkW3eSAF. – dim Nov 21 '18 at 8:09
• Clock of the GPIO port is enabled? – Bence Kaulics Nov 21 '18 at 12:19
• Yes output is enable – Hamed Nov 21 '18 at 12:21

I use this pin in INPUT Mod and for change state pull-down or pull-up for set or reset state ,This method works

  /*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = LED_G_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(LED_G_GPIO_Port, &GPIO_InitStruct);


for change state :

HAL_GPIO_WritePin(LED_G_GPIO_Port, LED_G_Pin, [GPIO_PIN_SET or RESET]);


Note : I use mosfet for turn ON/OFF LED this pin just suuport 3mA

simulate this circuit – Schematic created using CircuitLab

• This is not a good answer. Your circuit may work to a degree, given the voltage drop on the resistor leaves some headroom to establish a a Vgs, but your FET and LED are in the wrong places. Ground the source, put the LED above so that you have a low side switch topology. You probably don't even need the FET at all, if the LED current is reasonably low and you wire the LED and its resistor between the pin and the supply so that you are sinking current rather than sourcing it. – Chris Stratton Nov 21 '18 at 14:23

I assume that you are using the blue pill for this project Here is my toggle code it is sort of like the Arduino blink sketch and it toggles the pin on each passing in other words frist time in the loop it will switch the LED on the second time in the loop it will turn off the LED



HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); //Toggle the state of pin PC13
HAL_Delay(100);
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_11);
HAL_Delay(100);
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_0);
HAL_Delay(100);
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_6);
HAL_Delay(100);
HAL_Delay(1000);



There is nothing wrong with the answers above except that I only connected the LED to the pin on the one side and a resistor on the other for all the pins i used above except PC13 as that is the built in LED on the Blue pill version that I have and I cannot find any schematic that actually shows any other components related to driving the LED

EDIT: I quickly tried it and yes Chris Stratton syncing current rather than sourcing Meaning the led is connected to 3.3V from the regulator and the pin has to pull down to GND in order to switch on the LED