2025-06-02 10:03 AM
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 !!!
2025-06-02 10:15 AM
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:
Have you managed to do any of them?
2025-06-02 10:34 AM
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 )
2025-06-02 10:50 AM - edited 2025-06-02 10:52 AM
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 .
2025-06-02 11:40 AM
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.
2025-06-02 12:17 PM
so..you cannot read.
in the link -> the led to pin#pc-13
2025-06-02 12:20 PM
2025-06-02 12:23 PM
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));
}
2025-06-02 1:04 PM
That looks like true but i think i couldnt get where these codes am i gonna write so im working on it thanks