Closing i2c after use

31 views
Skip to first unread message

Richard Chapman

unread,
Feb 8, 2024, 6:33:55 AM2/8/24
to bcm2835
Hi All

I have a simple program on a raspberry pi4 to read from an eeprom over i2c, after reding the data I have the following in my code:-


 bcm2835_i2c_end();
 bcm2835_close();


The c code complies and executes as intended, however if I then run

sudo i2cdetect -y 1

The command runs really slow and nothing is detected on the i2c port. It's like my c code isn't closing the port. If I reboot and then run sudo i2cdetect -y 1 everything is back to normal. Any ideas?

Thanks

Sean ONeill

unread,
Feb 11, 2024, 9:59:18 AM2/11/24
to bcm2835
Hi

The bcm2835 library works directly on the SPI/I2C devices. It is not using any Linux device drivers. When relevant Linux drivers are loaded or activated then it can create unexpected behavior from other software like 'i2cdetect'.

Here is a simple utility which detects I2C bus devices with the bcm2835  library.
https://github.com/gavinlyonsrepo/RPI_Tools/tree/main/src/i2cdetect

Mike McCauley

unread,
Feb 11, 2024, 9:13:22 PM2/11/24
to bcm2835, Sean ONeill
Thanks for mentioning this Sam,

I have added a link to that utility for the next version

Cheers.

On Monday, 12 February 2024 00:59:18 AEST Sean ONeill wrote:
> Hi
>
> The bcm2835 library works directly on the SPI/I2C devices. It is not using
> any Linux device drivers. When relevant Linux drivers are loaded or
> activated then it can create unexpected behavior from other software like
> 'i2cdetect'.
>
> Here is a simple utility which detects I2C bus devices with the bcm2835
> library.
> https://github.com/gavinlyonsrepo/RPI_Tools/tree/main/src/i2cdetect
>
> On Thursday, February 8, 2024 at 11:33:55 AM UTC nood...@gmail.com wrote:
> > Hi All
> >
> > I have a simple program on a raspberry pi4 to read from an eeprom over
> > i2c, after reding the data I have the following in my code:-
> >
> >
> >
> > * bcm2835_i2c_end(); bcm2835_close();*
> >
> > The c code complies and executes as intended, however if I then run
> >
> > *sudo i2cdetect -y 1*
> >
> > The command runs really slow and nothing is detected on the i2c port. It's
> > like my c code isn't closing the port. If I reboot and then run *sudo
> > i2cdetect -y 1 *everything is back to normal. Any ideas?
> >
> > Thanks


--
Mike McCauley VK4AMM mi...@airspayce.com
Airspayce Pty Ltd 9 Bulbul Place Currumbin Waters QLD 4223 Australia
http://www.airspayce.com 5R3MRFM2+X6
Phone +61 7 5598-7474



Richard Chapman

unread,
Feb 12, 2024, 2:39:24 AM2/12/24
to bcm2835
Hi All

Ah, that makes sense, thanks for the information.

Reply all
Reply to author
Forward
0 new messages