![]() |
Forum Index : Microcontroller and PC projects : Detecting I2C devices
Author | Message | ||||
Bizzie Senior Member ![]() Joined: 06/07/2014 Location: AustraliaPosts: 192 |
As I will be starting some serious I2C work soon, I thought I would write a routine to detect I2C devices. I tried this code on the ARMmite V12B:- ' I2C_detect For Address = 0 To 127 Step 2 I2C Open 100,100 I2C Read Address,0,1,Data If mm.I2C = 0 Then Print "I2C device found at 0";Bin$(Address);"(";address;")",data EndIf I2C Close Next BUT it returns 128 devices! Does anyone have a method to see what I2C devices are present? Rob White |
||||
BobD![]() Guru ![]() Joined: 07/12/2011 Location: AustraliaPosts: 935 |
Rob Your address range is too large. 0 to 7 and 120 to 127 are not valid. Have a look at this thread and you will find a test in there. Bob |
||||
Bizzie Senior Member ![]() Joined: 06/07/2014 Location: AustraliaPosts: 192 |
Even changing my address range and using the code referred to gives a device on every address. This is not what the referenced code leads me to believe. Is there something different about the ARMmite? or the discovery board? Rob Rob White |
||||
BobD![]() Guru ![]() Joined: 07/12/2011 Location: AustraliaPosts: 935 |
A couple of possibilities come to mind here. This firmware is out for testing. It may have bugs. Is MM.I2C the variable name to use to test for I2C completion? If it is then it may be not being updated and be stuck at 0. Is the operation you are doing supposed to set the variable? |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10400 |
I thought I would write a routine to detect I2C devices
I haven't looked at whether MM.I2C is set correctly on the STM32 - probably not. Is testing for a I2C device at a specific address a real requirement? If so there is an internal function I use which I could expose through Basic Syntax would be "dim integer i=i2ctest(address)" returns 0 for no device at that address or non-zero for device found |
||||
Bizzie Senior Member ![]() Joined: 06/07/2014 Location: AustraliaPosts: 192 |
IMHO it would be good to know if a device is present especially when one has a new device and am not too sure of the address. Is it a problem in the longer term though with various version changing in different directions? Rob White |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |