2018-10-02 05:08 PM
i made this code to blink an led with systick time but it does not work can you please correct this. i am using stm32l152rc discovery board.
#include "stm32l1xx.h"
while {
if (SysTick->CTRL |= SysTick_CTRL_COUNTFLAG == 0)
{
GPIOB->BSRRH |= GPIO_BSRR_BS_6;
}
else {
GPIOB->BSRR |= GPIO_BSRR_BR_6;
}
}
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;
GPIOB->BSRRL = GPIO_BSRR_BR_6;
SysTick->CTRL = 0;
SysTick->LOAD = 1599999;
SysTick->VAL = 0;
SysTick->CTRL = 7;
}
2018-10-02 06:08 PM
Your presentation style is confusing.
What's the while() loop floating above main()?
Why is the |= in the if statement?
You should just do an assignment for BSRRH/BSRR, not OR it
The main() routine should not exit
Try using a debugger
2018-10-03 06:49 PM
thank you very much Mr Clive for your hints but this time can you please rewrit the above code and send it to me, i would greatly appreciate. I am just a beginner and you are an expert.
arif from canada
k.arif4@hotmail.com
2018-10-05 03:57 PM
#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;
void delay_ticks(unsigned ticks)
{
SysTick->LOAD = 319999;
SysTick->VAL = 0;
SysTick->CTRL = 5;
while(1)
(( SysTick->CTRL &= SysTick_CTRL_COUNTFLAG) == 1);
SysTick->CTRL = 0;
}
GPIOB -> BSRRL|= GPIO_BSRR_BS_6;// turn led on
void delay_s(unsigned ms)
{
delay_ticks(1000 * (32000000 / 8) );
}
GPIOB ->BSRRH |= GPIO_BSRR_BR_6; // turn off delay
void delay_s(unsigned ms)
{
delay_ticks(1000 * (32000000 / 8) );
}
}
i made this code for blinking an led with systick timer for a a delay of one second. can anyone make correction in it because led just lights up but does not turn off
2018-10-05 04:20 PM
"can you please correct this."
your code is too far from working and reflects a complete lack of understanding, both from a hardware and software perspective.
the flow would be something like this:
now you just need to implement the few blocks above.
2018-10-06 06:53 PM
i am doing point ( suggestion ) no 4 like this. Sir, i am just a beginner not an expert like you.
Is this correct ?
if (( SysTick->CTRL &= SysTick_CTRL_COUNTFLAG) == 1);
SysTick->CTRL = 0;
{ GPIOB -> BSRRL|= GPIO_BSRR_BS_6;// turn led on
}