actualizacion
This commit is contained in:
1
PICO/I2C_SCANER/.gitignore
vendored
Normal file
1
PICO/I2C_SCANER/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
build/
|
||||
43
PICO/I2C_SCANER/CMakeLists.txt
Normal file
43
PICO/I2C_SCANER/CMakeLists.txt
Normal file
@@ -0,0 +1,43 @@
|
||||
# Generated Cmake Pico project file
|
||||
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
# initalize pico_sdk from installed location
|
||||
# (note this can come from environment, CMake cache etc)
|
||||
set(PICO_SDK_PATH "/home/mdchaparror/linuxTools/pico-sdk")
|
||||
|
||||
# Pull in Pico SDK (must be before project)
|
||||
include(pico_sdk_import.cmake)
|
||||
|
||||
project(I2C_SCANER C CXX ASM)
|
||||
|
||||
set(PICO_CXX_ENABLE_EXCEPTIONS 1)
|
||||
|
||||
set(PICO_CXX_ENABLE_RTTI 1)
|
||||
|
||||
# Initialise the Pico SDK
|
||||
pico_sdk_init()
|
||||
|
||||
# Add executable. Default name is the project name, version 0.1
|
||||
|
||||
add_executable(I2C_SCANER I2C_SCANER.c )
|
||||
|
||||
pico_set_program_name(I2C_SCANER "I2C_SCANER")
|
||||
pico_set_program_version(I2C_SCANER "0.1")
|
||||
|
||||
pico_enable_stdio_uart(I2C_SCANER 0)
|
||||
pico_enable_stdio_usb(I2C_SCANER 1)
|
||||
|
||||
# Add the standard library to the build
|
||||
target_link_libraries(I2C_SCANER pico_stdlib)
|
||||
|
||||
# Add any user requested libraries
|
||||
target_link_libraries(I2C_SCANER
|
||||
hardware_i2c
|
||||
)
|
||||
|
||||
pico_add_extra_outputs(I2C_SCANER)
|
||||
|
||||
70
PICO/I2C_SCANER/I2C_SCANER.c
Normal file
70
PICO/I2C_SCANER/I2C_SCANER.c
Normal file
@@ -0,0 +1,70 @@
|
||||
#include <stdio.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/i2c.h"
|
||||
|
||||
// I2C defines
|
||||
// This example will use I2C0 on GPIO8 (SDA) and GPIO9 (SCL) running at 400KHz.
|
||||
// Pins can be changed, see the GPIO function select table in the datasheet for information on GPIO assignments
|
||||
#define I2C_PORT i2c0
|
||||
#define I2C_SDA 0
|
||||
#define I2C_SCL 1
|
||||
|
||||
// I2C reserves some addresses for special purposes. We exclude these from the scan.
|
||||
// These are any addresses of the form 000 0xxx or 111 1xxx
|
||||
bool reserved_addr(uint8_t addr)
|
||||
{
|
||||
return (addr & 0x78) == 0 || (addr & 0x78) == 0x78;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
stdio_init_all();
|
||||
|
||||
// I2C Initialisation. Using it at 400Khz.
|
||||
i2c_init(I2C_PORT, 400 * 1000);
|
||||
|
||||
gpio_set_function(I2C_SDA, GPIO_FUNC_I2C);
|
||||
gpio_set_function(I2C_SCL, GPIO_FUNC_I2C);
|
||||
gpio_pull_up(I2C_SDA);
|
||||
gpio_pull_up(I2C_SCL);
|
||||
|
||||
int error, address;
|
||||
uint8_t data;
|
||||
int nDevices;
|
||||
|
||||
sleep_ms(5000);
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
||||
printf("Escaneando bus I2C\n");
|
||||
printf("===================\n");
|
||||
|
||||
nDevices = 0;
|
||||
|
||||
for (address = 1; address < 127; address++)
|
||||
{
|
||||
|
||||
if (reserved_addr(address))
|
||||
error = PICO_ERROR_GENERIC;
|
||||
else
|
||||
error = i2c_read_blocking(I2C_PORT, address, &data, 1, false);
|
||||
|
||||
if (error >= 0)
|
||||
{
|
||||
printf("Dispositivo I2C encontrado en 0x%02x \n", address);
|
||||
nDevices = nDevices + 1;
|
||||
}
|
||||
}
|
||||
printf("Encontrados %2x dispositivos I2C\n", nDevices);
|
||||
printf("===================\n");
|
||||
printf("\n");
|
||||
printf("\n");
|
||||
printf("\n");
|
||||
printf("\n");
|
||||
|
||||
sleep_ms(5000);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
62
PICO/I2C_SCANER/pico_sdk_import.cmake
Normal file
62
PICO/I2C_SCANER/pico_sdk_import.cmake
Normal file
@@ -0,0 +1,62 @@
|
||||
# This is a copy of <PICO_SDK_PATH>/external/pico_sdk_import.cmake
|
||||
|
||||
# This can be dropped into an external project to help locate this SDK
|
||||
# It should be include()ed prior to project()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH))
|
||||
set(PICO_SDK_PATH $ENV{PICO_SDK_PATH})
|
||||
message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')")
|
||||
endif ()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT))
|
||||
set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT})
|
||||
message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')")
|
||||
endif ()
|
||||
|
||||
if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH))
|
||||
set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH})
|
||||
message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')")
|
||||
endif ()
|
||||
|
||||
set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK")
|
||||
set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable")
|
||||
set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK")
|
||||
|
||||
if (NOT PICO_SDK_PATH)
|
||||
if (PICO_SDK_FETCH_FROM_GIT)
|
||||
include(FetchContent)
|
||||
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR})
|
||||
if (PICO_SDK_FETCH_FROM_GIT_PATH)
|
||||
get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}")
|
||||
endif ()
|
||||
FetchContent_Declare(
|
||||
pico_sdk
|
||||
GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk
|
||||
GIT_TAG master
|
||||
)
|
||||
if (NOT pico_sdk)
|
||||
message("Downloading Raspberry Pi Pico SDK")
|
||||
FetchContent_Populate(pico_sdk)
|
||||
set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR})
|
||||
endif ()
|
||||
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE})
|
||||
else ()
|
||||
message(FATAL_ERROR
|
||||
"SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git."
|
||||
)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
|
||||
if (NOT EXISTS ${PICO_SDK_PATH})
|
||||
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found")
|
||||
endif ()
|
||||
|
||||
set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake)
|
||||
if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE})
|
||||
message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK")
|
||||
endif ()
|
||||
|
||||
set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE)
|
||||
|
||||
include(${PICO_SDK_INIT_CMAKE_FILE})
|
||||
Reference in New Issue
Block a user