How to use GPIO for am335x

From ESS-WIKI
Revision as of 08:29, 27 April 2018 by Zhengguang.yang (talk | contribs)
Jump to: navigation, search

RSB-4220

GPIO Number Linux OS(/sys/class/gpio/) Default direction
IDI0
gpio498
in
IDI1
gpio499
in
IDI2
gpio500
in
IDI3
gpio501
in
IDO0
gpio502
out
IDO1
gpio503
out
IDO2
gpio504
out
IDO3
gpio505
out

RSB-4221

GPIO Number Linux OS(/sys/class/gpio/) Default direction
GPIO0
gpio490
in
GPIO1
gpio491
in
GPIO2
gpio492
in
GPIO3
gpio493
in
GPIO4
gpio494
in
GPIO5
gpio495
in
GPIO6
gpio496
in
GPIO7
gpio497
in
GPIO8
gpio498
in
GPIO9
gpio499
in
GPIO10
gpio500
in
GPIO11
gpio501
in
GPIO12
gpio502
in
GPIO13
gpio503
in

ROM-3310

GPIO Number Linux OS(/sys/class/gpio/) Default direction
GPIO0
gpio490
in
GPIO1
gpio491
in
GPIO2
gpio492
in
GPIO3
gpio493
in
GPIO4
gpio494
in
GPIO5
gpio495
in
GPIO6
gpio496
in
GPIO7
gpio497
in
GPIO8
gpio498
in
GPIO9
gpio499
in
GPIO10
gpio503
in
GPIO11
gpio504
in

Test

Export GPIO then you can use control GPIO from userr space through sysfs

Export GPIO0

# echo 490 > /sys/class/gpio/export

Set GPIO direction to in/out

# echo "out" > /sys/class/gpio/gpio490/direction

Set GPIO value 0/1 if GPIO pin define is output

#  echo 1 > /sys/class/gpio/gpio490/value

Unexport GPIO0

# echo 490 > /sys/class/gpio/unexport

GPIO 490 and GPIO 491 are taken as an example:

  • Connect GPIO 490 and GPIO 491
  • Export GPIO 490 and GPIO 491
# echo 490 > /sys/class/gpio/export
# echo 491 > /sys/class/gpio/export
  • Set GPIO 490 to output
# echo "out" > /sys/class/gpio/gpio490/direction
  • Set GPIO 491 to input
# echo "in" > /sys/class/gpio/gpio491/direction
  • Change GPIO 490 to 1 and read GPIO 491 value
# echo 1 > /sys/class/gpio/gpio490/value
# cat /sys/class/gpio/gpio491/value
1
  • Change GPIO 490 to 0 and read GPIO 491 value
# echo 0 > /sys/class/gpio/gpio490/value
# cat /sys/class/gpio/gpio491/value
0