nkolban / esp32-snippets

Sample ESP32 snippets and code fragments
https://leanpub.com/kolban-ESP32
Apache License 2.0
2.35k stars 710 forks source link

stuck with u8g2 and i2c #857

Closed colaphile closed 5 years ago

colaphile commented 5 years ago

Hi there!

I would like to use u8g2 in I₂C mode. I have copied your files into a clean project but it crashes after I₂C initialization. I'm sure that my PINs, wires and connection are ok, because this board works when I compile it with Arduino framework. My board is TTGO T-Eight, which contains an esp32, sh1106 and a 12864 oled.

On Arduino I'm using this board:

U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

This is my test_sh1106_i2c.c

// SDA - GPIO21
#define PIN_SDA 21

// SCL - GPIO22
#define PIN_SCL 22

static const char *TAG = "sh1106";

void task_test_SH1306i2c(void *ignore) {
    u8g2_esp32_hal_t u8g2_esp32_hal = U8G2_ESP32_HAL_DEFAULT;
    u8g2_esp32_hal.sda   = PIN_SDA;
    u8g2_esp32_hal.scl  = PIN_SCL;
    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_Setup_sh1106_i2c_128x64_noname_f(
        &u8g2,
        U8G2_R0,
        //u8x8_byte_sw_i2c,
        u8g2_esp32_i2c_byte_cb,
        u8g2_esp32_gpio_and_delay_cb);  // init u8g2 structure
    u8x8_SetI2CAddress(&u8g2.u8x8, 0x78);
    // u8g2_SetI2CAddress(&u8g2, 0x78); // is also failed.

    ESP_LOGI(TAG, "u8g2_InitDisplay");
    u8g2_InitDisplay(&u8g2); // send init sequence to the display, display is in sleep mode after this,

    // ... Followings are same to your test_SSD1306_i2c.c

    u8g2_SendBuffer(&u8g2);

    ESP_LOGI(TAG, "All done!");

    vTaskDelete(NULL);
}

This is output during start on VSPI and HSPI

ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x33 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:6352
ho 0 tail 12 room 4
load:0x40078000,len:11308
load:0x40080400,len:6680
entry 0x40080760
I (30) boot: ESP-IDF v4.0-dev-16-g7541d2352 2nd stage bootloader
I (30) boot: compile time 01:20:34
I (40) boot: Enabling RNG early entropy source...
I (40) boot: SPI Speed      : 40MHz
I (40) boot: SPI Mode       : DIO
I (44) boot: SPI Flash Size : 4MB
I (48) boot: Partition Table:
I (52) boot: ## Label            Usage          Type ST Offset   Length
I (59) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (67) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (74) boot:  2 factory          factory app      00 00 00010000 00100000
I (82) boot: End of partition table
I (86) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x0b1b0 ( 45488) map
I (111) esp_image: segment 1: paddr=0x0001b1d8 vaddr=0x3ffb0000 size=0x01ebc (  7868) load
I (114) esp_image: segment 2: paddr=0x0001d09c vaddr=0x40080000 size=0x00400 (  1024) load
0x40080000: _WindowOverflow4 at /Users/colaphile/esp/esp-idf/components/freertos/xtensa_vectors.S:1779

I (118) esp_image: segment 3: paddr=0x0001d4a4 vaddr=0x40080400 size=0x02b6c ( 11116) load
I (131) esp_image: segment 4: paddr=0x00020018 vaddr=0x400d0018 size=0x15c60 ( 89184) map
0x400d0018: _stext at ??:?

I (167) esp_image: segment 5: paddr=0x00035c80 vaddr=0x40082f6c size=0x0656c ( 25964) load
0x40082f6c: esp_ptr_internal at /Users/colaphile/esp/esp-idf/components/spi_flash/flash_mmap.c:375
 (inlined by) spi_flash_mmap_pages at /Users/colaphile/esp/esp-idf/components/spi_flash/flash_mmap.c:151

I (183) boot: Loaded app from partition at offset 0x10000
I (183) boot: Disabling RNG early entropy source...
I (184) cpu_start: Pro cpu up.
I (187) cpu_start: Application information:
I (192) cpu_start: Project name:     hello-world
I (198) cpu_start: App version:      1
I (202) cpu_start: Compile time:     Apr 23 2019 01:20:32
I (208) cpu_start: ELF file SHA256:  3ce6211ba2e2e7dc...
I (214) cpu_start: ESP-IDF:          v4.0-dev-16-g7541d2352
I (220) cpu_start: Starting app cpu, entry point is 0x40080f08
0x40080f08: call_start_cpu1 at /Users/colaphile/esp/esp-idf/components/esp32/cpu_start.c:267

I (0) cpu_start: App cpu up.
I (231) heap_init: Initializing. RAM available for dynamic allocation:
I (238) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (244) heap_init: At 3FFB3330 len 0002CCD0 (179 KiB): DRAM
I (250) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (256) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (263) heap_init: At 400894D8 len 00016B28 (90 KiB): IRAM
I (269) cpu_start: Pro cpu start user code
I (287) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
Hello world!
This is ESP32 chip with 2 CPU cores, WiFi/BT/BLE, silicon revision 1, 4MB external flash

I would be appreciate if you can give my any tips why it fails to work ;). Thank you.

Best Regards, Hoo.

colaphile commented 5 years ago

Sorry for that.

I write a esp_restart(); after xTaskCreate(task_test_SH1306i2c......

how embarrassed of me...