cancel
Showing results for 
Search instead for 
Did you mean: 

I NEED to toggle PC13 led with button in stm32f103c6t6

Propiyonat
Associate

I'm a starter in embeded systems and my teacher told me to write a code for this stm32 and add a button to in on breadboard then it needs to toggle with it ( one push on button turn on the light r5 or pc13 and another push to same button turns off the same led ) I'm sure its a easy task to do but as a person don't knows anything about writing a code or work with embeded systems i couldn't find it anywhere i hope someone can help me with that (also i bought a udemy course too but it starts all started its good to learn but i need to do this in hurry. I've been working on it like 2 or 3 days and how fast im complete how good its going) Thanks All Of You !!!WhatsApp Görsel 2025-06-02 saat 20.01.47_70f33385.jpg

8 REPLIES 8
Andrew Neil
Super User

That's a so-called "BluePilll", so (almost) certainly contains a fake STM32.

Your teacher would do better to get you Nucleo boards - which come complete with a button, and a built-in ST-Link.

 


@Propiyonat wrote:

 I'm sure its a easy task to do but as a person don't knows anything about writing a code or work with embeded systems i couldn't find it anywhere


If you're in an embedded class, and you don't understand the task, then you need to ask your teacher for help - that's what they're there for!

The teacher won't have given an exercise that's beyond what's been taught in the class.

There are three key parts to your task:

  1. turn an LED on/off;
  2. detect when a button is pressed;
  3. put those 2 together to make the LED light when the button is pressed.

Have you managed to do any of them?

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.

Dude its not really a class we have teknofest to work to do and my master to learn me to do this give me this project for me to learn so i've been resarching like decades and couldn't find it anywhere i'm not sure even he knows info about this but i need to do this so can anyone help me or not ? ( And yeah ve have this and also nucleo too because of i'm working on it i don't know anything about it and i can blow it up by some chance and nucleo boards not a cheap option to me to work on it as person who don't know anythink about it ) 

you can read...?

https://letmegooglethat.com/?q=toggle+PC13+led+with+button+in+stm32f103

->

https://www.engineersgarage.com/push-button-and-led-with-stm32f103/

 

+

The cpu on your blue-pill looks genuine, as far as i can see it on your pic, so it should work with an st-link .

If you feel a post has answered your question, please click "Accept as Solution".

not an another led . led on board which is connected to pc13 which is blue (there is only 2 leds red and blue) i mean.

so..you cannot read.

in the link -> the led to pin#pc-13

If you feel a post has answered your question, please click "Accept as Solution".

WhatsApp Görsel 2025-06-02 saat 22.19.38_74228bcd.jpg

Toggle LED on PC13

     GPIO_InitTypeDef GPIO_InitStruct = {0};

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

     /*Configure GPIO pin : PC13 LED */
     GPIO_InitStruct.Pin = GPIO_PIN_13;
     GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
     GPIO_InitStruct.Pull = GPIO_NOPULL;
     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
     HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

    while(1) {
        HAL_GPIO_Toggle(GPIOC, GPIO_PIN_13);
        HAL_Delay(500);
    }


Add code to change PC13 based on buttons

     GPIO_InitTypeDef GPIO_InitStruct = {0};

     /* GPIO Ports Clock Enable */
     __HAL_RCC_GPIOB_CLK_ENABLE();

     /*Configure GPIO pin : PB0 / PB1 for buttons to GROUND */
     GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1;
     GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
     GPIO_InitStruct.Pull = GPIO_PULLUP;
     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
     HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

    while(1) {
        if (!HAL_GPIO_ReadPin(GPIOB,  GPIO_PIN_0)) // PB0 = LOW, BUTTON PRESSED
          HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET)); // LOW = LED ON

        if (!HAL_GPIO_ReadPin(GPIOB,  GPIO_PIN_1))
          HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET));
    }
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

That looks like true but i think i couldnt get where these codes am i gonna write so im working on it thanks