Maker Pro
Maker Pro

STM32F103C8T6 PC13 LED

Evaldas22

Oct 3, 2017
12
Joined
Oct 3, 2017
Messages
12
Hello, I'm currently learning to program STM32 microcontroller and for the first project, I chose to do blinking LED. I wrote short code and the on-board LED connected to pc13 was blinking. But then I wanted to add another LED to it(same pc13 pin) and then I noticed that both LEDs take turns when blinking. It goes like this: on_board LED ON - external LED OFF, on-board LED OFF - external LED ON and so on.
Then I noticed that when I set pc13 bit ('1'), on-board LED is OFF and external LED is ON and vice-versa. I then unplug external LED and observe the same results.
My question is why when I set pc13 bit ON, on-board LED stays LOW, but external LED lights up?? It seems like the pc13 on-board LED is inverted or something like that.

Code:
#include "stm32f1xx.h" // main library for MCU

void delay_ms(int ms);

int main(void)
{
    //Enable the GPIO(PortC)
    RCC ->APB2ENR |= RCC_APB2ENR_IOPCEN;
    // Set any Control Registers for Port C Pin 13
    GPIOC ->CRH &= ~(GPIO_CRH_CNF13); // making CNF13 '00' 
    GPIOC ->CRH &= ~(GPIO_CRH_MODE13_1); // making Mode13 as '01' - output mode, max speed 10 MHz
    GPIOC ->CRH |= GPIO_CRH_MODE13_0; // making Mode13 as '01' - output mode, max speed 10 MHz

    //Make default state of port C pin 13 = '0'
    GPIOC ->BSRR = GPIO_BSRR_BR13;
    while(1)
    {
        //Turn on LED (BSRR)
        GPIOC ->BSRR |= GPIO_BSRR_BS13;
        //Wait
        delay_ms(200000);
        //Turn off LED(BRR)
        GPIOC ->BSRR |= GPIO_BSRR_BR13;
        //Wait
        delay_ms(200000);
    }
}

void delay_ms(int ms) // this will wait x milliseconds - x * 1000 ticks
{
    for (int i = 0; i < ms; ++i) { }
}
 

Attachments

  • IMG_1.JPG
    IMG_1.JPG
    240.1 KB · Views: 125
  • IMG_2.JPG
    IMG_2.JPG
    229.9 KB · Views: 134
  • IMG_3.JPG
    IMG_3.JPG
    220.2 KB · Views: 115
Top