【发布时间】:2020-08-03 05:34:02
【问题描述】:
我正在学习如何使用寄存器对 STM32 Nucleo F446RE 板进行编程。
要知道寄存器的位置,我从数据表中获取边界地址和偏移量。 但是,我无法计算它们的总和。我举个例子:
volatile uint32_t *GPIOA = 0x0; // Initialization of the boundary adress
GPIOA = (uint32_t*)0x40020000; // Boundary adress from datasheet
volatile uint32_t *GPIOA_ODR = 0x0; // Initialization of GPIOA_ODR register
GPIOA_ODR = GPIOA + (uint32_t*)0x14; // Calculation of GPIOA_ODR as the sum of the boundary adress and the offset (i.e. 0x14.
第5行给我一个错误,你知道如何正确计算吗?
非常感谢您。
【问题讨论】:
-
你的演员阵容错了!。正确的演员表可以写成
GPIOA_ODR = (uint32_t*)(GPIOA + 0x14); -
方式不对。 IMO 对你来说太早了。你需要先学习指针和指针运算。使用来自 stm 标头的定义。它们的定义正确。
-
@lheb Albouda 它不起作用。这是我尝试过的一种解决方案,但没有。
标签: c pointers stm32 offset cpu-registers