我正在使用https://github.com/nkolban/esp32-snippets/tree/master/hardware/displays/U8G2庫作為 WROOM32 ESP32 開發模塊。當我掃描 i2c 時,我得到了這個結果:
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
當我在任務中呼叫我的 OLED 時,ESP 一遍又一遍地重新啟動,并在終端中出現此錯誤:
?[0;32mI (0) cpu_start: Starting scheduler on APP CPU.?[0m
?[0;32mI (0) u8g2_hal: sda_io_num 22?[0m
?[0;32mI (0) u8g2_hal: scl_io_num 19?[0m
?[0;32mI (10) u8g2_hal: clk_speed 1000000?[0m
?[0;32mI (10) u8g2_hal: i2c_param_config 1?[0m
?[0;31mE (20) i2c: i2c_param_config(647): i2c clock choice is invalid, please check flag and frequency?[0m
?[0;31mE (30) err: esp_err_t = 258?[0m
assertion "0 && "i2c_param_config(I2C_MASTER_NUM, &conf)"" failed: file "src/u8g2_esp32_hal.c", line 129, function: u8g2_esp32_i2c_byte_cb
這是我的完整代碼:
#include <driver/i2c.h>
#include <esp_log.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <stdio.h>
#include "sdkconfig.h"
#include "driver/gpio.h"
#include <u8g2.h>
#include <u8g2_esp32_hal.h>
#define SDA_PIN 22
#define SCL_PIN 19
static char tag[] = "i2cscanner";
void task_i2cscanner(void *ignore) {
//The scanner works!
ESP_LOGD(tag, ">> i2cScanner");
i2c_config_t conf;
conf.mode = I2C_MODE_MASTER;
conf.sda_io_num = SDA_PIN;
conf.scl_io_num = SCL_PIN;
conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
conf.master.clk_speed = 100000;
i2c_param_config(I2C_NUM_0, &conf);
i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);
int i;
esp_err_t espRc;
printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\n");
printf("00: ");
for (i=3; i< 0x78; i ) {
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (i << 1) | I2C_MASTER_WRITE, 1 /* expect ack */);
i2c_master_stop(cmd);
espRc = i2c_master_cmd_begin(I2C_NUM_0, cmd, 10/portTICK_PERIOD_MS);
if (i%16 == 0) {
printf("\n%.2x:", i);
}
if (espRc == 0) {
printf(" %.2x", i);
} else {
printf(" --");
}
//ESP_LOGD(tag, "i=%d, rc=%d (0x%x)", i, espRc, espRc);
i2c_cmd_link_delete(cmd);
}
printf("\n");
vTaskDelete(NULL);
}
void task_test_SSD1306i2c(void *pvParameter)
{
//The display does not work!
u8g2_esp32_hal_t u8g2_esp32_hal = U8G2_ESP32_HAL_DEFAULT;
u8g2_esp32_hal.sda = SDA_PIN;
u8g2_esp32_hal.scl = SCL_PIN;
u8g2_esp32_hal_init(u8g2_esp32_hal);
u8g2_t u8g2; // a structure which will contain all the data for one display
u8g2_Setup_ssd1306_i2c_128x32_univision_f(
&u8g2,
U8G2_R0,
//u8x8_byte_sw_i2c,
u8g2_esp32_i2c_byte_cb,
u8g2_esp32_gpio_and_delay_cb);
u8x8_SetI2CAddress(&u8g2.u8x8, 0x3c);
u8g2_InitDisplay(&u8g2);
u8g2_SetPowerSave(&u8g2, 0);
u8g2_ClearBuffer(&u8g2);
u8g2_DrawBox(&u8g2, 0, 26, 80, 6);
u8g2_DrawFrame(&u8g2, 0, 26, 100, 6);
u8g2_SetFont(&u8g2, u8g2_font_ncenB14_tr);
u8g2_DrawStr(&u8g2, 2, 17, "Hi nkolban!");
u8g2_SendBuffer(&u8g2);
printf("All done!");
vTaskDelete(NULL);
}
void app_main()
{
ets_timer_init();
//xTaskCreate(&task_i2cscanner, "task_i2cscanner", 4096, NULL, 10, NULL);
xTaskCreate(&task_test_SSD1306i2c, "task_test_SSD1306i2c", 4096, NULL, 10, NULL);
}
問題:我在使用顯示幕時做錯了什么?
uj5u.com熱心網友回復:
相對于較新版本的 ESP IDF,該庫已過時。I2C 配置結構已收到clk_flags此庫未設定的新成員。請參閱此執行緒中的詳細資訊。
您可以退回到舊版本的 ESP IDF(不知道是哪個,抱歉)或修復 U8G2 庫(看起來很簡單,請查看參考檔案)。
uj5u.com熱心網友回復:
在第 127 行之后的 u8g2_esp32_hal.c 檔案中:
conf.master.clk_speed = I2C_MASTER_FREQ_HZ;
嘗試添加行:
conf.master.clk_flags = 0;
我相信你的問題是沒有設定 clk_flags
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/366243.html
上一篇:(宏 1)和(1 宏)區別的原因
