From 18771f535de09e7796408422cd99bf1e818e8eda Mon Sep 17 00:00:00 2001 From: Mikhail Date: Tue, 30 Jun 2026 16:28:03 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE:=20=D0=9F=D0=B5=D1=80=D0=B5=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B1=D1=83=D1=84=D0=B5?= =?UTF-8?q?=D1=80=D0=B0=20=D0=9D=D0=B5=D0=BF=D0=BE=D0=BB=D0=BD=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=BE=D1=87=D0=B8=D1=81=D1=82=D0=BA=D0=B0=20=D0=BC=D0=B0?= =?UTF-8?q?=D1=81=D1=81=D0=B8=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/DS_I2CScanner.c | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/Src/DS_I2CScanner.c b/Src/DS_I2CScanner.c index e80781a..d8db573 100644 --- a/Src/DS_I2CScanner.c +++ b/Src/DS_I2CScanner.c @@ -2,24 +2,29 @@ void DS_I2CScan(I2C_HandleTypeDef *I2C, uint8_t *Result, uint8_t maxNumResults) { - HAL_StatusTypeDef HAL_result = HAL_ERROR; - uint8_t NumOfResult = 0; + 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) + for (uint8_t i = 0; i < maxNumResults; i++) { - Result[NumOfResult] = addr; - if (NumOfResult < maxNumResults - 1) - { - NumOfResult++; - } + Result[i] = 0; } - } -} \ No newline at end of file + + // 2. Перебор стандартных 7-битных адресов (от 1 до 127) + for (uint8_t addr = 1; addr < 128; addr++) + { + if (NumOfResult >= maxNumResults) + { + break; + } + + // Передаем адрес со сдвигом влево (addr << 1) + HAL_result = HAL_I2C_IsDeviceReady(I2C, (addr << 1), 3, 50); + + if (HAL_result == HAL_OK) + { + Result[NumOfResult] = (addr << 1); + NumOfResult++; + } + } +} -- 2.47.3