0

I am new learner for raspberry pi 3B+, I ever study stm32 mcu, but it's my first time to use an Linux OS on a developing board.

I read the BCM2837-ARM-Peripherals manaul and learn how to turn on and off led by access virtual address through ioremap_nocache(). It's not too difficult for me.

But I would like to learn set a gpio input interrupt for a button, I try many ways but still fail. I refer the dht11 example and source code http://www.tortosaforum.com/raspberrypi/dht11driver.htm

I use the material code like blow, or just compile the dht11 example, all I try will make linux crash without any hint and I can operate rpi only after power reset.

#define GPIO_INT_RISING(g,v) *(gpio+19) = v ? (*(gpio+19) | (1<<g)) : (*(gpio+19) ^ (1<<g))

#define BCM2708_PERI_BASE        0x3F000000
#define GPIO_BASE                (BCM2708_PERI_BASE + 0x200000)
#define ARM_IRQ2_BASE                  32 
#define INTERRUPT_GPIO0                (ARM_IRQ2_BASE + 17)

gpio = ioremap_nocache(GPIO_BASE, SZ_4K)
request_irq(INTERRUPT_GPIO0, irq_handler, IRQF_SHARED, NAME, (void*) gpio)
GPIO_INT_RISING(gpio_pin, 1);

I found there are another way to use library, like

button_irq = gpio_to_irq(BUTTON)
request_irq( button_irq, button_isr ,IRQF_TRIGGER_RISING, MY_GPIO_INT_NAME, MY_DEV_NAME)

It works for me to trigger irq when I press the input button, but I prefer to learn more direct way like dht11 example. Can any one give me a example about how to setting gpio input interrupt with direct memory access?

  • Well, it is easy to find python tutorials on how to read a Rpi GPIO connected button using (1) stupid looping, (2) not so stupid interrupt. But your rather low level DMA approach is newbie scary. There are many python examples for programming DHT11. One way to solve your problem is write a workable python DHT11/button detection program and then 'translate' it to lower level C/C++. – tlfong01 Aug 17 at 5:26
0

The DHT11 is not a good model for general programming, and the sample which relies on a LKM makes it more complex. (This is probably necessary for DHT11 because of its timing constraints).

I suggest you try http://wiringpi.com/reference/priority-interrupts-and-threads/

pigpio is excellent code, although the documentation is brief http://abyz.me.uk/rpi/pigpio/index.html

Unless you want to develop in c, gpiozero is an excellent Python library, well documented and easy to use.

None of the others require fiddling with kernel modules, as interrupt support is included in modern kernels.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.