From 306e273e8c6112e6864ccc6a7eab832278417716 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Thu, 29 May 2025 23:52:53 +0300 Subject: [PATCH 1/3] Day1 --- Inc/DS_I2CScanner.h | 0 Src/DS_I2CScanner.c | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 Inc/DS_I2CScanner.h create mode 100644 Src/DS_I2CScanner.c diff --git a/Inc/DS_I2CScanner.h b/Inc/DS_I2CScanner.h new file mode 100644 index 0000000..e69de29 diff --git a/Src/DS_I2CScanner.c b/Src/DS_I2CScanner.c new file mode 100644 index 0000000..e69de29 From 5a62faaa35f1d7cab26cffdbecac8ea6ccfefc1a Mon Sep 17 00:00:00 2001 From: Mikhail Date: Fri, 30 May 2025 15:33:33 +0300 Subject: [PATCH 2/3] Day2 --- Inc/DS_I2CScanner.h | 19 +++++++++++++++++++ Src/DS_I2CScanner.c | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/Inc/DS_I2CScanner.h b/Inc/DS_I2CScanner.h index e69de29..5b5908a 100644 --- a/Inc/DS_I2CScanner.h +++ b/Inc/DS_I2CScanner.h @@ -0,0 +1,19 @@ +#ifndef DS_I2CSCANNER_H +#define DS_I2CSCANNER_H + +#include "main.h" + +#ifdef STM32G0 + #include "stm32g0xx_hal.h" +#endif + +#ifdef STM32F0 + #include "stm32f0xx_hal.h" +#endif + + +void DS_I2CScan(I2C_HandleTypeDef* I2C); + + + +#endif \ No newline at end of file diff --git a/Src/DS_I2CScanner.c b/Src/DS_I2CScanner.c index e69de29..fb5d0d0 100644 --- a/Src/DS_I2CScanner.c +++ b/Src/DS_I2CScanner.c @@ -0,0 +1,6 @@ +#include "DS_I2CScanner.h" + +void DS_I2CScan(I2C_HandleTypeDef *I2C) +{ + +} \ No newline at end of file From e9dee893036098e3c1c376f9191ced716456a9be Mon Sep 17 00:00:00 2001 From: Mikhail Date: Wed, 11 Jun 2025 00:30:54 +0300 Subject: [PATCH 3/3] 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