我无法让我的新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);
}
}
答案 0 :(得分:1)
有几个选择:
错误的延迟实现和编译器优化代码:
void delay(volatile int a) {
//Added volatile in a and in i
for (volatile int i = 0; i < a; i++);
}
在您的情况下错误的初始化。您已初始化GPIOD
,但使用GPIOA
。