cancel
Showing results for 
Search instead for 
Did you mean: 

I have an ic MCP3428, I'm trying to connect it by I2C. Now problem is that I'm writing a code to figure out what the exact I2C address is? but it doesn't work

RSafa
Associate II

for(uint8_t i=0;i<255;i++)

{

HAL_Delay(10);

if(HAL_I2C_IsDeviceReady(&hi2c1,i,2,20)==HAL_OK)

{

uint8_t address=i;

break;

}

}

3 REPLIES 3
Ozone
Lead II

Are you sure the function HAL_I2C_IsDeviceReady() really probes the bus ?

The I2C address of the MCP3428 is well defined, see section 5.3 of the datasheet, especiall fig. 5-1.

Address bits A2 and A1 are defined by your hardware, A0 by the access type.

No need to guess or probe the bus.

RSafa
Associate II

you're right bro just before coding i wanted to test whether i could connect it or not as a test

but i couldn't

unbelievably it worked by Arduino

RSafa
Associate II

At the start of any I2C based IC

I test it by this code