CHQ1838引腳示意圖
2.png (36.61 KB, 下載次數(shù): 78)
下載附件
2021-8-20 17:36 上傳
1.png (24.76 KB, 下載次數(shù): 77)
下載附件
2021-8-20 17:36 上傳
源程序如下:
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "freertos/queue.h"
- #include "driver/gpio.h"
- #include "esp_log.h"
- #include "esp_system.h"
- static const char *TAG = "main";
- #define GPIO_INPUT_IO_2 2 // D4
- #define GPIO_INPUT_PIN_SEL (1ULL<<GPIO_INPUT_IO_2)
- static xQueueHandle gpio_evt_queue = NULL;
- extern uint32_t esp_get_time(void); // 獲取當前啟動毫秒數(shù)
- static void gpio_task_example(void *arg)
- {
- uint32_t interval_us,ms;
- for (;;) {
- if (xQueueReceive(gpio_evt_queue, &interval_us, portMAX_DELAY)) {
- // ESP_LOGI(TAG, "GPIO failling edge interval time: %d\n", interval_us);
- // printf("data is: ");
- ms = interval_us / 100;
- if (ms <= 150 && ms >= 120 ) // 在 12 - 15 ms之間認為是前導碼
- {
- printf("\n start ");
- }
- else if (ms < 20 && ms >= 10) // 在 1 - 2 ms之間認為是0
- {
- printf("0 ");
- }
- else if (ms <= 30 && ms >= 20) // 在2 - 3 ms之間認為是1
- {
- printf("1 ");
- }
- }
- }
- }
- uint32_t first_time = 0, second_time = 0,interval_time = 0;
- static void monitor_chq1838_break(void *arg){
- first_time = second_time;
- second_time = esp_get_time();
- interval_time = second_time - first_time;
- xQueueSendFromISR(gpio_evt_queue, &interval_time, NULL);
- }
- void app_main(void)
- {
- gpio_config_t io_conf;
- io_conf.intr_type = GPIO_INTR_NEGEDGE;
- io_conf.mode = GPIO_MODE_INPUT;
- io_conf.pin_bit_mask = GPIO_INPUT_PIN_SEL;
- io_conf.pull_down_en = 0;
- io_conf.pull_up_en = 1;
- gpio_config(&io_conf);
- gpio_evt_queue = xQueueCreate(100, sizeof(uint32_t));
- xTaskCreate(gpio_task_example, "gpio_task_example", 2048, NULL, 10, NULL);
- gpio_install_isr_service(0);
- gpio_isr_handler_add(GPIO_INPUT_IO_2, monitor_chq1838_break, (void *) GPIO_INPUT_IO_2);
- while (1) {
- vTaskDelay(1000 / portTICK_RATE_MS);
- }
- }
復制代碼
手冊下載:
CHQ1838.PDF
(806.72 KB, 下載次數(shù): 13)
2021-8-20 17:34 上傳
點擊文件名下載附件
中文手冊 下載積分: 黑幣 -5
|