LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-14-2020, 10:46 AM   #1
DeanAnderson
LQ Newbie
 
Registered: Nov 2019
Posts: 5

Rep: Reputation: Disabled
how C developer can get to know to which i2c bus number your device is connected


Hi
How C developer can get to know to which i2c bus number your device is connected? In linux shell it is easy.
Firstly You must know the i2c address of your device. Let's assume I know. Then I execute:
Code:
i2cdetect -l
it returns numbers.
Code:
i2cdetect -r 0
i2cdetect -r 1
i2cdetect -r 2
i2cdetect -r 3
i2cdetect -r 4
and I can found the bus 0,1,2,3 or 4.
The problem is that I need to know the bus in kernel source files before I run linux image. Because the function for registering i2c client forces me to set number - i2c_get_adapter:

Code:
// Setup device
	i2c_dev = i2c_get_adapter(n); //n bus number, means i2c-n
	i2c_client = i2c_new_device(i2c_dev, board_info);
//in board_info you set device name (it might be whatever) and i2c address of device
//then You can read write through functions, for example:
i2c_smbus_write_byte_data(i2c_client, 0x40, 0);
i2c_smbus_read_byte(i2c_client);
Any idea? Should I try to search something on board schematics?

Last edited by DeanAnderson; 01-14-2020 at 10:49 AM.
 
Old 01-15-2020, 05:11 AM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 10,853

Rep: Reputation: 1236Reputation: 1236Reputation: 1236Reputation: 1236Reputation: 1236Reputation: 1236Reputation: 1236Reputation: 1236Reputation: 1236
Have you tried
Code:
cd /sys
find -iname '*i2c*'
Plenty of stuff there, updated on the fly. You're the dev. Knock yourself out.
 
1 members found this post helpful.
Old 01-16-2020, 08:51 PM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 8,299
Blog Entries: 13

Rep: Reputation: 3695Reputation: 3695Reputation: 3695Reputation: 3695Reputation: 3695Reputation: 3695Reputation: 3695Reputation: 3695Reputation: 3695Reputation: 3695Reputation: 3695
I've always used i2cdump on the buses and it shows all devices it detects, an example output is shown in this page, https://www.waveshare.com/wiki/Raspb...al_Series:_I2C.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ipxe smbus i2c driver i2c-i801.c toma642 Linux - Hardware 0 01-08-2019 08:45 PM
i2c-dev.h missing i2c read/write functions dbrazeau Programming 1 12-17-2015 11:40 PM
How to forward IOCTL's from i2c-dev.c to adapter driver (i2c-rt3352.c) elonica.pl Linux - Kernel 2 08-23-2011 03:03 AM
[SOLVED] No /dev/i2c-0 entry after insmod i2c-dev sajnanazeer Linux - Newbie 1 08-10-2011 08:39 AM
Help! Problems with i2c-dev. No more /dev/i2c-* em1l Fedora 0 10-28-2005 06:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration