stm32f103板子不闪烁

stm32f103 board not blinking

我无法让我的新 stm32f103c8t6 板闪烁一个简单的 LED。我已经尝试了一切。我已经将裸机直接写入寄存器并使用了 GPIO 库,但它仍然无法正常工作。我正在使用基尔。我的 LED 通过 1k 电阻器连接在面包板上。我还测试了输出引脚两端的电压,但它微不足道。请问有什么问题吗?下面的代码...

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

    }
}

几个选项:

错误的延迟实现和编译器优化代码:

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

与您的情况一样,初始化错误。您初始化了 GPIOD 但使用了 GPIOA.