16
Inc/DS_I2CScanner.h
Normal file
16
Inc/DS_I2CScanner.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#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, uint8_t *Result, uint8_t maxNumResults);
|
||||||
|
|
||||||
|
#endif
|
||||||
25
Src/DS_I2CScanner.c
Normal file
25
Src/DS_I2CScanner.c
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#include "DS_I2CScanner.h"
|
||||||
|
|
||||||
|
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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user