GastonAznarez
Posts: 2
Joined: Sat Jun 09, 2018 10:35 pm

Reading GPIO input assembly

Sat Jun 09, 2018 11:14 pm

Hi, i'm a Computer science student. I'm trying to read the pin #4 of mi Raspberry Pi 3 B with assembly code but i can not make it work.
If someone can help me I will be grateful.
This is my code:

Code: Select all

.equ GPIO_GPLEV0, 0x34
.equ GPIO_4, 0x10	
.equ PERIPHERAL_BASE, 0x3F000000

mov w8, PERIPHERAL_BASE + GPIO_BASE    //0x3F200000
ldr w9, [x8, GPIO_GPLEV0]               //Get the 0-31 GPIO states
tbnz w9, #4,  jump //Branch if the 4th bit (0x10) is 1 who corresponds to the pin #4

Attachments
WhatsApp Image 2018-06-09 at 20.07.41.jpeg
Hardware setup
WhatsApp Image 2018-06-09 at 20.07.41.jpeg (123.39 KiB) Viewed 468 times

User avatar
Paeryn
Posts: 2107
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Reading GPIO input assembly

Sun Jun 10, 2018 2:08 am

That is gpio 23 not 4. Looks like you are confusing the wiringpi name/number (which looks to be labeled #4 on that pin) with the actual BCM gpio number which you need to use when reading the hardware registers.
She who travels light — forgot something.

B.Goode
Posts: 6348
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Reading GPIO input assembly

Sun Jun 10, 2018 8:13 am

I'm sure @Paeryn is correct.

You might find this interactive website that documents the Raspberry Pi header instructive: https://pinout.xyz/pinout/pin16_gpio23

GastonAznarez
Posts: 2
Joined: Sat Jun 09, 2018 10:35 pm

Re: Reading GPIO input assembly

Sun Jun 10, 2018 8:34 pm

B.Goode wrote: I'm sure @Paeryn is correct.

You might find this interactive website that documents the Raspberry Pi header instructive: https://pinout.xyz/pinout/pin16_gpio23
Paeryn wrote: That is gpio 23 not 4. Looks like you are confusing the wiringpi name/number (which looks to be labeled #4 on that pin) with the actual BCM gpio number which you need to use when reading the hardware registers.
Thank you very much to both. It is working now.

Return to “Bare metal, Assembly language”

Who is online

Users browsing this forum: No registered users and 4 guests