Created
February 23, 2026 19:54
-
-
Save ZeroSkill1/3a5c694788228979c457a5ebaa96c6a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include "driver/i2c_master.h" | |
| #include "freertos/FreeRTOS.h" | |
| void app_main(void) | |
| { | |
| i2c_master_bus_config_t mcfg = { | |
| .i2c_port = 0, | |
| .scl_io_num = GPIO_NUM_15, | |
| .sda_io_num = GPIO_NUM_16, | |
| .clk_source = I2C_CLK_SRC_DEFAULT | |
| }; | |
| i2c_master_bus_handle_t master_bus; | |
| ESP_ERROR_CHECK(i2c_new_master_bus(&mcfg, &master_bus)); | |
| while (1) { | |
| int r = rand() & 0x7f; | |
| if (r != 106) { | |
| i2c_device_config_t dev_cfg = { | |
| .dev_addr_length = I2C_ADDR_BIT_LEN_7, | |
| .device_address = r, | |
| .scl_speed_hz = 400000, | |
| .scl_wait_us = 0 | |
| }; | |
| printf("trying to read from %d\n", r); | |
| i2c_master_dev_handle_t slave_dev; | |
| ESP_ERROR_CHECK(i2c_master_bus_add_device(master_bus, &dev_cfg, &slave_dev)); | |
| uint8_t rb[10]; | |
| i2c_master_receive(slave_dev, rb, sizeof(rb), 100); | |
| i2c_master_bus_rm_device(slave_dev); | |
| } | |
| vTaskDelay(150 / portTICK_PERIOD_MS); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment