View previous topic :: View next topic |
Author |
Message |
CBailey
Joined: 07 May 2015 Posts: 102
|
Posted: Fri Mar 10, 2023 11:09 pm Post subject: I2C scanner not working |
|
|
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 |
|
|
programmista123
Joined: 31 Jan 2018 Posts: 140
|
Posted: Sat Mar 11, 2023 7:35 am Post subject: |
|
|
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 |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Sat Mar 11, 2023 7:35 am Post subject: |
|
|
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 |
|
|
CBailey
Joined: 07 May 2015 Posts: 102
|
Posted: Sat Mar 11, 2023 7:48 am Post subject: |
|
|
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 |
|
|
i.dobson
Joined: 05 Jan 2006 Posts: 1570 Location: Basel, Switzerland
|
Posted: Sun Mar 12, 2023 9:01 am Post subject: |
|
|
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 |
|
|
CBailey
Joined: 07 May 2015 Posts: 102
|
Posted: Sun Mar 12, 2023 3:26 pm Post subject: |
|
|
That makes sense. Thanks Ian! |
|
Back to top |
|
|
|