Hardware Timers

ESP32 has 4 individual hardware timers, arranged as 2 timers x 2 timer groups. All 4 are 64-bit generic timers based on 16-bit prescalers and 64-bit auto-reload-capable up / down counters. Resources https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/timer.html Example using Timer TG0 as 100uS irq Timer #include <stdio.h> #include <string.h> #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "rom/ets_sys.h" #include "rom/gpio.h" #include <stddef.h> […]

Read More

.Interrupts General

What can you do in interrupts In ISR functions you can do only simple thing, not time consuming operations. Disable interrupts You can suspend interrupts and context switches by calling  portDISABLE_INTERRUPTS and the interrupts on that core should stop firing, stopping task switches as well. Call portENABLE_INTERRUPTS after you're done

Read More

Creating tasks

TaskScheduler vTaskStartScheduler(); //<<<This FreeRTOS call is not required as the scheduler is already started before app_main() call Create New xTask Tasks should never return (i.e. be a continuous loop). xTaskCreate( [pointer to the function which will execute when the task is scheduled to run], [descriptive name for the the task, up to 16 chars, mainly […]

Read More

Using the I2C interface

Resources https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/i2c.html https://github.com/espressif/esp-idf/tree/master/examples/peripherals/i2c I2C Master Example #include "driver/i2c.h" #define EXAMPLE_I2C_PORT_NUMBER I2C_NUM_1 //I2C port number #define EXAMPLE_I2C_SCL_GPIO 16 //GPIO pin #define EXAMPLE_I2C_SDA_GPIO 17 //GPIO pin #define EXAMPLE_I2C_FREQ_HZ 100000 //!< I2C master clock frequency #define EXAMPLE_I2C_ADDR 0x98 #define EXAMPLE_I2C_WRITE_BIT I2C_MASTER_WRITE #define EXAMPLE_I2C_READ_BIT I2C_MASTER_READ #define EXAMPLE_I2C_ACK_CHECK_EN 0x1 #define EXAMPLE_I2C_ACK_CHECK_DIS 0x0 #define EXAMPLE_I2C_ACK_VAL 0x0 #define EXAMPLE_I2C_NACK_VAL 0x1 //—– CREATE […]

Read More

IO Pin Control – General

  Input Pins gpio_set_direction(GPIO_NUM_4, GPIO_MODE_INPUT); if (gpio_get_level(GPIO_NUM_4)) //Do something Output Pins gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT); gpio_set_level(GPIO_NUM_4, 1); //Set high gpio_set_level(GPIO_NUM_4, 0); //Set low  

Read More

Delays

Delay in mS vTaskDelay(2000 / portTICK_PERIOD_MS);   The RTOS tick period is (by default) 10ms N.B. We've found using a value less than the RTOS tick rate, so (10 / portTICK_PERIOD_MS), results in a delay of 100mS regardless of the value used!  Even vTaskDelay(10) does it.  This seems like it must be a bug that […]

Read More

Making Eclipse work properly

Eclipse defaults are different to lots of IDE's we use on Windows, here's how we fix eclipse… Open eclipse preferences: Menu > Window > Preferences General > Workspace > Build > Save automatically before build General > Keys To Upper Case – Ctrl + Shift + U To Lower Case – Ctrl + Shift + L […]

Read More

.Creating A New Project

NOTE: The esp-idf build system does not support spaces in paths to esp-idf or to projects The default location to create a project is in: C:\msys32\home\[YOUR USER NAME]\esp Create Project In Eclipse Copy your sample \ template project files to: C:\msys32\home\[YOUR USER NAME]\esp Then follow these instrucitons to configure eclipse for your project (based on: https://docs.espressif.com/projects/esp-idf/en/stable/get-started/eclipse-setup-windows.html#eclipse-windows-setup ) Import New […]

Read More

Terminal window

Open the terminal window Use Windows start button > Run C:\msys32\mingw32.exe Configure Tool https://docs.espressif.com/projects/esp-idf/en/stable/get-started/index.html#get-started-get-esp-idf Enter the following in the terminal window cd ~/esp/[MY PROJECT NAME] make menuconfig Monitor Tool Use to view the output of your application and send keystrokes to it. cd ~/esp/[MY PROJECT NAME] make monitor Anything you type is sent through the […]

Read More