-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 28bdb14
Showing
4 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# | ||
# This is a project Makefile. It is assumed the directory this Makefile resides in is a | ||
# project subdirectory. | ||
# | ||
|
||
PROJECT_NAME := i2c-scanner | ||
|
||
include $(IDF_PATH)/make/project.mk | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# I2C Scanner | ||
|
||
Starts a FreeRTOS task to scan I2C Bud | ||
|
||
ESP32 -- SDA (21) -- SCL (22) | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# | ||
# "main" pseudo-component makefile. | ||
# | ||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include <driver/i2c.h> | ||
#include <esp_log.h> | ||
#include <freertos/FreeRTOS.h> | ||
#include <freertos/task.h> | ||
#include <stdio.h> | ||
#include "sdkconfig.h" | ||
|
||
#define SDA_PIN 21 | ||
#define SCL_PIN 22 | ||
|
||
static char tag[] = "i2cscanner"; | ||
|
||
void task_i2cscanner(void *ignore) { | ||
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 app_main(void) | ||
{ | ||
xTaskCreate(&task_i2cscanner, "i2c scanner", 2048, NULL, 6, NULL); | ||
} | ||
|