Hey Guys,
im new to ESP32 Programming, i have knowledge in Atmega328p programming on register level. So now i want to programm the ESP32 on register level, but the technical reference is not that easy to read and follow.
I have written some code for ESP32 so activate the ESP32 permanently, but the code wont work, maybe you could help me. What have i done wrong?
#include "soc/gpio_reg.h"
#include "soc/io_mux_reg.h"
#include "driver/gpio.h"
#include <stdio.h>
void app_main(void){
REG_WRITE(GPIO_FUNC16_OUT_SEL_CFG_REG, (1 << GPIO_FUNC16_OEN_SEL)); // Das ist der richtige Shift-Wert
// Aktiviere GPIO16 als Ausgang
REG_WRITE(GPIO_ENABLE_REG, (1 << 16));
// Setze GPIO16 auf HIGH
REG_WRITE(GPIO_OUT_REG, (1 << 16));
}
ESP32 Register Programming
-
MicroController
- Posts: 2705
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: ESP32 Register Programming
The ESPs don't 'work' that way. As you may have noticed, the Technical Reference Manual isn't as complete as you may be used to from Atmel or STM. The 'philosophy' behind this is that you're supposed to just use the provided ESP-IDF drivers instead. Which makes sense from a productivity point-of-view: Why write down what code you'd have to write to use a peripheral when I can provide the necessary code directly?So now i want to programm the ESP32 on register level
To understand how some aspect of a peripheral works in detail, the drivers' source code is usually a definitive source of information.
Also worth noting is that the ESPs are much more complex devices than the AVRs, which inherently makes working 'bare metal' much harder.
If you want to use direct register accesses, e.g. for maximum performance, I recommend at least using the IDF driver for initialization of the peripheral you want to use, and after that use specific registers only as much as necessary.
Also pay attention to multi-threading issues when 'bypassing' the drivers.
What does that mean?I have written some code for ESP32 so activate the ESP32 permanently,
Looking at your code, I assume you're trying to output a high level on GPIO16 and disable the outputs of all other GPIO0...31 at the same time? - Not a good idea because you'd kill the MCU's access to the flash memory in the process. (And apparently, GPIO16 is used for the flash/PSRAM's CE# signal, so not to be messed with anyway.)
No, it's notCode: Select all
... (1 << GPIO_FUNC16_OEN_SEL)); // Das ist der richtige Shift-Wert
GPIO_FUNC16_OEN_SEL is (1<<GPIO_FUNC16_OEN_SEL_S) already.
Re: ESP32 Register Programming
What you can do is to look at functions like gpio_ll_set_level(...) (note "_ll_" in the name), those located in components/esp_driver_gpio and components/halim new to ESP32 Programming, i have knowledge in Atmega328p programming on register level. So now i want to programm the ESP32 on register level, but the technical reference is not that easy to read and follow.
They are short and do exactly what you want: access GPIOs through REG_WRITE..
But better is to stick to IDF functions (like gpio_set_level()) instead of manipulating registers directly. If you want your code to be as fast as direct register access, then just use "_ll_" versions (gpio_ll_set_level() instead of gpio_set_level())
Thanks!
Slava.
Slava.
Who is online
Users browsing this forum: Baidu [Spider], Google [Bot], trendictionbot and 1 guest