提问人:FancyPants General 提问时间:8/5/2023 最后编辑:FancyPants General 更新时间:8/5/2023 访问量:79
STM32F411RE:我想在开漏模式下打开 LED,但 LED 不亮
STM32F411RE: I want to turn on the LED in open-drain mode, but the LED doesn't turn on
问:
我想在开漏模式下打开微控制器上的 LED,但 LED 不亮。 到目前为止,我有这个,我不知道我的错误是什么。我正在与STMCubeIDE中的STM32F411RE合作。
#include "main.h"
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART2_UART_Init(void);
#define RCC_BASE_ADDRESS 0x40023800
#define GPIOA_BASE_ADDRESS 0x40020000
#define RCC_AHB1ENR_OFFSET 0x30
#define GPIOA_MODER_OFFSET 0x00
#define GPIOA_ODR_OFFSET 0x14
#define GPIOA_OTYPER_OFFSET 0x04
#define RCC_AHB1ENR_POINTER (uint32_t*)(RCC_BASE_ADDRESS + RCC_AHB1ENR_OFFSET)
#define GPIOA_MODER_POINTER (uint32_t*)(GPIOA_BASE_ADDRESS + GPIOA_MODER_OFFSET)
#define GPIOA_ODR_POINTER (uint32_t*)(GPIOA_BASE_ADDRESS + GPIOA_ODR_OFFSET)
#define GPIOA_OTYPER_POINTER (uint32_t*)(GPIOA_BASE_ADDRESS + GPIOA_OTYPER_OFFSET)
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART2_UART_Init();
*RCC_AHB1ENR_POINTER |= (1 << 0); // Enable clock for GPIOA
*GPIOA_MODER_POINTER |= (1 << 10); // Set pin 5 as output
*GPIOA_OTYPER_POINTER |= (1 << 5); // Set pin 5 to open-drain mode
*GPIOA_ODR_POINTER &= ~(1 << 5); // Turn on the LED by driving the pin low (since it's open-drain)
while(1) {}
}
答: 暂无答案
评论
volatile
GPIO_TypeDef