6

I am reading a hall sensor output in beaglebone gpio pin, for every rising edge the interrupt service routine needs to execute. So, how to use external interrupt in beaglebone? and is there any standard driver for this purpose?

Thanks.

duslabo
  • 1,487
  • 4
  • 20
  • 33

2 Answers2

3

Yes there is a standard driver. This page here shows the basic steps for using gpio's.

Barath Ravikumar
  • 5,658
  • 3
  • 23
  • 39
TJD
  • 11,800
  • 1
  • 26
  • 34
  • Better yet, you can do it all from user-space. The only issue you might come up against is that that all IO pins on OMAP devices can be multiplexed a number of ways (one of which is GPIO). With any luck, if you're using a a kernel intended for your board it will already be set up. – marko Aug 06 '12 at 21:46
  • Thanks Marko, Ya I want to do it in userspace itself using sysfs :). And What is the difference between using sysfs and creating separate driver ? I mean for realtime application. Do you think accessing through sysfs is slower than accessing through driver? – duslabo Aug 07 '12 at 16:15
  • This is debatable. Using sysfs you'll have a user-space thread blocked with `select()`. If that has real-time thread priority, there's not going to much in it on a RT pre-emptive kernel with the interrupt handler you'd write in the driver - which runs in a kernel thread - also with RT priority. I ended up with a driver in order to prevent a race condition - seems that using sysfs, edges are only ever detected when you're blocked on select(). My device could generate them immediately after clearing down the cause of the previous interrupt. In this condition I've never get another edge. – marko Aug 09 '12 at 23:55
  • sysfs is slightly slower because you have the kernel->usermode transitions and a bit of overhead within sysfs. It is not dramatic though. Most likely you'll be fine with userspace GPIO. – Nils Pipenbrinck Mar 03 '13 at 15:38
  • 4
    the link has changed to: https://developer.ridgerun.com/wiki/index.php?title=How_to_use_GPIO_signals – Mojtaba Ahmadi Mar 09 '19 at 12:56
3

In Python using Adafruit Libray,

import Adafruit_BBIO.GPIO as GPIO 

Pin = "P8_8" 
GPIO.setup(Pin, GPIO.IN)    # set GPIO25 as input (button)  

def my_callback(channel):  
    if GPIO.input(Pin):    
        print "Rising edge detected on 25"  
    else:                  # if port 25 != 1  
        print "Falling edge detected on 25" 

GPIO.add_event_detect(Pin, GPIO.BOTH, my_callback, 1)

Here is reference link.

Community
  • 1
  • 1
Vijay Panchal
  • 317
  • 3
  • 8