Beaglebone GPIO Pin Muxing

 
GPIO Muxing

I had to choose some gpio pins for a 6-key-keypad which will be connected beaglebone and I found these pins:  GPIO1_30, GPIO1_4, GPIO1_0, GPIO1_5, GPIO1_1 and GPIO1_29
They are 21-26 pins at expansion P8 header.  

As each GPIO index has 32 pins, gpio1_30 is equal to GPIO62 actually. Also GPIO1_0 = GPIO32
The calculation is like this:  GPIOx_y = 32*x + y 

For GPIO1_30 pin, the muxing is the following:

echo 27 > /sys/kernel/debug/omap_mux/gpmc_csn1   (you can check gpmc_csn1 from datasheet)
echo 62 > /sys/class/gpio/export                                   (gpio62 is from the calculation)
echo in /sys/class/gpio/gpio62/direction                        (direction is input)
cat /sys/class/gpio/gpio62/value                                    (check everything is alright)


If the lines above except the cat command was added to /etc/init.d as a script and linked to /etc/rc5.d, It would be not necessary to enter these lines always, and it would start as a startup application.
In /etc/rc5.d, it should be named as the last number, because there are some files whose names starting with numbers like S21script1 , S22script2, S23 script3. Your script name must be created like this i.e. S24yourscript.sh

The script I have written:


#!/bin/sh

echo 27 > /sys/kernel/debug/omap_mux/gpmc_csn1
echo 62 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio62/direction
echo 27 > /sys/kernel/debug/omap_mux/gpmc_ad5
echo 37 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio37/direction
echo 27 > /sys/kernel/debug/omap_mux/gpmc_ad4
echo 36 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio36/direction
echo 27 > /sys/kernel/debug/omap_mux/gpmc_ad1
echo 33 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio33/direction
echo 27 > /sys/kernel/debug/omap_mux/gpmc_ad0
echo 32 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio32/direction
echo 27 > /sys/kernel/debug/omap_mux/gpmc_csn0
echo 61 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio61/direction


The question is why the first lines have a 27 number.

Bit 5: 1 - Input, 0 - Output

Bit 4: 1 - Pull up, 0 - Pull down

Bit 3: 1 - Pull disabled, 0 - Pull enabled

Bit 2 \

Bit 1 |- Mode

Bit 0 /
Think 2 and 7 is separated each other. 2 is 1 0  and  7 is 0111
You were entering echo 27 which is --> 1 0 0111  and it means: bit 0,1 and 2 is 1, so the mode is set. Also, bit 4 is set for pull up.







Comments

  1. Hello,
    I came across your blog while I was searching for pin mux details, I also noticed that you were connecting a 6 key pey pad to beaglebone. were you planning on using it as a matrix key pad or each key as a individual input ? I am looking to interface 4x4 matrix keypad to my beaglebone. do have any suggestions on how to ? in terms of script/code.

    Appreciate your help

    ReplyDelete

Post a Comment

Popular posts from this blog

Virüsler ve Kanser İlişkisi Üzerine

Endokrin Sistemi