cancel
Showing results for 
Search instead for 
Did you mean: 

why my hal delay function working weird?

qqwq.1
Associate II

Hi all,

This is my first time in stm32 mcu's and since today i struggled to manage to install all needed software to my old win7 pc. Finally at 2am i managed to success. Then after desided to program my bluepill quick before go to sleep. I started with blink program using hal_delay function. but it seems it works reverse for some reason.

This is my ide code;

while (1)
  {
    /* USER CODE END WHILE */
	  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);
	  HAL_Delay(4000);
	  HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
	  	  HAL_Delay(1000);
    /* USER CODE BEGIN 3 */
  }

The problem is when above code generated and uploaded to stm32f103 , led turn on for 1sec and turn off for 4 seconds(if i manage to see the led correctly ). But i thought it must be reverse. Mean, must turn on for 4 sec and off for 1 sec, correct me if im wrong ?

This is just a simple blink pc13 pin on bluepill nothing more but it seems im doing something wrong with it that i couldnt understand.

Here are my ioc file looks like;
_legacyfs_online_stmicro_images_0693W00000bkzmzQAA.png
_legacyfs_online_stmicro_images_0693W00000bkzmuQAA.png

1 ACCEPTED SOLUTION

Accepted Solutions
NEdom.1
Associate III

Try to initialize this GPIOC, GPIO_PIN_13 to HIGH and LOW state individually. If this pin is initialized HIGH and LED off, with LOW and LED on, the check your code. If PC13 initialized HIGH and LED is on, the your Bluepill's user LED is not working in sink mode. It is working in source mode.

According to Bluepill schematic, the user LED at PC13 is sink mode. Your code should work fine with it.

View solution in original post

2 REPLIES 2
NEdom.1
Associate III

Try to initialize this GPIOC, GPIO_PIN_13 to HIGH and LOW state individually. If this pin is initialized HIGH and LED off, with LOW and LED on, the check your code. If PC13 initialized HIGH and LED is on, the your Bluepill's user LED is not working in sink mode. It is working in source mode.

According to Bluepill schematic, the user LED at PC13 is sink mode. Your code should work fine with it.

S.Ma
Principal

Check the board schematic and know if the LED turns on at high or low level (active high or low).

You can go debug mode, run the code few seconds, then hold it and manually change the GPIO out register if needed play and get a feel for it.