lew247
 Guru
 Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Posted: 09:56am 09 Oct 2024 |
|
|
|
The basic commands that allow you to configure the direction and status of GPIOs are very useful.
The first way for configuring I/O signals is based on the memory read and write functions, PEEK and POKE, respectively. This is a very low level mode and requires in-depth knowledge of the ESP32 module, which can also be found by consulting the component datasheet. The following example reads the contents of address 0x3FF44004 (register GPIO_OUT_REG), put it in OR with 0x04 (binary 100) and finally writes the value at the same address. This corresponds to setting GPIO2 high:
The address could be a memory address or a register. In this case, as we can see again on the datasheet, the address is inside the 4kB address space reserved for GPIO:
The second way, much simpler and more immediate, is to use the IODIR (set GPIO input or output direction), IOSET (set value of an output GPIO) and IOGET (get the value of an input GPIO) functions. Here is an example which first sets the direction of GPIO2 as output, then get and sets its value:
|