diff --git a/examples/peripherals/mcpwm/mcpwm_sync/main/mcpwm_sync_example_main.c b/examples/peripherals/mcpwm/mcpwm_sync/main/mcpwm_sync_example_main.c index c05aa0e000..bb7279d0f7 100644 --- a/examples/peripherals/mcpwm/mcpwm_sync/main/mcpwm_sync_example_main.c +++ b/examples/peripherals/mcpwm/mcpwm_sync/main/mcpwm_sync_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -28,6 +28,12 @@ static void example_setup_sync_strategy(mcpwm_timer_handle_t timers[]) // | | | // v v v // timer0 timer1 timer2 + gpio_config_t sync_gpio_conf = { + .mode = GPIO_MODE_OUTPUT, + .pin_bit_mask = BIT(EXAMPLE_SYNC_GPIO), + }; + ESP_ERROR_CHECK(gpio_config(&sync_gpio_conf)); + ESP_LOGI(TAG, "Create GPIO sync source"); mcpwm_sync_handle_t gpio_sync_source = NULL; mcpwm_gpio_sync_src_config_t gpio_sync_config = { @@ -35,7 +41,6 @@ static void example_setup_sync_strategy(mcpwm_timer_handle_t timers[]) .gpio_num = EXAMPLE_SYNC_GPIO, .flags.pull_down = true, .flags.active_neg = false, // by default, a posedge pulse can trigger a sync event - .flags.io_loop_back = true, // then we can trigger a sync event using `gpio_set_level` on the same GPIO }; ESP_ERROR_CHECK(mcpwm_new_gpio_sync_src(&gpio_sync_config, &gpio_sync_source)); @@ -50,8 +55,9 @@ static void example_setup_sync_strategy(mcpwm_timer_handle_t timers[]) } ESP_LOGI(TAG, "Trigger a pulse on the GPIO as a sync event"); - gpio_set_level(EXAMPLE_SYNC_GPIO, 0); - gpio_set_level(EXAMPLE_SYNC_GPIO, 1); + ESP_ERROR_CHECK(gpio_set_level(EXAMPLE_SYNC_GPIO, 0)); + ESP_ERROR_CHECK(gpio_set_level(EXAMPLE_SYNC_GPIO, 1)); + ESP_ERROR_CHECK(gpio_reset_pin(EXAMPLE_SYNC_GPIO)); } #endif // CONFIG_EXAMPLE_SYNC_FROM_GPIO