- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我调整了 here 中的示例用于 STM3240G-EVAL 板,以便使 LED 3 和 4 闪烁。我可以正常工作,但对模式寄存器设置感到困惑:
GPIOG->MODER |= (GPIO_MODER_MODER6_0 | GPIO_MODER_MODER8_0) ;
当我阅读 reference manual (p186),它声称必须将模式设置为 01 才能输出,但以这种方式将其设置为 0 就可以了。理想情况下,我希望能够更改为其他模式,但我假设上面的代码会将端口 G 的引脚 6 和 8 更改为输入引脚。我一定是遗漏了什么。
如果相关,这是我完整的主要文档:
#include "stm32f4xx.h"
/* We will use PG6 and PG8 connected to LEDs 1 and 2 because they're the same port. */
/* Find base register value for Port G */
void delay (int a);
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f0xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f0xx.c file
*/
/* GPIOG Periph clock enable */
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOGEN;
GPIOG->MODER |= (GPIO_MODER_MODER6_0 | GPIO_MODER_MODER8_0) ;
/* Configure PG6 and PG8 in output mode */
GPIOG->OTYPER &= ~(GPIO_OTYPER_OT_6 | GPIO_OTYPER_OT_8) ;
// Ensure push pull mode selected--default
GPIOG->OSPEEDR |= (GPIO_OSPEEDER_OSPEEDR6|GPIO_OSPEEDER_OSPEEDR8);
//Ensure maximum speed setting (even though it is unnecessary)
GPIOG->PUPDR &= ~(GPIO_PUPDR_PUPDR6|GPIO_PUPDR_PUPDR8);
//Ensure all pull up pull down resistors are disabled
while (1)
{
/* Set PG6 and PG8 */
/* the bit set/reset low register SETS the output data register */
/* the bit set/reset high register RESETS the output data register */
GPIOG -> BSRRL = (1 << 6);
GPIOG -> BSRRL = (1 << 8);
delay(500000);
/* Reset PC8 and PC9 */
GPIOG -> BSRRH = (1 << 6);
GPIOG -> BSRRH = (1 << 8);
delay(500000);
}
return 0;
}
void delay (int a)
{
volatile int i,j;
for (i=0 ; i < a ; i++)
{
j++;
}
return;
}
最佳答案
您不是将其设置为零,而是将其设置为一。
GPIO_MODER_MODER6_0
常量的定义是 0x00001000
。 GPIO_MODER_MODER6
位的掩码是 0x00003000
,因此您将位 01
放在正确的位置。
如果常量 GPIO_MODER_MODER6_0
被定义为零,那么在任何情况下将其放入配置寄存器都不会产生任何影响。要将这两个位都设置为零,您需要执行以下操作:
GPIOG->MODER &= ~(GPIO_MODER_MODER6_0 | GPIO_MODER_MODER6_1);
_0
和 _1
后缀指的是用于屏蔽的位数,而不是写入的值。
关于c++ - GPIO模式寄存器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27158211/
虽然找到了许多关于如何使用 GPIO.BCM 模式设置 gpio 的示例(其中引脚编号等效于 RPI(参见图像和 nvidia/jetson-gpio),但我找不到在 GPIO.TEGRA_SOC 模
我一直在努力编写一个脚本,该脚本将 Pi 的 BCM 引脚 17、27 和 10 打开 1 秒,然后关闭 1 秒,连续 100 次。当我运行脚本时,LED1 会亮起然后熄灭,程序因以下错误而关闭: T
我想使用 linux GPIO 驱动程序来处理 mpc8308 处理器的 GPIO 引脚之一作为输出。所以我启用了 GPIO 驱动程序并在以下位置进行调试: Device Drivers ---> G
我正在开发一个项目,需要我配置 GPIO 引脚并向原子板添加传感器。内核已配置 gpio ... CONFIG_GPIO_SYSFS=y 是内核选项之一。 我使用的是fedora版本2.6.29-10
我真的很担心我的 GPIO 可能被烧坏了,因为即使是这个 super 简单的代码也会导致错误 import RPi.GPIO as io import time io.setmode(io.BCM)
我尝试将 RPi.GPIO 与 Python 3.6 一起使用。 我安装了 RPi.GPIO,它适用于 Python 3.4,但不适用于 Python 3.6 我得到这个错误: ModuleNotFo
默认情况下,/sys/class/gpio 只能作为 root 访问。所以我喜欢一个新组gpio可以使用/sys/class/gpio下的文件和目录。为此,我将以下行添加到 /etc/rc.local
我已经阅读了 RPi.GPIO 的文档,并在谷歌和 SO 上进行了搜索,但无法完全找到可能是一个非常愚蠢的问题的解决方案。我试图只检测按下按钮的边缘。但无论我是否指定寻找“下降”或“上升”边缘,Pi
我正在编写一个程序来读取 GPIO 引脚的温度。不幸的是,访问这些总是会抛出 ModuleNotFoundError:没有名为“RPi”的模块。 我尝试重新安装它们,但没有成功。 异常(excepti
我正在使用 Raspberry pi 和 java 来使用 pi4j 使 LED 闪烁,一切都已清除并且工作正常,LED 按照代码闪烁但是当我第二次运行时它会导致以下错误,我搜索了很多有很多相同的问题
所以我一直在尝试通过使用命令行和 sysfs 写入和读取 /sys/class/gpio/ 让我的 Raspberry Pi GPIO 正常运行。根据以下教程,我无法复制将 GPIO 设置为输出并将其
我正在使用 Q7 模块 (x86) 并尝试在 Linux 上使用 ACPI SSDT 覆盖配置我们的外围设备。但我与它斗争。我想我误解了 ACPI 的一些核心概念。 问题 CPU -> I2C ->
我正在尝试在 Raspberry PI 上使用 nodejs 从连接的光传感器读取值。我可以读取 python 程序的读数,并可以确认我的设置是正确的。 下面是程序 var gpio = requir
我正在从事密室逃脱项目。实际上,我试图创建的行为如下: 网络浏览器以通常的方式显示网络应用程序的一部分。从此时起,客户端上将不再有键盘/鼠标的输入。我已经使用 JS 解决了基于时间的更改,因此我可以加
我的代码在使用 raspberry pi 时遇到问题。我刚开始使用 Python,所以我需要一些帮助。 这是代码: import RPi.GPIO as GPIO import time GPIO.s
我遇到了和这个问题一样的问题, python import fails when called from PHP但现在是我的另一个导入。 脚本在命令行 (python uit.py) 和一个 test
现在使用旧方法 gpio-sunxi 如何在 OrangePi PC plus ( SoC H3 ) 上访问 Armbian 3.4.113 上的 GPIO并编辑 .fex -file 已过时(想分享
在 Android 和 Linux 下使用传统的 sysfs GPIO 过程的第一步是脚趾 export您要使用的特定 GPIO 引脚。当您完成 GPIO 引脚到 unexport它。 我一直在寻找关
PHYTEC 的内核版本 3.12.30-AM335x-PD15.1.1。 如果我使用/sys/class/gpio 方式,我可以看到按钮输入引脚(AM3359 的 gpio103)值从 0 变为 1
从以前已知的 sysfs 接口(interface),任何人都可以设置合理配置的 GPIO 线的输出,并且此输出将保持该值,直到 SoC 重置或有人更改线值。使用 GPIOlib,当消费者关闭 gpi
我是一名优秀的程序员,十分优秀!