Last active
October 7, 2018 20:28
-
-
Save ftp27/10401472 to your computer and use it in GitHub Desktop.
Code for blinking led on board STM32L-Discovery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stm32l1xx.h" | |
void delay(unsigned int time) { | |
for (time; time > 0; time--); | |
} | |
int main(void) | |
{ | |
RCC->AHBENR |= RCC_AHBENR_GPIOBEN; | |
GPIOB->MODER |= GPIO_MODER_MODER7_0; | |
GPIOB->OTYPER &= ~GPIO_OTYPER_ODR_7; | |
GPIOB->OSPEEDR &= ~GPIO_OSPEEDER_OSPEEDR7_0; | |
GPIOB->PUPDR &= ~GPIO_PUPDR_PUPDR7; | |
while(1) | |
{ | |
GPIOB->ODR |= GPIO_ODR_ODR_7; | |
delay(700000); | |
GPIOB->ODR &= ~GPIO_ODR_ODR_7; | |
delay(700000); | |
} | |
} |
can anyone please please correct my code because the led turns on but does not blink. I am using systick timer for i second delay.
thanks
[email protected]
#include"stm32l1xx.h"
int main(void)
{
RCC -> AHBENR |= RCC_AHBENR_GPIOBEN;
GPIOB->MODER &= ~GPIO_MODER_MODER6;
GPIOB->MODER |= GPIO_MODER_MODER6_0;
GPIOB->OTYPER &= -(GPIO_OTYPER_OT_6);
GPIOB->OSPEEDR &= ~GPIO_OSPEEDER_OSPEEDR6;
GPIOB->PUPDR &= ~GPIO_PUPDR_PUPDR6;
SysTick->LOAD = 319999;
SysTick->VAL = 0;
SysTick->CTRL = 5;
while(1) {
if (( SysTick->CTRL &= SysTick_CTRL_COUNTFLAG)==0)
{
GPIOB -> BSRRL|= GPIO_BSRR_BS_6; // turn led on
SysTick->CTRL = 5;
}
else
{
GPIOB ->BSRRH |= GPIO_BSRR_BR_6;
}
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this. I have published a systick based version here:
https://drolliblog.wordpress.com/2017/04/06/led-blink-with-the-stm32l031x6/