stm32f103 board not blinking

0

I cant get my new stm32f103c8t6 board to blink a simple led. I have tried everything. I have written bare metal directly to the registers and also used GPIO libraries but its still not working. I am using keil. my led is connected on a breadboard across a 1k resistor . I have also tested the voltage across the output pin but its insignificant. What could be wrong please ? code below ...

#include "stm32f10x.h"

GPIO_InitTypeDef GPIO_InitStructure;

void delay(int a)
{
    for (int i = 0; i < a; i++)
    {

    }

}
int main(void)
{

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

    /* Configure PD0 and PD2 in output pushpull mode */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_2;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOD, &GPIO_InitStructure);

    /* To achieve GPIO toggling maximum frequency, the following  sequence is mandatory. 
     You can monitor PD0 or PD2 on the scope to measure the output signal. 
     If you need to fine tune this frequency, you can add more GPIO set/reset 
     cycles to minimize more the infinite loop timing.
     This code needs to be compiled with high speed optimization option.  */
    while (1)
    {
        /* Set PD0 and PD2 */
        GPIOA->BSRR = 0x00000005;
        delay(1000000);
        /* Reset PD0 and PD2 */
        GPIOA->BRR = 0x00000005;
        delay(1000000);

    }
}
c
embedded
stm32
gpio
asked on Stack Overflow Feb 28, 2017 by ched • edited Feb 28, 2017 by LPs

1 Answer

1

Several options:

Wrong delay implementation and compiler optimizes code out:

void delay(volatile int a) {
    //Added volatile in a and in i
    for (volatile int i = 0; i < a; i++);
}

Wrong initialization as in your case. You initialized GPIOD but use GPIOA.

answered on Stack Overflow Feb 28, 2017 by tilz0R • edited Feb 28, 2017 by tilz0R

User contributions licensed under CC BY-SA 3.0