这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » STM32 » NUCLEO L053R8 边学边玩 (四) Mbed Blink 的庖丁解牛

共37条 2/4 1 2 3 4 跳转至
专家
2015-11-13 11:54:43     打赏
11楼

那么对Nucleo L053R8而言

我们首先需要知道的是板载LED连接到哪个GPIO


在ST的文档中我们找到这样一段话:

LEDs
The tricolor LED (green, orange, red) LD1 (COM) provides information about ST-LINK communication status. LD1 default color is red. LD1 turns to green to indicate that communication is in progress between the PC and the ST-LINK/V2-1, with the following setup:
?Slow blinking Red/Off: at power-on before USB initialization
?Fast blinking Red/Off: after the first correct communication between the PC and STLINK/
V2-1 (enumeration)
?Red LED On: when the initialization between the PC and ST-LINK/V2-1 is complete
?Green LED On: after a successful target communication initialization
?Blinking Red/Green: during communication with target
?Green On: communication finished and successful.
?Orange On: Communication failure
User LD2: the green LED is a user LED connected to Arduino signal D13 corresponding to MCU I/O PA5 (pin 21) or PB13 (pin 34) depending on the STM32 target. Please refer to Table 10 to Table 21.
?When the I/O is HIGH value, the LED is on.
?When the I/O is LOW, the LED is off.
LD3 PWR: the red LED indicates that the MCU part is powered and +5V power is available.


有这个图可以看出,这个LED连接至D13, PA5


专家
2015-11-13 11:55:54     打赏
12楼

那么GPIOA相关的寄存器都有哪些呢?

地址又是多少呢?



专家
2015-11-13 11:57:56     打赏
13楼

专家
2015-11-13 11:58:20     打赏
14楼

为嘛图片都变性了呢?

愁死了


专家
2015-11-13 11:59:37     打赏
15楼

从上图可以看出

IOPORT的地址是0x5000 0000 至 0x5000 1FFFF

然而这并没有什么鸟用



专家
2015-11-13 12:04:11     打赏
16楼

经过一番搜索,终于找到一个完整点的文档,1000多页啊


RM0367
Reference manual
Ultra-low-power STM32L0x3 advanced ARM®-based
32-bit MCUs


就是它,就不信找不到GPIO的寄存器信息


功夫不负有心人,铁杵终于磨成针


哇,好多寄存器。



专家
2015-11-13 12:12:15     打赏
17楼

研究了半天,原来是对应IOPORT中寄存器的地址 (偏移量)

就好比说我住2单元十楼2号,光知道这个信息,你找不到我

你还需要知道是哪个城市,哪个街道,哪个小区。


擦,可惜这事没法交给快递员去做

我慢慢找找



专家
2015-11-13 12:14:51     打赏
18楼

功夫不负有心人,铁杵终于磨成针

为嘛我感觉这句话很熟悉的样子,似乎哪个名人刚刚说过?


当当当当

虽然和之前的之前的那个图基本上差不多

不过这个更详细


专家
2015-11-13 18:22:02     打赏
19楼


专家
2015-11-13 18:32:28     打赏
20楼

也就是说,通过设置这组寄存器,可以达到设置或者重设ODx bit


和我平时理解的稍微有些差异

我以为设置,那么就置一,重置呢就置零(再不解放台湾,志玲就老了)

实际上呢,设置是把 Port x set bit y 置一

重置呢是把Port x reset bit y 置零


再回头看mbed官网连接中的这个程序:

#include "mbed.h"
 
// Reuse initialization code from the mbed library
DigitalOut led1(LED1); // P1_18
 
int main() {
    unsigned int mask_pin18 = 1 << 18;
    
    volatile unsigned int *port1_set = (unsigned int *)0x2009C038;
    volatile unsigned int *port1_clr = (unsigned int *)0x2009C03C;
    
    while (true) {
        *port1_set |= mask_pin18;
        wait(0.5);
        
        *port1_clr |= mask_pin18;
        wait(0.5);
    }
}

 

对于我们来讲:
portA_set 的地址为:0x5000 0000 + 0x18

portA_reset 的地址同样为:0x5000 0000 + 0x18

与例子中使用的MCU还是有所差异的



共37条 2/4 1 2 3 4 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]