I am a very newbie in microcontroller and the embedded world, so I started with trying to code a blinking programme in stm32 using basics registers and all, finally, I got it to blink, but then I found that whenever the pin pc13 is high the built-in led is off but on when pc13 is low (exactly reversed!), I don't know why I even added an external led to check whether I am right or not and I am right (in doubting it's working) the external led is on whenever builtin is off and vice versa, please help???? my code is : (my board is STM32F103C8 64KB FLASH, STM32_SMART BOARD)
#include "stm32f10x.h" // Device header
void delay(int rep);
int main(void)
{
RCC->APB2ENR |= 0x10; /// Or 0b10000 --> Anabling Preiph GPIOC
GPIOC->CRH &= 0xFF0FFFFF; /// Reset the PORT C PIN 13
GPIOC->CRH |= 0x00300000; /// Set Port C PIN 13 as Output
GPIOC->ODR |= 0x2000; /// Set Port C Pin 13
while(1)
{
/// Blinking the Port C pin 13
GPIOC->ODR |= 0x2000;
delay(10000000);
GPIOC->ODR &= ~0x2000;
delay(10000000);
}
}
/// Random time delay Function
void delay(volatile int a) {
//Added volatile in a and in i
for (volatile int i = 0; i < a; i++);
}