Directly addressing the ESP32 registers for fast I/O operations
Posted: Mon Nov 13, 2023 9:35 am
Hi,
This is my very first project using ESP32. I got a Chinese dev board ESP WROOM - 32 but I already verified that it is working (led blink was successful.)
I have some experience with PIC32 register based programming, so I would like to start with the same philosophy on ESP. Of course, the ESP-IDF can provide ready to use complex USB, Ethernet, SPI etc. drivers. But I would like to start from the fundamentals of understanding the I/O based on directly setting the right registers. I am using visual studio code with the ESP-IDF framework. I found the chapter in a datasheet that explains how to do it, but I am not sure about how should I address the registers in ESP-IDF. Can someone write me the code equivalent of this very little datasheet chapter? Thank you in advance, I really hope that after this example I will be able to address the registers on my own.
P.S. I have written some very simple code:
Even if the code is wrong, any register name that I write, the compiler treats it as undeclared function, am I missing any include? Also what is the syntax if I want to set a specific field (that has a name in the datasheet) of a register?
This is my very first project using ESP32. I got a Chinese dev board ESP WROOM - 32 but I already verified that it is working (led blink was successful.)
I have some experience with PIC32 register based programming, so I would like to start with the same philosophy on ESP. Of course, the ESP-IDF can provide ready to use complex USB, Ethernet, SPI etc. drivers. But I would like to start from the fundamentals of understanding the I/O based on directly setting the right registers. I am using visual studio code with the ESP-IDF framework. I found the chapter in a datasheet that explains how to do it, but I am not sure about how should I address the registers in ESP-IDF. Can someone write me the code equivalent of this very little datasheet chapter? Thank you in advance, I really hope that after this example I will be able to address the registers on my own.
P.S. I have written some very simple code:
Code: Select all
#include <stdio.h>
#include <stdint.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
//I want to toggle GPIO pin 2
void app_main() {
GPIO_FUNC2_OUT_SEL_CFG_REG = 0x100; //This step is provided in the datasheet
while (1) {
GPIO_OUT_DATA |= (1 << 2);
vTaskDelay(1000 / portTICK_PERIOD_MS);
GPIO_OUT_DATA &= ~(1 << 2);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}