SC-F001 way better logging and parameters. not integrated yet but.
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
# The following four lines of boilerplate have to be in your project's CMakeLists
|
||||
# in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(i2c_scanner)
|
||||
@@ -0,0 +1,5 @@
|
||||
#V := 1
|
||||
PROJECT_NAME := i2c_scanner
|
||||
|
||||
|
||||
include $(IDF_PATH)/make/project.mk
|
||||
@@ -0,0 +1,31 @@
|
||||
# I2C bus scanner
|
||||
|
||||
## What it does
|
||||
|
||||
This example scans the i2c bus in a loop and prints out a table with the addresses of the found i2c devices.
|
||||
|
||||
## Wiring
|
||||
|
||||
Connect `SCL` and `SDA` pins to the following pins with appropriate pull-up
|
||||
resistors.
|
||||
|
||||
| Name | Description | Defaults |
|
||||
|------|-------------|----------|
|
||||
| `CONFIG_EXAMPLE_I2C_MASTER_SCL` | GPIO number for `SCL` | "5" for `esp8266`, "6" for `esp32c3`, "19" for `esp32`, `esp32s2`, and `esp32s3` |
|
||||
| `CONFIG_EXAMPLE_I2C_MASTER_SDA` | GPIO number for `SDA` | "4" for `esp8266`, "5" for `esp32c3`, "18" for `esp32`, `esp32s2`, and `esp32s3` |
|
||||
|
||||
## Example output
|
||||
|
||||
Three devices found on a bus: 0x38, 0x60 and 0x77
|
||||
|
||||
```
|
||||
0 1 2 3 4 5 6 7 8 9 a b c d e f
|
||||
00: -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
30: -- -- -- -- -- -- -- -- 38 -- -- -- -- -- -- --
|
||||
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
60: 60 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
70: -- -- -- -- -- -- -- 77
|
||||
```
|
||||
@@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "main.c"
|
||||
INCLUDE_DIRS ".")
|
||||
@@ -0,0 +1,7 @@
|
||||
menu "I2C scanner configuration"
|
||||
config EXAMPLE_I2C_CLOCK_HZ
|
||||
int "I2C clock frequency, Hz"
|
||||
default 100000
|
||||
|
||||
rsource "../../../Kconfig.i2c"
|
||||
endmenu
|
||||
@@ -0,0 +1 @@
|
||||
COMPONENT_ADD_INCLUDEDIRS = . include/
|
||||
@@ -0,0 +1,7 @@
|
||||
dependencies:
|
||||
esp-idf-lib/esp_idf_lib_helpers:
|
||||
version: '*'
|
||||
esp-idf-lib/i2cdev:
|
||||
version: '*'
|
||||
description: default
|
||||
version: 1.0.0
|
||||
@@ -0,0 +1,43 @@
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <i2cdev.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void task(void *ignore)
|
||||
{
|
||||
i2c_dev_t dev = { 0 };
|
||||
dev.cfg.sda_io_num = CONFIG_EXAMPLE_I2C_MASTER_SDA;
|
||||
dev.cfg.scl_io_num = CONFIG_EXAMPLE_I2C_MASTER_SCL;
|
||||
#if HELPER_TARGET_IS_ESP32
|
||||
dev.cfg.master.clk_speed = CONFIG_EXAMPLE_I2C_CLOCK_HZ; // 100kHz
|
||||
#endif
|
||||
while (1)
|
||||
{
|
||||
esp_err_t res;
|
||||
printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\n");
|
||||
printf("00: ");
|
||||
for (uint8_t addr = 3; addr < 0x78; addr++)
|
||||
{
|
||||
if (addr % 16 == 0)
|
||||
printf("\n%.2x:", addr);
|
||||
|
||||
dev.addr = addr;
|
||||
res = i2c_dev_probe(&dev, I2C_DEV_WRITE);
|
||||
|
||||
if (res == 0)
|
||||
printf(" %.2x", addr);
|
||||
else
|
||||
printf(" --");
|
||||
}
|
||||
printf("\n\n");
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
}
|
||||
|
||||
void app_main()
|
||||
{
|
||||
// Init i2cdev library
|
||||
ESP_ERROR_CHECK(i2cdev_init());
|
||||
// Start task
|
||||
xTaskCreate(task, "i2c_scanner", configMINIMAL_STACK_SIZE * 3, NULL, 5, NULL);
|
||||
}
|
||||
Reference in New Issue
Block a user