Page 15 of 16
Page 317
uint32_t* GPIObase = (uint32_t*)0x60004000; //EP32 S3
//uint32_t* GPIObase = (uint32_t*)0x3FF44000; //ESP32
uint32_t* GPIOSet = GPIObase + 8 / 4;
uint32_t* GPIOClear = GPIObase + 0xC / 4;
uint32_t mask = 1 << 2;
void setup() {
pinMode(2, OUTPUT);
}
void loop() {
*GPIOSet = mask;
delay(1000);
*GPIOClear = mask;
delay(1000);
}
Page 318
#include "soc/gpio_reg.h"
uint32_t mask = 1 << 2;
void setup() {
pinMode(2, OUTPUT);
}
void loop() {
*(int32_t*)GPIO_OUT_W1TS_REG = mask;
delay(1000);
*(int32_t*)GPIO_OUT_W1TC_REG = mask;
delay(1000);
}
Path 320
#include "soc/gpio_reg.h"
uint32_t mask = (1 << 2) | (1 << 4);
uint32_t value1 = (1 << 2);
uint32_t value2 = (1 << 4);
void gpio_value_mask(int32_t value, int32_t mask) {
*(int32_t*)GPIO_OUT_REG = (*(int32_t*)GPIO_OUT_REG & ~mask) | (value & mask);
}
void setup() {
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
}
void loop() {
gpio_value_mask(value1, mask);
gpio_value_mask(value2, mask);
}
Path 322
Does not work on NANO ESP32
bool isrollover(int timer) {
int32_t *base=(int32_t*)0x600190C0; //ESP32 S3
//int32_t *base=(int32_t*)0x3FF59180; //ESP32
bool value = *((int32_t*)base) & 1<<timer;
*((int32_t*)base+3) = 1<<timer;
return value;
}
uint8_t wave[256];
void setup() {
ledcAttach(2, 150000, 8);
for (int i = 0; i < 256; i++) {
wave[i] = (uint8_t)((128.0 +
sinf((float)i * 2.0 * 3.14159 / 255.0) * 128.0));
}
}
void loop() {
for (int i = 0; i < 256; i++) {
analogWrite(2, wave[i]);
while (!isrollover(0)) {};
}
}
Page 325
Does not work on NANO ESP32 as the header file is not installed.
#include "esp_netif_sntp.h"
#include <WiFi.h>
int wifiConnect(char* ssid, char* password) {
int status = WiFi.begin(ssid, password);
while (status != WL_CONNECTED) {
switch (status) {
case WL_NO_SSID_AVAIL:
Serial.printf("No AP with name %s can be found", ssid);
return status;
case WL_CONNECT_FAILED:
Serial.printf("Connection failed");
return status;
case WL_CONNECTION_LOST:
Serial.printf("Connection lost possible security problem");
return status;
}
delay(100);
status = WiFi.status();
}
return status;
}
void setup() {
Serial.begin(9600);
delay(2000);
Serial.begin(9600);
Serial.println();
int status = wifiConnect("ssid", "password");
Serial.println(status);
esp_sntp_config_t config =
ESP_NETIF_SNTP_DEFAULT_CONFIG("pool.ntp.org");
esp_netif_sntp_init(&config);
if (esp_netif_sntp_sync_wait(pdMS_TO_TICKS(10000)) != ESP_OK)
{
printf("Failed to update system time within 10s timeout");
}
struct timeval t;
gettimeofday(&t, NULL);
setenv("TZ", "UTC-1", 1);
tzset();
struct tm *tm = localtime(&(t.tv_sec));
printf("hour = %d\n", tm->tm_hour);
printf("min = %d\n", tm->tm_min);
char date[100];
strftime(date, 100, "%a, %d %b %Y %T", tm);
printf("date = %s\n", date);
}
void loop() {
}
Page 328
Does not work on NANO ESP32 because of problem restarting USB serial connection
void setup() {
Serial.begin(9600);
Serial.println();
}
void loop() {
esp_sleep_enable_timer_wakeup(1000000);
for (int i = 0; i < 10; i++) {
Serial.printf("starting sleep %d \n", i);
Serial.flush();
esp_light_sleep_start();
Serial.printf("back from sleep %d \n", i);
}
}