0

你能帮我找出我犯错的地方吗?LED 在 PA5 端口上。

int main(void){
    HAL_Init();
    SystemClock_Config();
    GPIO_InitTypeDef GPIO_InitStruct;
    __HAL_RCC_GPIOA_CLK_ENABLE();

    GPIO_InitStruct.Pin = GPIO_PIN_5;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    while(1){
        HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
        HAL_Delay(5000);
    }
}
4

1 回答 1

0

在微控制器上,引脚具有多种功能,这些功能的启用必须由软件配置,有时由硬件配置(将引脚拉到 VCC 或 GND,...)。PA5STM32L073xZ 具有替代功能,这在第 39 页和第 45 页的数据表 ( https://www.mouser.de/datasheet/2/389/stm32l073v8-956245.pdf ) 中,Nucleo L073RZ 上的 MCU 封装是 LQFP64,参见https://www.st.com/content/ccc/resource/technical/document/user_manual/98/2e/fa/4b/e0/82/43/b7/DM00105823.pdf中的 Nucleo 示意图/files/DM00105823.pdf/jcr:content/translations/en.DM00105823.pdf第 64 页(https://www.st.com/content/ccc/resource/technical/document/reference_manual/2f/b9/c6/34/28/29/42/d2/DM00095744.pdf/files/DM00095744.pdf/jcr:内容/翻译/en.DM00095744.pdf)。

我不知道您是否在其余代码的某处启用了备用功能,但这可能是问题的核心。您发布的代码部分是准确的,在https://github.com/TechBreiteneder/00_GPIO_BlinkLED/blob/master/Src/main.c中是 CubeMX 项目中的 LED 闪烁代码。因此,您可能在引脚 PA5 上启用了替代功能,此外,您还必须启用其他组件,例如时钟系统,MCU 才能正常工作,参见https://riptutorial.com/stm32/example/25059/first-time- setup-with-blink-led-example-using-sw4stm32-and-hal-library。因此,在不知道您的 MCU 配置的情况下,很难说错误在哪里......

你应该做的是在切换之前设置一个定义的初始状态但是我认为这不是问题

/*Configure GPIO pin Output Level */
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN5, GPIO_PIN_RESET);
于 2020-02-02T17:36:12.613 回答