Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:41 17 Sep 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Detecting I2C devices

Author Message
Bizzie
Senior Member

Joined: 06/07/2014
Location: Australia
Posts: 192
Posted: 02:51pm 12 Mar 2015
Copy link to clipboard 
Print this post

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?


Edited by Bizzie 2015-03-14
Rob White
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 06:44pm 12 Mar 2015
Copy link to clipboard 
Print this post

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: Australia
Posts: 192
Posted: 08:45pm 12 Mar 2015
Copy link to clipboard 
Print this post

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: Australia
Posts: 935
Posted: 10:43pm 12 Mar 2015
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 10400
Posted: 11:22pm 12 Mar 2015
Copy link to clipboard 
Print this post

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: Australia
Posts: 192
Posted: 12:54am 13 Mar 2015
Copy link to clipboard 
Print this post

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
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025