简体   繁体   English

读取GPIO的引脚电平?

[英]Read pin level of GPIO?

I want to read the level of a GPIO pin. 我想读取GPIO引脚的电平。 The following is found in the documentation for the chip: 在该芯片的文档中可以找到以下内容:

GPIO Pin Level Registers (GPLEVn)

SYNOPSIS    The pin level registers return the actual value of the pin.
            The LEV{n} field gives the value of the respective GPIO pin.

Bit(s)    Field Name        Description              Type    Reset
21-0      LEVn (n=32..53)   0 = GPIO pin n is low    R/W     0
                            1 = GPIO pin n is high

This is the code I have written: 这是我编写的代码:

ldr r0,=0x20200038    @ Load address of GPLEV into r0
mov r1,#1             @ Load value 1 into r1
lsl r1,#18            @ Left shift value in r1 eighteen places. This corresponds to GPIO50
str r1,[r0]           @ Store the content of r1 at the address in r0

I would now expect to find the pin level in r0 , but it does not seem to work. 我现在期望在r0中找到引脚电平,但是它似乎不起作用。 Are the above code a correct method for reading the pin level of a GPIO? 上面的代码是读取GPIO引脚电平的正确方法吗?

In your code, r0 holds the address of the GPLEV register but not the value of the GPLEV register. 在您的代码中, r0保存GPLEV寄存器的地址,但不保存GPLEV寄存器的值。 If you want to read the value from the GPLEV register into a different register then you need something like: 如果要将值从GPLEV寄存器读取到另一个寄存器中,则需要类似以下内容:

ldr r0,=0x20200038
ldr r2,[r0]

Your code puts the value 0x00040000 in r1 and then stores that value in GPLEV. 您的代码将值0x00040000放入r1 ,然后将该值存储在GPLEV中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM