Main Site Documentation

I2C Scan


I’ve placed some code: for an I2C scanner.
I know that if the return code is unequal 0, then a device is on that address.
But several devices return several codes.

Question: who knows what the return codes mean?


result (in your code) is the number of bytes written.
“The number of bytes of data transferred in the transaction”


??? I’m not sure about that mrPositive.

The data written to the bus is always the same.
A PCF9531 returns number three (3).
A PCA8591 returns number two (2).
If is is the number of bytes transfered, why is it different on these chips?
There is no read, just an ACK. I will check your anser with my analyzer during the day.

Cu Wim.

The procedure with an analyzer took place and see what happened:
Not two bytes and three bytes return.


i wanted to take a look at the datasheets of the devices but can’t find the PCF9531


I think it is PCA9531


Indeed a typo.
It is a PCA9531 and a PCF 8591.
But this still leaves the question unanswered.

Cu Wim.


The number you get is the number of bytes that was ACKed by the device at that address.

When you get a return of 2 you will see that the third byte was NACKed…

The scan code doesn’t make sense as it is for a scanner. You create an I2C_Device with address X, then you send the address X to the device and a byte 0?

You end up writing 3 bytes to the device. You only need to send one byte to see if it gets ACKed. That is also the safest. As the code is it will write garbage to a I2C_Eprom as the device address.(if eeprom is at address 0x91 on the bus then it will write zero into addres 0x91 of eeprom)