The time synchronization period is determined by CONFIG_LWIP_SNTP_UPDATE_DELAY (the default value is one hour). Sntp_setoperatingmode ( SNTP_OPMODE_POLL ) sntp_setservername ( 0, "" ) sntp_init () Īn application with this initialization code will periodically synchronize the time. To start synchronization via SNTP, just call the following three functions: Sntp_get_sync_status() and sntp_set_sync_status(): Can be used to get/set time synchronization status. Sntp_set_time_sync_notification_cb(): Can be used to set a callback function that will notify of the time synchronization process. The lwIP SNTP library has API functions for setting a callback function for a certain event. If the difference between the SNTP response time and system time is more than 35 minutes, update system time immediately by using settimeofday(). SNTP_SYNC_MODE_SMOOTH: Updates time smoothly by gradually reducing time error using the function adjtime(). SNTP_SYNC_MODE_IMMED (default): Updates system time immediately upon receiving a response from the SNTP server after using settimeofday(). Use the function sntp_set_sync_mode() to set one of the following sync modes: The function to use inside the lwIP SNTP library depends on the sync mode for system time. These functions can also be used separately from the lwIP SNTP library. They are used internally in the lwIP SNTP library to set current time when a response from the NTP server is received. To set the current time, you can use the POSIX functions settimeofday() and adjtime(). Struct timeval tv_now gettimeofday ( & tv_now, NULL ) int64_t time_us = ( int64_t ) tv_now. Additionally, you can use the following standard C library functions to obtain time and manipulate it: To get the current time, use the POSIX function gettimeofday(). More details about the wiring requirements for the external crystal or external oscillator, please refer to ESP32 Hardware Design Guidelines. To modify the RTC clock source, set CONFIG_RTC_CLK_SRC in project configuration. The choice depends on your requirements for system time accuracy and power consumption in sleep modes. It also does not require external components. Internal 8.5 MHz oscillator, divided by 256 (~33 kHz): Provides better frequency stability than the Internal 150 kHz RC oscillator at the expense of a higher (by 5 μA) Deep-sleep current consumption. In this case, the 32K_XN pin cannot be used as a GPIO pin. Common mode voltage should be in the range of 0.1 < Vcm < 0.5xVamp, where Vamp stands for signal amplitude. The amplitude should be less than 1.2 V for sine wave signal and less than 1 V for square wave signal. The external clock signal must be connected to the 32K_XN pin. This source provides a better frequency stability at the expense of a slightly higher (by 1 μA) Deep-sleep current consumption.Įxternal 32 kHz oscillator at 32K_XN pin: Allows using 32 kHz clock generated by an external circuit. However, the frequency stability of this clock source is affected by temperature fluctuations, so time may drift in both Deep-sleep and Light-sleep modes.Įxternal 32 kHz crystal: Requires a 32 kHz crystal to be connected to the 32K_XP and 32K_XN pins. Internal 150 kHz RC oscillator (default): Features the lowest Deep-sleep current consumption and no dependence on any external components. The RTC timer has the following clock sources: However, users can also select a different setting via the CONFIG_NEWLIB_TIME_SYSCALL configuration option. It is recommended that users stick to the default option as it provides the highest accuracy. The possible combinations of hardware timers used to keep system time are listed below: Time will be measured at 1 μs resolution. The timer uses the APB_CLK clock source (typically 80 MHz), which has a frequency deviation of less than ☑0 ppm. High-resolution timer: This timer is not available in sleep modes and will not persist over a reset, but has greater accuracy. The frequency deviation depends on the RTC Timer Clock Sources and affects the accuracy only in sleep modes, in which case the time will be measured at 6.6667 μs resolution. RTC timer: This timer allows time keeping in various sleep modes, and can also persist time keeping across any resets (with the exception of power-on resets which reset the RTC timer). System time can be kept by using either one or both of the hardware timers depending on the application’s purpose and accuracy requirements for system time. ESP32 uses two hardware timers for the purpose of keeping system time.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |