关于IDF的pcnt例程

最近调试IDF中的pcnt,最开始使用的芯片是ESP32C3,编译时会报错

/home/ubuntu/.espressif/tools/riscv32-esp-elf/esp-2022r1-11.2.0/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/11.2.0/../../../../riscv32-esp-elf/bin/ld: /home/ubuntu/project/esp32c3/v5.0/rotary_encoder/build/../main/rotary_encoder_example_main.c:83: undefined reference to `pcnt_unit_clear_count'
/home/ubuntu/.espressif/tools/riscv32-esp-elf/esp-2022r1-11.2.0/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/11.2.0/../../../../riscv32-esp-elf/bin/ld: /home/ubuntu/project/esp32c3/v5.0/rotary_encoder/build/../main/rotary_encoder_example_main.c:85: undefined reference to `pcnt_unit_start'
/home/ubuntu/.espressif/tools/riscv32-esp-elf/esp-2022r1-11.2.0/riscv32-esp-elf/bin/../lib/gcc/riscv32-esp-elf/11.2.0/../../../../riscv32-esp-elf/bin/ld: /home/ubuntu/project/esp32c3/v5.0/rotary_encoder/build/../main/rotary_encoder_example_main.c:101: undefined reference to `pcnt_unit_get_count'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
ninja failed with exit code 1, output of the command is in the

会报各种未定义的错误,实际上是有的,在driver/pulse_cnt.h下面有声明,无意间把target改成ESP32S3编译没问题
例外一个python脚本文件中有这么一段,猜测应该是支持的型号吧
在这里插入图片描述

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是 ESP-IDF 中使用 WiFi TCP 发送数据的示例代码: ```c #include <stdio.h> #include <string.h> #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_wifi.h" #include "esp_event_loop.h" #include "esp_log.h" #include "tcpip_adapter.h" #define EXAMPLE_ESP_WIFI_SSID "your_wifi_ssid" #define EXAMPLE_ESP_WIFI_PASS "your_wifi_password" #define EXAMPLE_ESP_MAXIMUM_RETRY 3 static const char *TAG = "example"; static EventGroupHandle_t s_wifi_event_group; const int WIFI_CONNECTED_BIT = BIT0; static int s_retry_num = 0; static void wifi_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { if (event_id == WIFI_EVENT_STA_START) { esp_wifi_connect(); } else if (event_id == WIFI_EVENT_STA_DISCONNECTED) { if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) { esp_wifi_connect(); s_retry_num++; ESP_LOGI(TAG, "retry to connect to the AP"); } ESP_LOGI(TAG,"connect to the AP fail"); } else if (event_id == IP_EVENT_STA_GOT_IP) { ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip)); s_retry_num = 0; xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); } } void wifi_init_sta(void) { s_wifi_event_group = xEventGroupCreate(); tcpip_adapter_init(); ESP_ERROR_CHECK(esp_event_loop_create_default()); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); wifi_config_t wifi_config = { .sta = { .ssid = EXAMPLE_ESP_WIFI_SSID, .password = EXAMPLE_ESP_WIFI_PASS, }, }; ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config)); ESP_ERROR_CHECK(esp_wifi_start()); ESP_LOGI(TAG, "wifi_init_sta finished."); xEventGroupWaitBits(s_wifi_event_group, WIFI_CONNECTED_BIT, false, true, portMAX_DELAY); } void tcp_client_task(void *pvParameters) { char buffer[128]; int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); if (sock < 0) { ESP_LOGE(TAG, "Unable to create socket: errno %d", errno); vTaskDelete(NULL); return; } struct sockaddr_in server_address; server_address.sin_family = AF_INET; server_address.sin_addr.s_addr = inet_addr("192.168.1.100"); server_address.sin_port = htons(8080); int err = connect(sock, (struct sockaddr *)&server_address, sizeof(server_address)); if (err != 0) { ESP_LOGE(TAG, "Socket unable to connect: errno %d", errno); close(sock); vTaskDelete(NULL); return; } while (1) { sprintf(buffer, "Hello from ESP32!"); int err = send(sock, buffer, strlen(buffer), 0); if (err < 0) { ESP_LOGE(TAG, "Error occurred during sending: errno %d", errno); break; } vTaskDelay(2000 / portTICK_PERIOD_MS); } shutdown(sock, 0); close(sock); vTaskDelete(NULL); } void app_main() { ESP_LOGI(TAG, "ESP_WIFI_MODE_STA"); wifi_init_sta(); xTaskCreate(tcp_client_task, "tcp_client", 4096, NULL, 5, NULL); } ``` 以上代码实现了一个 TCP 客户端任务,与 IP 地址为 192.168.1.100、端口号为 8080 的服务器建立连接,并每隔 2 秒发送一条字符串数据。在使用时需要将 EXAMPLE_ESP_WIFI_SSID 和 EXAMPLE_ESP_WIFI_PASS 替换为实际的 WiFi SSID 和密码,并且根据实际情况修改服务器的 IP 地址和端口号。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值