Espressif ESP32-S2 Programming Manual page 1062

Table of Contents

Advertisement

Chapter 2. API Reference
• Internal 90kHz RC oscillator (default): Features lowest deep sleep current consumption and no
dependence on any external components. However, as frequency stability is affected by temperature fluctua-
tions, time may drift in both Deep and Light sleep modes.
• External 32kHz crystal: Requires a 32kHz crystal to be connected to the 32K_XP and 32K_XN pins.
Provides better frequency stability at the expense of slightly higher (by 1 uA) Deep sleep current consumption.
• External 32kHz oscillator at 32K_XN pin: Allows using 32kHz clock generated by an external
circuit. The external clock signal must be connected to the 32K_XN pin. The amplitude should be less than
1.2 V for sine wave signal and less than 1 V for square wave signal. Common mode voltage should be in the
range of 0.1 < Vcm < 0.5xVamp, where Vamp is signal amplitude. Additionally, a 1 nF capacitor must be
placed between the 32K_XP pin and ground. In this case, the 32K_XP pin cannot be used as a GPIO pin.
• Internal 8.5MHz oscillator, divided by 256 (~33kHz): Provides better frequency
stability than the internal 90kHz RC oscillator at the expense of higher (by 5 uA) deep sleep
current consumption. It also does not require external components.
The choice depends on your requirements for system time accuracy and power consumption in sleep modes. To
modify the RTC clock source, set
More details on wiring requirements for the External 32kHz crystal and External 32kHz oscil-
lator at 32K_XN pin sources can be found in Section Crystal Oscillator of
Guidelines.
Get Current Time
To get the current time, use the POSIX function gettimeofday(). Additionally, you can use the following
standard C library functions to obtain time and manipulate it:
gettimeofday
time
asctime
clock
ctime
difftime
gmtime
localtime
mktime
strftime
adjtime*
* –To stop smooth time adjustment and update the current time immediately, use the POSIX function settime-
ofday().
If you need to obtain time with one second resolution, use the following method:
time_t
now;
char
strftime_buf[64];
struct
tm
timeinfo;
time(&now);
// Set timezone to China Standard Time
setenv("TZ", "CST-8", 1);
tzset();
localtime_r(&now, &timeinfo);
strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
ESP_LOGI(TAG,
"The current date/time in Shanghai is:
If you need to obtain time with one microsecond resolution, use the code snippet below:
struct
timeval
tv_now;
gettimeofday(&tv_now, NULL);
int64_t
time_us
=
(int64_t)tv_now.tv_sec
Espressif Systems
CONFIG_ESP32S2_RTC_CLK_SRC
*
1000000L
1051
Submit Document Feedback
in project configuration.
ESP32-S2 Hardware Design
%s", strftime_buf);
+
(int64_t)tv_now.tv_usec;
Release v4.4

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S2 and is the answer not in the manual?

Table of Contents

Save PDF