Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

I2C scanner not working

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
CBailey

Bascom Member



Joined: 07 May 2015
Posts: 115

blank.gif
PostPosted: Fri Mar 10, 2023 11:09 pm    Post subject: I2C scanner not working Reply with quote

I'm having problems with an I2C motor driver, so I ran the below code to see what's on the I2C bus:

LCD "i2c ";
For Adress_loop = 2 To 252 Step 2 'Scan every even address
I2cstart 'setup i2c bus
I2cwbyte Adress_loop 'get result
If Err = 0 Then 'err=hw problem
LCD Adress_loop 'no error so device
LCD ","
End If 'exits
I2cstop 'stop bus
Next Adress_loop 'loop through each sensor
LCD "Done."

What happens is that the program freezes right after the first address is found. I never see the 'Done' message. Any idea why?

(BASCOM-AVR version : 2.0.8.5 )
Back to top
View user's profile
programmista123

Bascom Member



Joined: 31 Jan 2018
Posts: 191

poland.gif
PostPosted: Sat Mar 11, 2023 7:35 am    Post subject: Reply with quote

Do you know at which adres I2C scanner stuck?
What is adres for motor driver? How many I2C devices you have?

Regards,
Przemek
Back to top
View user's profile
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1571
Location: Basel, Switzerland

switzerland.gif
PostPosted: Sat Mar 11, 2023 7:35 am    Post subject: Reply with quote

Hi,

Please post the whole code, rather than just a snippet. The code that you posted looks OK, so I imagine the problem is with the CPU setup (I/O, stack etc).

Regards
Ian Dobson

_________________
Walking on water and writing software to specification is easy if they're frozen.
Back to top
View user's profile
CBailey

Bascom Member



Joined: 07 May 2015
Posts: 115

blank.gif
PostPosted: Sat Mar 11, 2023 7:48 am    Post subject: Reply with quote

I think the problem might be that I'm using the PCF8574 I2C LCD Adapter. I Scanned into an array, then sent it to the LCD and it worked. I'm guessing the LCD I2C driver is causing problems.

Also, it stops on any device found. As an example, if a device is found at 30, I change the loop to start at 32. When it finds the next device, it hangs.
Back to top
View user's profile
i.dobson

Bascom Expert



Joined: 05 Jan 2006
Posts: 1571
Location: Basel, Switzerland

switzerland.gif
PostPosted: Sun Mar 12, 2023 9:01 am    Post subject: Reply with quote

Hi,

If you had described the system setup better in your first post, it would be much easier to help you.

So the LCD is connected per i2c. If a i2c device is seen, the uC tries to send the address to the LCD, so you need to send an i2cstop before sending anything to the LCD, something like:

Code:

LCD "i2c ";
For Adress_loop = 2 To 252 Step 2 'Scan every even address
  I2cstart 'setup i2c bus
  I2cwbyte Adress_loop 'get result
  If Err = 0 Then 'err=hw problem
     i2cstop
     LCD Adress_loop 'no error so device
     LCD ","
  else
     i2cstop
  End If 'exits
Next Adress_loop 'loop through each sensor
LCD "Done."
 


Regards
Ian Dobson

_________________
Walking on water and writing software to specification is easy if they're frozen.
Back to top
View user's profile
CBailey

Bascom Member



Joined: 07 May 2015
Posts: 115

blank.gif
PostPosted: Sun Mar 12, 2023 3:26 pm    Post subject: Reply with quote

That makes sense. Thanks Ian!
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum