STM32 I2C Scanner

I2C scanner for STM32f10x series

I2C scanner is fairly simple, yet fast and effective way to find whatever device you put onto I2C bus. Some devices (boards) comes with clear designation on the PCB, some with misleading designation – address is shifted to the left, so for example OLED display typical address is 0x3C/0x3D (depends of address selector jumper), but shifted to the left by 1 bit is 0x78 or 0x7A respectively. They made it as if zero bit is inserted at LSB place so that you ‘just’ send it as-is. But that is bad practice. Rather make your own shifting routine and insert 1 or 0, whether you want to read or write at this address.

Example:

scannerThe code is even simpler:

Whole thing scan all 127 addresses in 45 mS.

Here is how looks whole packet with six addresses found. After each address found, there is 5.5 mS delay until timeout.:

scanner

Almost standard wire.c library

Since I am beginner, I just begin to make few more or less standard libraries for STM32f10x series. Right now there are three functions in wire.c; twiScan(), twiSend(), and twiReceive(). So far I did not found need for anything else, but that may change, so stay tuned. Since I have none of other MCU that has different set of registers with also different syntax for those. Here is complete thing with example of main.c code that does nothing except scan.:

Implemented in wire.c with wireSend() and wireReceive() functions:

That is all. Happy scanning! 😀