嗨,我正在使用Raspberry Pi-4B。 我使用带有bcm2835 lib的C语言,将GPIO引脚编程为输入。 我尝试了GPIO引脚P1-11。它被编程为输入以检测异步上升沿。但是在执行期间,GPESD位在上升沿和下降沿均置1。知道为什么要检测到下降沿吗?
请在下面找到代码并输出:
#include <bcm2835.h>
#include <stdio.h>
#define PIN RPI_GPIO_P1_11
int main(int argc, char **argv)
{
//bcm2835_set_debug(1);
if (!bcm2835_init())
return 1;
// Set RPI pin P1-15 to be an input
bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_INPT);
// with a pullup
bcm2835_gpio_set_pud(PIN, BCM2835_GPIO_PUD_DOWN);
// And a rising edge detect enable
bcm2835_gpio_aren(PIN);
bcm2835_gpio_clr_ren(PIN);
bcm2835_gpio_clr_len(PIN);
bcm2835_gpio_clr_hen(PIN);
bcm2835_gpio_clr_fen(PIN);
bcm2835_gpio_clr_afen(PIN);
delay(500);
printf("gpio_event: \n");
while (1)
{
uint8_t value = bcm2835_gpio_lev(PIN);
printf("read from pin %0d: %d\n", PIN, value);
delay(50);
if (bcm2835_gpio_eds(PIN))
{
delay(50);
printf("rising edge detected on pin %0d\n",PIN);
//clear the eds flag by setting it to 1
bcm2835_gpio_set_eds(PIN);
}
// wait a bit
delay(1000);
}
bcm2835_close();
return 0;
}
// Output:
//================================================
//gpio_event:
//read from pin 17: 0
//read from pin 17: 0
//read from pin 17: 0
//read from pin 17: 0
//read from pin 17: 0
//read from pin 17: 0
//read from pin 17: 0
//read from pin 17: 1
//rising edge detected on pin 17
//read from pin 17: 1
//read from pin 17: 1
//read from pin 17: 1
//read from pin 17: 0
//rising edge detected on pin 17
//read from pin 17: 0
//read from pin 17: 0
//read from pin 17: 0
//read from pin 17: 0
//================================================