From 4793bb3267141bd110bf0f59642393631f92c936 Mon Sep 17 00:00:00 2001 From: Armando Date: Thu, 14 Jan 2021 16:57:10 +0800 Subject: [PATCH] adc: update adc_dma example README.md --- .../{adc_dma_demo => adc_dma}/CMakeLists.txt | 0 examples/peripherals/adc/adc_dma/README.md | 63 +++++++++++++++++++ .../main/CMakeLists.txt | 0 .../main/adc_dma_example_main.c | 8 +-- 4 files changed, 67 insertions(+), 4 deletions(-) rename examples/peripherals/adc/{adc_dma_demo => adc_dma}/CMakeLists.txt (100%) create mode 100644 examples/peripherals/adc/adc_dma/README.md rename examples/peripherals/adc/{adc_dma_demo => adc_dma}/main/CMakeLists.txt (100%) rename examples/peripherals/adc/{adc_dma_demo => adc_dma}/main/adc_dma_example_main.c (96%) diff --git a/examples/peripherals/adc/adc_dma_demo/CMakeLists.txt b/examples/peripherals/adc/adc_dma/CMakeLists.txt similarity index 100% rename from examples/peripherals/adc/adc_dma_demo/CMakeLists.txt rename to examples/peripherals/adc/adc_dma/CMakeLists.txt diff --git a/examples/peripherals/adc/adc_dma/README.md b/examples/peripherals/adc/adc_dma/README.md new file mode 100644 index 0000000000..8d349d76f3 --- /dev/null +++ b/examples/peripherals/adc/adc_dma/README.md @@ -0,0 +1,63 @@ +| Supported Targets | ESP32-C3 | +| ----------------- | -------- | + +# ADC DMA Example + +(See the README.md file in the upper level 'examples' directory for more information about examples.) + +This example shows how to use DMA-Read-APIs and Single-Read-APIs to read voltage from GPIO pins via ADC controller. + +## How to use example + +### Hardware Required + +* A development board with ESP32C3 SoC +* A USB cable for power supply and programming + +For `single_read` (Single-Read-APIs example), we use `ADC1_CHANNEL_2`, `ADC1_CHANNEL_3`, `ADC1_CHANNEL_4`, `ADC2_CHANNEL_0`. Hence we need to connect voltage sources (0 ~ 3.3V) to GPIO2, GPIO3, GPIO4, GPIO5 respectively. + +For `continuous_read` (DMA-Read-APIs example), we use `ADC1_CHANNEL_0`, `ADC1_CHANNEL_1` and `ADC2_CHANNEL_0`. Therefore, GPIO0, GPIO1 and GPIO5 should be connected to voltage sources (0 ~ 3.3V). + +If other ADC units/channels are selected in your application, you need to change the GPIO pin (please refer to the `ESP32C3 Technical Reference Manual`). + +### Configure the project + +``` +idf.py menuconfig +``` + +### Build and Flash + +Build the project and flash it to the board, then run monitor tool to view serial output: + +``` +idf.py -p PORT flash monitor +``` + +(To exit the serial monitor, type ``Ctrl-]``.) + +See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects. + +## Example Output + +Running this example, you will see the following log output on the serial monitor: +``` +I (322) ADC1_CH2: 7c8 +I (322) ADC1_CH3: 278 +I (322) ADC1_CH4: d4b +I (322) ADC2_CH0: 48 +``` +``` +ADC1_CH0: 61b +ADC1_CH1: 39b +ADC2_CH0: 4b +``` + +## Troubleshooting + +* program upload failure + + * Hardware connection is not correct: run `idf.py -p PORT monitor`, and reboot your board to see if there are any output logs. + * The baud rate for downloading is too high: lower your baud rate in the `menuconfig` menu, and try again. + +For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon. diff --git a/examples/peripherals/adc/adc_dma_demo/main/CMakeLists.txt b/examples/peripherals/adc/adc_dma/main/CMakeLists.txt similarity index 100% rename from examples/peripherals/adc/adc_dma_demo/main/CMakeLists.txt rename to examples/peripherals/adc/adc_dma/main/CMakeLists.txt diff --git a/examples/peripherals/adc/adc_dma_demo/main/adc_dma_example_main.c b/examples/peripherals/adc/adc_dma/main/adc_dma_example_main.c similarity index 96% rename from examples/peripherals/adc/adc_dma_demo/main/adc_dma_example_main.c rename to examples/peripherals/adc/adc_dma/main/adc_dma_example_main.c index 005c168375..1adc19b328 100644 --- a/examples/peripherals/adc/adc_dma_demo/main/adc_dma_example_main.c +++ b/examples/peripherals/adc/adc_dma/main/adc_dma_example_main.c @@ -57,7 +57,7 @@ static bool check_valid_data(const adc_digi_output_data_t *data) return true; } -static void continuous_read_demo(void *arg) +static void continuous_read(void *arg) { esp_err_t ret; uint32_t ret_num = 0; @@ -90,7 +90,7 @@ static void continuous_read_demo(void *arg) assert(ret == ESP_OK); } -static void single_read_demo(void *arg) +static void single_read(void *arg) { esp_err_t ret; int adc1_reading[3] = {0xcc}; @@ -123,6 +123,6 @@ static void single_read_demo(void *arg) void app_main() { - single_read_demo(NULL); - continuous_read_demo(NULL); + single_read(NULL); + continuous_read(NULL); }