So I went here and tried, on the one hand, to get the interface for the IC2 to work and to make the Adafruit library C suitable, at least the part that I need.
My main problem is that I can't seem to get the oscillator to work and the displays just stay off.
SO I WOULD BE VERY HAPPY IF SOMEONE COULD HELP ME FURTHER.
- main.c VZ_Seg_setDisplay(&VZ_DISP_1, "ABCD");
- VZ_Seg_setDisplay(&VZ_DISP_2, "1234");
- VZ_Seg_setDisplay(&VZ_DISP_3, "BLUB");
- I2Ccon.c //###############################################################################################################################
- // Unsere I2Ccon.c für die Initialisierung I2C Geräte und dem Master auf dem I2C-Bus unser Wrover-Kit
- //###############################################################################################################################
- #include "../include/I2Ccon.h"
- //###############################################################################################################################
- #define CHECK_ARG(ARG) do { if (!ARG) return ESP_ERR_INVALID_ARG; } while (0)
- //###############################################################################################################################
- // Master-Config
- // #define CONFIG_SCL_GPIO 0 // Definieren wiir über ide menuconfig
- // #define CONFIG_SDA_GPIO 2
- #define I2C_MASTER_PORT I2C_NUM_0 // Standartport
- #define I2C_MASTER_TX_BUF_ENABLE 0
- #define I2C_MASTER_RX_BUF_ENABLE 0
- #define I2C_MASTER_FREQ_HZ 100000 // Taktfrequenz
- // Geräte im Bus und ihre Adressen
- #define BTTF_RTC_ADDR 0x68 //*!< RTC device address */
- #define VZ_DISP_1_ADDR 0x70 //*!< HT16K33 device address 1 */
- #define VZ_DISP_2_ADDR 0x71 //*!< HT16K33 device address 2 */
- #define VZ_DISP_3_ADDR 0x72 //*!< HT16K33 device address 3 */
- // Flag, um den I2C-Master-Status zu überprüfen
- static bool i2c_master_initialized = false;
- i2c_dev_t BTTF_RTC, VZ_DISP_1, VZ_DISP_2, VZ_DISP_3;
- // I2C //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //###############################################################################################################################
- // Zuerst initialisiern wir den Master für den I2C-Bus (in unserem Fall das Wrover-Kit)
- esp_err_t BTTF_i2c_master_init(i2c_port_t port, int sda, int scl)
- {
- // Nur initialisieren, wenn noch nicht geschehen
- if (!i2c_master_initialized) {
- uint8_t i2c_master_port = I2C_MASTER_PORT;
- i2c_config_t conf = {
- .mode = I2C_MODE_MASTER,
- .sda_io_num = CONFIG_SDA_GPIO,
- .scl_io_num = CONFIG_SCL_GPIO,
- .sda_pullup_en = GPIO_PULLUP_ENABLE,
- .scl_pullup_en = GPIO_PULLUP_ENABLE,
- .master.clk_speed = I2C_MASTER_FREQ_HZ,
- };
- esp_err_t i2c_init_result = i2c_param_config(i2c_master_port, &conf);
- ESP_ERROR_CHECK(i2c_init_result);
- i2c_init_result = i2c_driver_install(
- i2c_master_port,
- conf.mode,
- I2C_MASTER_RX_BUF_ENABLE,
- I2C_MASTER_TX_BUF_ENABLE,
- 0
- );
- if (i2c_init_result != ESP_OK) {
- ESP_LOGE(TAG, "Fehler bei der Installation des I2C-Treibers: %d", i2c_init_result);
- const char *driver_err_msg = esp_err_to_name(i2c_init_result);
- ESP_LOGE(TAG, "I2C-Treiberfehlermeldung: %s", driver_err_msg);
- } else {
- ESP_LOGI(TAG, "I2C-Master initialisiert");
- i2c_master_initialized = true; // Setze das Flag, dass der I2C-Master initialisiert wurde
- I2C_Scan(); // DEBUG-Funktion Scannt den I2C Bus auf vorhandene Geräte
- }
- return i2c_init_result; // Hier wird der Rückgabewert übergeben
- }
- // Falls bereits initialisiert, gebe ESP_OK zurück
- return ESP_OK;
- }
- // DEBUG: Hilfsfunktion um den IC2 Bus auf Geräte zu scannen
- static esp_err_t check_adress_for_device(uint8_t device_address)
- {
- uint8_t write_buf[2] = {0, 0};
- return i2c_master_write_to_device(I2C_NUM_0, device_address, write_buf, sizeof(write_buf), 10 / portTICK_PERIOD_MS);
- }
- // DEBUG: I2C Bus auf Geräte scannen // Gibt und Anzahl und Adressen von angeschlossenen I2C-Geräten
- void I2C_Scan() {
- size_t devicesDiscovered = 0;
- for (size_t address = 1; address < 127; address++) {
- if (ESP_OK == check_adress_for_device(address)) {
- ESP_LOGI(TAG, "Found device at address 0x%X", address);
- devicesDiscovered++;
- }
- }
- if (devicesDiscovered == 1){
- ESP_LOGI(TAG, "Found %d device\n", (int)devicesDiscovered);
- } else if (devicesDiscovered > 1) {
- ESP_LOGI(TAG, "Found %d devices\n", (int)devicesDiscovered);
- } else {
- ESP_LOGI(TAG, "No devices found\n");
- }
- vTaskDelay(pdMS_TO_TICKS(50));
- }
- void Init_I2C_Devices() {
- // Initialisiere die RTC
- if (ds3231_init_desc(&BTTF_RTC, I2C_NUM_0, CONFIG_SDA_GPIO, CONFIG_SCL_GPIO) != ESP_OK) {
- ESP_LOGE(TAG, "RTC: Konnte Gerätebeschreibung nicht initialisieren.");
- while (1) { vTaskDelay(100); }
- } else {
- ESP_LOGI(TAG, "RTC erfolgreich initialisiert");
- }
- // Initialisiere das VZ1-Display
- if (VZ1_init_desc(&VZ_DISP_1, I2C_NUM_0, CONFIG_SDA_GPIO, CONFIG_SCL_GPIO) != ESP_OK) {
- ESP_LOGE(TAG, "VZ_DISP_1: Konnte Gerätebeschreibung nicht initialisieren.");
- ESP_LOGE(TAG, "I2C-Treiberfehlermeldung: %s", esp_err_to_name(i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0)));
- while (1) { vTaskDelay(100); }
- } else {
- ESP_LOGI(TAG, "VZ_DISP_1 initialisiert");
- }
- // Initialisiere das VZ2-Display
- if (VZ2_init_desc(&VZ_DISP_2, I2C_NUM_0, CONFIG_SDA_GPIO, CONFIG_SCL_GPIO) != ESP_OK) {
- ESP_LOGE(TAG, "VZ_DISP_2: Konnte Gerätebeschreibung nicht initialisieren.");
- ESP_LOGE(TAG, "I2C-Treiberfehlermeldung: %s", esp_err_to_name(i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0)));
- while (1) { vTaskDelay(100); }
- } else {
- ESP_LOGI(TAG, "VZ_DISP_2 initialisiert");
- }
- // Initialisiere das VZ3-Display
- if (VZ3_init_desc(&VZ_DISP_3, I2C_NUM_0, CONFIG_SDA_GPIO, CONFIG_SCL_GPIO) != ESP_OK) {
- ESP_LOGE(TAG, "VZ_DISP_3: Konnte Gerätebeschreibung nicht initialisieren.");
- ESP_LOGE(TAG, "I2C-Treiberfehlermeldung: %s", esp_err_to_name(i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0)));
- while (1) { vTaskDelay(100); }
- } else {
- ESP_LOGI(TAG, "VZ_DISP_3 initialisiert");
- }
- if (VZ_Seg_begin(&VZ_DISP_1) &&
- VZ_Seg_begin(&VZ_DISP_2) &&
- VZ_Seg_begin(&VZ_DISP_3)) {
- ESP_LOGI(TAG, "Alle Displays erfolgreich initialisiert");
- } else {
- ESP_LOGE(TAG, "Fehler bei der Initialisierung der Displays");
- }
- }
- // Funktion zur Initialisierung der RTC
- esp_err_t ds3231_init_desc(i2c_dev_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)
- {
- CHECK_ARG(dev);
- dev->port = port;
- dev->addr = BTTF_RTC_ADDR; // Verwende die Adresse für die RTC
- dev->sda_io_num = sda_gpio;
- dev->scl_io_num = scl_gpio;
- dev->clk_speed = I2C_MASTER_FREQ_HZ;
- return BTTF_i2c_master_init(port, sda_gpio, scl_gpio);
- }
- // Funktion zur Initialisierung des VZ1-Displays
- esp_err_t VZ1_init_desc(i2c_dev_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)
- {
- CHECK_ARG(dev);
- dev->port = port;
- dev->addr = VZ_DISP_1_ADDR;
- dev->sda_io_num = sda_gpio;
- dev->scl_io_num = scl_gpio;
- dev->clk_speed = I2C_MASTER_FREQ_HZ;
- return BTTF_i2c_master_init(port, sda_gpio, scl_gpio);
- }
- // Funktion zur Initialisierung des VZ2-Displays
- esp_err_t VZ2_init_desc(i2c_dev_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)
- {
- CHECK_ARG(dev);
- dev->port = port;
- dev->addr = VZ_DISP_2_ADDR;
- dev->sda_io_num = sda_gpio;
- dev->scl_io_num = scl_gpio;
- dev->clk_speed = I2C_MASTER_FREQ_HZ;
- return BTTF_i2c_master_init(port, sda_gpio, scl_gpio);
- }
- // Funktion zur Initialisierung des VZ1-Displays
- esp_err_t VZ3_init_desc(i2c_dev_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)
- {
- CHECK_ARG(dev);
- dev->port = port;
- dev->addr = VZ_DISP_3_ADDR;
- dev->sda_io_num = sda_gpio;
- dev->scl_io_num = scl_gpio;
- dev->clk_speed = I2C_MASTER_FREQ_HZ;
- return BTTF_i2c_master_init(port, sda_gpio, scl_gpio);
- }
- //###############################################################################################################################
- I2Ccon.h //###############################################################################################################################
- // Unsere Headerdatei für die Init.c
- //###############################################################################################################################
- #ifndef I2CCON_H
- #define I2CCON_H
- //###############################################################################################################################
- #include "Include.h" // Header-Datei für alle Includes
- extern i2c_dev_t BTTF_RTC, VZ_DISP_1, VZ_DISP_2, VZ_DISP_3; // Geräte-Handels (Objekte) RTC und die 3x ht16k33 14-Seg
- //FUNKTIONSDEKLARATIONEN/////////////////////////////////////////////////////////////////////////////////////////////////////////
- esp_err_t ds3231_init_desc(i2c_dev_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio);
- esp_err_t VZ1_init_desc(i2c_dev_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio);
- esp_err_t VZ2_init_desc(i2c_dev_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio);
- esp_err_t VZ3_init_desc(i2c_dev_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio);
- esp_err_t BTTF_i2c_master_init(i2c_port_t port, int sda, int scl);
- void I2C_Scan();
- extern void Init_I2C_Devices();
- //###############################################################################################################################
- #endif
- VZ_seg.c //###############################################################################################################################
- // Unsere VZ_seg.c für die Vierzehn-Segmentanzeigen die durch HT16K33 gesteuert werden
- //###############################################################################################################################
- #include "../include/VZ_seg.h"
- //###############################################################################################################################
- // DEKLARATIONEN
- const uint16_t alphafonttable[] = {
- 0b0000000000000001, 0b0000000000000010, 0b0000000000000100,
- 0b0000000000001000, 0b0000000000010000, 0b0000000000100000,
- 0b0000000001000000, 0b0000000010000000, 0b0000000100000000,
- 0b0000001000000000, 0b0000010000000000, 0b0000100000000000,
- 0b0001000000000000, 0b0010000000000000, 0b0100000000000000,
- 0b1000000000000000, 0b0000000000000000, 0b0000000000000000,
- 0b0000000000000000, 0b0000000000000000, 0b0000000000000000,
- 0b0000000000000000, 0b0000000000000000, 0b0000000000000000,
- 0b0001001011001001, 0b0001010111000000, 0b0001001011111001,
- 0b0000000011100011, 0b0000010100110000, 0b0001001011001000,
- 0b0011101000000000, 0b0001011100000000,
- 0b0000000000000000, //
- 0b0000000000000110, // !
- 0b0000001000100000, // "
- 0b0001001011001110, // #
- 0b0001001011101101, // $
- 0b0000110000100100, // %
- 0b0010001101011101, // &
- 0b0000010000000000, // '
- 0b0010010000000000, // (
- 0b0000100100000000, // )
- 0b0011111111000000, // *
- 0b0001001011000000, // +
- 0b0000100000000000, // ,
- 0b0000000011000000, // -
- 0b0100000000000000, // .
- 0b0000110000000000, // /
- 0b0000110000111111, // 0
- 0b0000000000000110, // 1
- 0b0000000011011011, // 2
- 0b0000000010001111, // 3
- 0b0000000011100110, // 4
- 0b0010000001101001, // 5
- 0b0000000011111101, // 6
- 0b0000000000000111, // 7
- 0b0000000011111111, // 8
- 0b0000000011101111, // 9
- 0b0001001000000000, // :
- 0b0000101000000000, // ;
- 0b0010010000000000, // <
- 0b0000000011001000, // =
- 0b0000100100000000, // >
- 0b0001000010000011, // ?
- 0b0000001010111011, // @
- 0b0000000011110111, // A
- 0b0001001010001111, // B
- 0b0000000000111001, // C
- 0b0001001000001111, // D
- 0b0000000011111001, // E
- 0b0000000001110001, // F
- 0b0000000010111101, // G
- 0b0000000011110110, // H
- 0b0001001000001001, // I
- 0b0000000000011110, // J
- 0b0010010001110000, // K
- 0b0000000000111000, // L
- 0b0000010100110110, // M
- 0b0010000100110110, // N
- 0b0000000000111111, // O
- 0b0000000011110011, // P
- 0b0010000000111111, // Q
- 0b0010000011110011, // R
- 0b0000000011101101, // S
- 0b0001001000000001, // T
- 0b0000000000111110, // U
- 0b0000110000110000, // V
- 0b0010100000110110, // W
- 0b0010110100000000, // X
- 0b0001010100000000, // Y
- 0b0000110000001001, // Z
- 0b0000000000111001, // [
- 0b0010000100000000, //
- 0b0000000000001111, // ]
- 0b0000110000000011, // ^
- 0b0000000000001000, // _
- 0b0000000100000000, // `
- 0b0001000001011000, // a
- 0b0010000001111000, // b
- 0b0000000011011000, // c
- 0b0000100010001110, // d
- 0b0000100001011000, // e
- 0b0000000001110001, // f
- 0b0000010010001110, // g
- 0b0001000001110000, // h
- 0b0001000000000000, // i
- 0b0000000000001110, // j
- 0b0011011000000000, // k
- 0b0000000000110000, // l
- 0b0001000011010100, // m
- 0b0001000001010000, // n
- 0b0000000011011100, // o
- 0b0000000101110000, // p
- 0b0000010010000110, // q
- 0b0000000001010000, // r
- 0b0010000010001000, // s
- 0b0000000001111000, // t
- 0b0000000000011100, // u
- 0b0010000000000100, // v
- 0b0010100000010100, // w
- 0b0010100011000000, // x
- 0b0010000000001100, // y
- 0b0000100001001000, // z
- 0b0000100101001001, // {
- 0b0001001000000000, // |
- 0b0010010010001001, // }
- 0b0000010100100000, // ~
- 0b0011111111111111,
- };
- uint16_t displaybuffer[8];
- uint8_t buffer[17]= {0}; // Initialisiert alle Elemente mit 0;
- // VZ-SEG ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //###############################################################################################################################
- void VZ_Seg_writeDigitRaw( uint8_t n, uint16_t bitmask) {
- displaybuffer[n] = bitmask;
- }
- void VZ_Seg_writeDigitAscii(i2c_dev_t *display, uint8_t n, uint8_t ascii, bool d) {
- uint16_t font = alphafonttable[ascii];
- displaybuffer[n] = font;
- if (d)
- displaybuffer[n] |= (1 << 14);
- }
- void VZ_Seg_setBrightness(i2c_dev_t *display, uint8_t b) {
- if (b > 15)
- b = 15; // limit to max brightness
- uint8_t buffer = HT16K33_CMD_BRIGHTNESS | b;
- i2c_dev_write(display, NULL, 0, &buffer, sizeof(uint8_t));
- }
- void VZ_Seg_blinkRate(i2c_dev_t *display, uint8_t b) {
- if (b > 3)
- b = 0; // turn off if not sure
- uint8_t buffer = HT16K33_BLINK_CMD | HT16K33_BLINK_DISPLAYON | (b << 1);
- // Verwende das i2c_dev_t-Objekt des Displays, um Daten zu schreiben
- i2c_dev_write(display, NULL, 0, &buffer, sizeof(uint8_t));
- }
- bool VZ_Seg_begin(i2c_dev_t *display) {
- ESP_LOGI(TAG, "beginn");
- VZ_Seg_clear(display);
- // turn on oscillator
- uint8_t buffer[1] = {0x21};
- i2c_dev_write(display, NULL, 0, &buffer, sizeof(uint8_t));
- VZ_Seg_setBrightness(display, 15);
- VZ_Seg_writeDisplay(display);
- return true; // oder false je nach Erfolg oder Misserfolg der Initialisierung
- }
- void VZ_Seg_writeDisplay(i2c_dev_t *display) {
- buffer[0] = 0x00; // start at address $00
- for (uint8_t i = 0; i < 8; i++) {
- buffer[1 + 2 * i] = displaybuffer[i] & 0xFF;
- buffer[2 + 2 * i] = displaybuffer[i] >> 8;
- }
- ESP_LOGI(TAG, "writeDisplay");
- ESP_LOGI(TAG, "Buffer values: %02x %02x %02x %02x %02x %02x %02x %02x",
- buffer[1], buffer[2], buffer[3], buffer[4],
- buffer[5], buffer[6], buffer[7], buffer[8]);
- i2c_dev_write(display, NULL, 0, &buffer, sizeof(uint8_t));
- }
- void VZ_Seg_clear(i2c_dev_t *display) {
- for (uint8_t i = 0; i < 8; i++) {
- displaybuffer[i] = 0;
- }
- }
- void VZ_Seg_setDisplay(i2c_dev_t *display, const char *text) {
- VZ_Seg_clear(display);
- for (uint8_t i = 0; i < strlen(text); i++) {
- VZ_Seg_writeDigitAscii(display, i, text[i], false);
- }
- VZ_Seg_writeDisplay(display);
- }
- VZ_seg.h
- -------A-------
- |\ | /|
- | \ J / |
- | H | K |
- F \ | / B
- | \|/ |
- |--G1--|--G2--|
- | /|\ |
- E / | \ C
- | L | N |
- | / M \ |
- |/ | \|
- -------D------- DP
- */
- // DEFINITIONEN /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- extern uint16_t displaybuffer[8];
- #define LED_ON 1 ///< GFX color of lit LED segments (single-color displays)
- #define LED_OFF 0 ///< GFX color of unlit LED segments (single-color displays)
- #define HT16K33_BLINK_CMD 0x80 ///< I2C register for BLINK setting
- #define HT16K33_BLINK_DISPLAYON 0x01 ///< I2C value for steady on
- #define HT16K33_BLINK_OFF 0 ///< I2C value for steady off
- #define HT16K33_BLINK_2HZ 1 ///< I2C value for 2 Hz blink
- #define HT16K33_BLINK_1HZ 2 ///< I2C value for 1 Hz blink
- #define HT16K33_BLINK_HALFHZ 3 ///< I2C value for 0.5 Hz blink
- #define HT16K33_CMD_BRIGHTNESS 0xE0 ///< I2C register for BRIGHTNESS setting
- #define ALPHANUM_SEG_A 0b0000000000000001 ///< Alphanumeric segment A
- #define ALPHANUM_SEG_B 0b0000000000000010 ///< Alphanumeric segment B
- #define ALPHANUM_SEG_C 0b0000000000000100 ///< Alphanumeric segment C
- #define ALPHANUM_SEG_D 0b0000000000001000 ///< Alphanumeric segment D
- #define ALPHANUM_SEG_E 0b0000000000010000 ///< Alphanumeric segment E
- #define ALPHANUM_SEG_F 0b0000000000100000 ///< Alphanumeric segment F
- #define ALPHANUM_SEG_G1 0b0000000001000000 ///< Alphanumeric segment G1
- #define ALPHANUM_SEG_G2 0b0000000010000000 ///< Alphanumeric segment G2
- #define ALPHANUM_SEG_H 0b0000000100000000 ///< Alphanumeric segment H
- #define ALPHANUM_SEG_J 0b0000001000000000 ///< Alphanumeric segment J
- #define ALPHANUM_SEG_K 0b0000010000000000 ///< Alphanumeric segment K
- #define ALPHANUM_SEG_L 0b0000100000000000 ///< Alphanumeric segment L
- #define ALPHANUM_SEG_M 0b0001000000000000 ///< Alphanumeric segment M
- #define ALPHANUM_SEG_N 0b0010000000000000 ///< Alphanumeric segment N
- #define ALPHANUM_SEG_DP 0b0100000000000000 ///< Alphanumeric segment DP
- //###############################################################################################################################
- #ifdef __cplusplus
- extern "C" {
- #endif
- // Funktionen für die C++-Implementierung in der .cpp-Datei
- extern bool VZ_Seg_begin(i2c_dev_t *display);
- extern void VZ_Seg_setBrightness(i2c_dev_t *display, uint8_t b);
- void VZ_Seg_blinkRate(i2c_dev_t *display, uint8_t b);
- void VZ_Seg_writeDisplay(i2c_dev_t *display);
- void VZ_Seg_clear(i2c_dev_t *display);
- void VZ_Seg_writeDigitRaw(uint8_t n, uint16_t bitmask);
- void VZ_Seg_writeDigitAscii(i2c_dev_t *display, uint8_t n, uint8_t ascii, bool d);
- extern void VZ_Seg_setDisplay(i2c_dev_t *display, const char *text);
- #ifdef __cplusplus
- }
- #endif
- //###############################################################################################################################
- #endif
- i2cdev.h #ifndef MAIN_I2CDEV_H_
- #define MAIN_I2CDEV_H_
- #include "driver/i2c.h"
- #define I2C_FREQ_HZ 400000
- #define I2CDEV_TIMEOUT 1000
- typedef struct {
- i2c_port_t port; // I2C port number
- uint8_t addr; // I2C address
- gpio_num_t sda_io_num; // GPIO number for I2C sda signal
- gpio_num_t scl_io_num; // GPIO number for I2C scl signal
- uint32_t clk_speed; // I2C clock frequency for master mode
- } i2c_dev_t;
- esp_err_t i2c_master_init(i2c_port_t port, int sda, int scl);
- esp_err_t i2c_dev_read(const i2c_dev_t *dev, const void *out_data, size_t out_size, void *in_data, size_t in_size);
- esp_err_t i2c_dev_write(const i2c_dev_t *dev, const void *out_reg, size_t out_reg_size, const void *out_data, size_t out_size);
- inline esp_err_t i2c_dev_read_reg(const i2c_dev_t *dev, uint8_t reg,
- void *in_data, size_t in_size)
- {
- return i2c_dev_read(dev, ®, 1, in_data, in_size);
- }
- inline esp_err_t i2c_dev_write_reg(const i2c_dev_t *dev, uint8_t reg,
- const void *out_data, size_t out_size)
- {
- return i2c_dev_write(dev, ®, 1, out_data, out_size);
- }
- #endif /* MAIN_I2CDEV_H_ */
- i2cdev.c #include <string.h>
- #include <time.h>
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "driver/i2c.h"
- #include "esp_log.h"
- #include "i2cdev.h"
- #define TAG "I2CDEV"
- esp_err_t i2c_master_init(i2c_port_t port, int sda, int scl)
- {
- i2c_config_t i2c_config = {
- .mode = I2C_MODE_MASTER,
- .sda_io_num = sda,
- .scl_io_num = scl,
- .sda_pullup_en = GPIO_PULLUP_ENABLE,
- .scl_pullup_en = GPIO_PULLUP_ENABLE,
- .master.clk_speed = 1000000
- };
- //i2c_param_config(I2C_NUM_0, &i2c_config);
- //i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);
- i2c_param_config(port, &i2c_config);
- return i2c_driver_install(port, I2C_MODE_MASTER, 0, 0, 0);
- }
- esp_err_t i2c_dev_read(const i2c_dev_t *dev, const void *out_data, size_t out_size, void *in_data, size_t in_size)
- {
- if (!dev || !in_data || !in_size) return ESP_ERR_INVALID_ARG;
- i2c_cmd_handle_t cmd = i2c_cmd_link_create();
- if (out_data && out_size)
- {
- i2c_master_start(cmd);
- i2c_master_write_byte(cmd, (dev->addr << 1) | I2C_MASTER_WRITE, true);
- i2c_master_write(cmd, (void *)out_data, out_size, true);
- }
- i2c_master_start(cmd);
- i2c_master_write_byte(cmd, (dev->addr << 1) | 1, true);
- i2c_master_read(cmd, in_data, in_size, I2C_MASTER_LAST_NACK);
- i2c_master_stop(cmd);
- esp_err_t res = i2c_master_cmd_begin(dev->port, cmd, I2CDEV_TIMEOUT / portTICK_PERIOD_MS);
- if (res != ESP_OK)
- ESP_LOGE(TAG, "Could not read from device [0x%02x at %d]: %d", dev->addr, dev->port, res);
- i2c_cmd_link_delete(cmd);
- return res;
- }
- esp_err_t i2c_dev_write(const i2c_dev_t *dev, const void *out_reg, size_t out_reg_size, const void *out_data, size_t out_size)
- {
- if (!dev || !out_data || !out_size) return ESP_ERR_INVALID_ARG;
- i2c_cmd_handle_t cmd = i2c_cmd_link_create();
- i2c_master_start(cmd);
- i2c_master_write_byte(cmd, (dev->addr << 1) | I2C_MASTER_WRITE, true);
- if (out_reg && out_reg_size)
- i2c_master_write(cmd, (void *)out_reg, out_reg_size, true);
- i2c_master_write(cmd, (void *)out_data, out_size, true);
- i2c_master_stop(cmd);
- esp_err_t res = i2c_master_cmd_begin(dev->port, cmd, I2CDEV_TIMEOUT / portTICK_PERIOD_MS);
- if (res != ESP_OK)
- ESP_LOGE(TAG, "Could not write to device [0x%02x at %d]: %d", dev->addr, dev->port, res);
- i2c_cmd_link_delete(cmd);
- return res;
- }
- OUTPUT : rst:0x1 (POWERON_RESET),boot:0x1e (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:0x3fff0030,len:7084
- ho 0 tail 12 room 4
- load:0x40078000,len:15584
- load:0x40080400,len:4
- 0x40080400: _init at ??:?
- load:0x40080404,len:3876
- entry 0x4008064c
- I (31) boot: ESP-IDF v5.1.1-dirty 2nd stage bootloader
- I (31) boot: compile time Nov 17 2023 11:57:48
- I (31) boot: Multicore bootloader
- I (36) boot: chip revision: v3.0
- I (40) boot.esp32: SPI Speed : 40MHz
- I (44) boot.esp32: SPI Mode : DIO
- I (49) boot.esp32: SPI Flash Size : 2MB
- I (53) boot: Enabling RNG early entropy source...
- I (59) boot: Partition Table:
- I (62) boot: ## Label Usage Type ST Offset Length
- I (70) boot: 0 nvs WiFi data 01 02 00009000 00006000
- I (77) boot: 1 phy_init RF data 01 01 0000f000 00001000
- I (85) boot: 2 factory factory app 00 00 00010000 00100000
- I (92) boot: End of partition table
- I (96) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=0c940h ( 51520) map
- I (123) esp_image: segment 1: paddr=0001c968 vaddr=3ffb0000 size=02230h ( 8752) load
- I (127) esp_image: segment 2: paddr=0001eba0 vaddr=40080000 size=01478h ( 5240) load
- I (131) esp_image: segment 3: paddr=00020020 vaddr=400d0020 size=1b22ch (111148) map
- I (178) esp_image: segment 4: paddr=0003b254 vaddr=40081478 size=0c91ch ( 51484) load
- I (199) esp_image: segment 5: paddr=00047b78 vaddr=50000000 size=00004h ( 4) load
- I (207) boot: Loaded app from partition at offset 0x10000
- I (207) boot: Disabling RNG early entropy source...
- I (219) cpu_start: Multicore app
- I (220) cpu_start: Pro cpu up.
- I (220) cpu_start: Starting app cpu, entry point is 0x40081294
- 0x40081294: call_start_cpu1 at C:/Users/CheckMakRack/esp/esp-idf/components/esp_system/port/cpu_start.c:154
- I (0) cpu_start: App cpu up.
- I (238) cpu_start: Pro cpu start user code
- I (238) cpu_start: cpu freq: 160000000 Hz
- I (238) cpu_start: Application information:
- I (243) cpu_start: Project name: BTTF-TCD
- I (248) cpu_start: App version: 1
- I (252) cpu_start: Compile time: Nov 18 2023 10:57:00
- I (258) cpu_start: ELF file SHA256: 6c274682c571f52c...
- I (264) cpu_start: ESP-IDF: v5.1.1-dirty
- I (270) cpu_start: Min chip rev: v0.0
- I (274) cpu_start: Max chip rev: v3.99
- I (279) cpu_start: Chip rev: v3.0
- I (284) heap_init: Initializing. RAM available for dynamic allocation:
- I (291) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
- I (297) heap_init: At 3FFB33F8 len 0002CC08 (179 KiB): DRAM
- I (303) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
- I (310) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
- I (316) heap_init: At 4008DD94 len 0001226C (72 KiB): IRAM
- I (324) spi_flash: detected chip: generic
- I (327) spi_flash: flash io: dio
- W (331) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
- W (344) rmt(legacy): legacy driver is deprecated, please migrate to `driver/rmt_tx.h` and/or `driver/rmt_rx.h`
- I (355) app_start: Starting scheduler on CPU0
- I (360) app_start: Starting scheduler on CPU1
- I (360) main_task: Started on CPU0
- I (370) main_task: Calling app_main()
- I (370) gpio: GPIO[4]| InputEn: 1| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
- I (380) gpio: GPIO[5]| InputEn: 1| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
- I (390) gpio: GPIO[12]| InputEn: 1| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
- I (400) gpio: GPIO[14]| InputEn: 1| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
- I (410) uart_rx_task: Start
- I (410) uart_tx_task: Start
- sending:7e ff 6 c 0 0 0 fe ef ef
- received:7e ff 6 3f 0 0 2 fe ba ef
- I (1560) MAIN: DF_begin=1
- I (1560) MAIN: DFPlayer Mini initialisiert.
- I (1560) MAIN: Setzen Lautstärke auf 15
- sending:7e ff 6 6 0 0 f fe e6 ef
- I (1560) MAIN: I2C-Master initialisiert
- I (1580) MAIN: Found device at address 0x57
- I (1580) MAIN: Found device at address 0x5F
- I (1580) MAIN: Found device at address 0x68
- I (1580) MAIN: Found device at address 0x70
- I (1590) MAIN: Found device at address 0x71
- I (1590) MAIN: Found device at address 0x72
- I (1600) MAIN: Found 6 devices
- I (1650) MAIN: RTC erfolgreich initialisiert
- I (1650) MAIN: VZ_DISP_1 initialisiert
- I (1650) MAIN: VZ_DISP_2 initialisiert
- I (1650) MAIN: VZ_DISP_3 initialisiert
- I (1650) MAIN: beginn
- I (1660) MAIN: writeDisplay
- I (1660) MAIN: Buffer values: 00 00 00 00 00 00 00 00
- I (1660) MAIN: beginn
- I (1670) MAIN: writeDisplay
- I (1670) MAIN: Buffer values: 00 00 00 00 00 00 00 00
- I (1680) MAIN: beginn
- I (1680) MAIN: writeDisplay
- I (1680) MAIN: Buffer values: 00 00 00 00 00 00 00 00
- I (1690) MAIN: Alle Displays erfolgreich initialisiert
- I (1690) MAIN: I2C_SCL_GPIO = 0
- I (1700) getClock: 2023-11-23 10:32:00, 19.75 deg Cel
- I (1700) MAIN: I2C_SDA_GPIO = 2
- I (1710) MAIN: CONFIG_TIMEZONE= 1
- I (1710) MAIN: writeDisplay
- I (1720) MAIN: Buffer values: f7 00 8f 12 39 00 0f 12
- I (1720) MAIN: writeDisplay
- I (1720) MAIN: Buffer values: 06 00 db 00 8f 00 e6 00
- I (1730) MAIN: writeDisplay
- I (1730) MAIN: Buffer values: 8f 12 38 00 3e 00 8f 12
- I (1740) main_task: Returned from app_main()
- I (1740) MAIN: IR-RX vor RINGBUFFER -DEBUGPRINT
- I (11690) getClock: 2023-11-23 10:32:10, 19.75 deg Cel