Compare commits
1
Commits
ai-context
...
Dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
18771f535d |
+12
-7
@@ -5,21 +5,26 @@ void DS_I2CScan(I2C_HandleTypeDef *I2C, uint8_t *Result, uint8_t maxNumResults)
|
|||||||
HAL_StatusTypeDef HAL_result = HAL_ERROR;
|
HAL_StatusTypeDef HAL_result = HAL_ERROR;
|
||||||
uint8_t NumOfResult = 0;
|
uint8_t NumOfResult = 0;
|
||||||
|
|
||||||
for (uint8_t i = 0; i < maxNumResults - 1; i++)
|
for (uint8_t i = 0; i < maxNumResults; i++)
|
||||||
{
|
{
|
||||||
Result[i] = 0;
|
Result[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t addr = 0; addr < 0xFF; ++addr)
|
// 2. Перебор стандартных 7-битных адресов (от 1 до 127)
|
||||||
|
for (uint8_t addr = 1; addr < 128; addr++)
|
||||||
{
|
{
|
||||||
HAL_result = HAL_I2C_IsDeviceReady(I2C, addr, 3, 1000);
|
if (NumOfResult >= maxNumResults)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Передаем адрес со сдвигом влево (addr << 1)
|
||||||
|
HAL_result = HAL_I2C_IsDeviceReady(I2C, (addr << 1), 3, 50);
|
||||||
|
|
||||||
if (HAL_result == HAL_OK)
|
if (HAL_result == HAL_OK)
|
||||||
{
|
{
|
||||||
Result[NumOfResult] = addr;
|
Result[NumOfResult] = (addr << 1);
|
||||||
if (NumOfResult < maxNumResults - 1)
|
|
||||||
{
|
|
||||||
NumOfResult++;
|
NumOfResult++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user