From e9dee893036098e3c1c376f9191ced716456a9be Mon Sep 17 00:00:00 2001 From: Mikhail Date: Wed, 11 Jun 2025 00:30:54 +0300 Subject: [PATCH] Release 0.1 --- Inc/DS_I2CScanner.h | 9 +++------ Src/DS_I2CScanner.c | 23 +++++++++++++++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Inc/DS_I2CScanner.h b/Inc/DS_I2CScanner.h index 5b5908a..ebd55b1 100644 --- a/Inc/DS_I2CScanner.h +++ b/Inc/DS_I2CScanner.h @@ -4,16 +4,13 @@ #include "main.h" #ifdef STM32G0 - #include "stm32g0xx_hal.h" +#include "stm32g0xx_hal.h" #endif #ifdef STM32F0 - #include "stm32f0xx_hal.h" +#include "stm32f0xx_hal.h" #endif - -void DS_I2CScan(I2C_HandleTypeDef* I2C); - - +void DS_I2CScan(I2C_HandleTypeDef *I2C, uint8_t *Result, uint8_t maxNumResults); #endif \ No newline at end of file diff --git a/Src/DS_I2CScanner.c b/Src/DS_I2CScanner.c index fb5d0d0..e80781a 100644 --- a/Src/DS_I2CScanner.c +++ b/Src/DS_I2CScanner.c @@ -1,6 +1,25 @@ #include "DS_I2CScanner.h" -void DS_I2CScan(I2C_HandleTypeDef *I2C) +void DS_I2CScan(I2C_HandleTypeDef *I2C, uint8_t *Result, uint8_t maxNumResults) { - + HAL_StatusTypeDef HAL_result = HAL_ERROR; + uint8_t NumOfResult = 0; + + for (uint8_t i = 0; i < maxNumResults - 1; i++) + { + Result[i] = 0; + } + + for (uint8_t addr = 0; addr < 0xFF; ++addr) + { + HAL_result = HAL_I2C_IsDeviceReady(I2C, addr, 3, 1000); + if (HAL_result == HAL_OK) + { + Result[NumOfResult] = addr; + if (NumOfResult < maxNumResults - 1) + { + NumOfResult++; + } + } + } } \ No newline at end of file