繁体   English   中英

stm32f103板不闪烁

[英]stm32f103 board not blinking

我无法让新的stm32f103c8t6板闪烁一个简单的led。 我已经尝试了一切。 我已经将裸机直接写入寄存器,还使用了GPIO库,但是它仍然无法正常工作。 我在用keil。 我的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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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