Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
LarryN3t committed Mar 20, 2019
0 parents commit 28bdb14
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Makefile
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

7 changes: 7 additions & 0 deletions README.md
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)


5 changes: 5 additions & 0 deletions main/component.mk
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.)

56 changes: 56 additions & 0 deletions main/main.c
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);
}

0 comments on commit 28bdb14

Please sign in to comment.