简体   繁体   中英

stm32f103 board not blinking

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);

    }
}

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM