* Simple read byte data compilation problem
@ 2008-10-21 9:44 Fabien Marteau
[not found] ` <ce62e9d00810210244p3194a50fj3b6b19209465ac7e-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Fabien Marteau @ 2008-10-21 9:44 UTC (permalink / raw)
To: i2c-GZX6beZjE8VD60Wz+7aTrA
[-- Attachment #1.1: Type: text/plain, Size: 474 bytes --]
Hy,
I wrote a simple user program to test an i2c bus driver. I found in
Documentation/i2c/dev-interface their is macro function to read data
(i2c_smbus_read_byte_data). I used it but I have link error when I compile :
$ arm-linux-gcc -O i2cread.c -o i2cread
/tmp/ccfa90st.o: In function `read_byte':
i2cread.c:(.text+0x3c): undefined reference to `i2c_smbus_read_byte_data'
collect2: ld returned 1 exit status
Is someone know what is the problem ?
Thanks in advance
FabM
[-- Attachment #1.2: Type: text/html, Size: 525 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: i2cread.c --]
[-- Type: text/x-csrc; name=i2cread.c, Size: 2621 bytes --]
/* a simple program to read on i2c bus
* Fabien Marteau <fabien.marteau@armadeus.com>
*
* inspired from :
* ch7024: manage the Svideo controller CH7024
* author: thom25@users.sourceforge.net
*
*
** THE ARMADEUS PROJECT
**
** Copyright (C) year The source forge armadeus project team
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
*/
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
int fd;
/* Read a byte on the I2C bus
This is done by writing the register address
we want to access and then by reading this register
@param fd: file descriptor of the device
@param reg: register to access
@param buf: buffer used to store the result
@return : -1 in case of error otherwise 0
*/
__s32 read_byte( int fd,unsigned char addr, unsigned char reg)
{
int err;
__s32 res;
/* select address */
if(err=ioctl(fd,I2C_SLAVE,addr) < 0){
perror("can't select this address\n");
return err;
}
res = i2c_smbus_read_byte_data(fd,(__u8)reg);
if(res<0)
perror("read byte data error\n");
return res;
}
/* i2cread i2c-devfile addr*/
int main(int argc, char **argv){
unsigned char buf;
unsigned char addr;
unsigned char subaddr;
unsigned char value;
if(argc != 4){
printf("wrong args numbers\nsyntaxe (hexa) :\n");
printf("i2cread i2c-devfile addr subaddr\n");
return -1;
}
fd = open(argv[1],O_RDWR);
if(fd < 0){
printf("%d : can't open %s\n",fd,argv[1]);
return -1;
}
/* select address */
addr = (unsigned char )strtol(argv[2], (char **)NULL, 16);
/* select subaddress */
subaddr = (unsigned char )strtol(argv[3], (char **)NULL, 16);
buf = (unsigned char)read_byte(fd,addr, subaddr);
printf("Read component %02x at subaddress %02x->%02x\n",addr,subaddr,buf);
return value;
}
[-- Attachment #3: Type: text/plain, Size: 157 bytes --]
_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Simple read byte data compilation problem
[not found] ` <ce62e9d00810210244p3194a50fj3b6b19209465ac7e-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2008-10-21 12:59 ` Jean Delvare
[not found] ` <20081021145956.4a65467e-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Jean Delvare @ 2008-10-21 12:59 UTC (permalink / raw)
To: Fabien Marteau; +Cc: i2c-GZX6beZjE8VD60Wz+7aTrA
Salut Fabien,
On Tue, 21 Oct 2008 11:44:28 +0200, Fabien Marteau wrote:
> I wrote a simple user program to test an i2c bus driver. I found in
> Documentation/i2c/dev-interface their is macro function to read data
> (i2c_smbus_read_byte_data). I used it but I have link error when I compile :
> $ arm-linux-gcc -O i2cread.c -o i2cread
> /tmp/ccfa90st.o: In function `read_byte':
> i2cread.c:(.text+0x3c): undefined reference to `i2c_smbus_read_byte_data'
> collect2: ld returned 1 exit status
>
> Is someone know what is the problem ?
Documentation/i2c/dev-interface says:
So let's say you want to access an i2c adapter from a C program. The
first thing to do is "#include <linux/i2c-dev.h>". Please note that
there are two files named "i2c-dev.h" out there, one is distributed
with the Linux kernel and is meant to be included from kernel
driver code, the other one is distributed with i2c-tools and is
meant to be included from user-space programs. You obviously want
the second one here.
Apparently you missed this paragraph.
As a side note, if you only need to test your bus driver, the
i2cdetect, i2cget, i2cset and i2cdump utilities from the i2c-tools
package should be a good start, maybe you don't need to write your own
utility.
--
Jean Delvare
_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Simple read byte data compilation problem
[not found] ` <20081021145956.4a65467e-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
@ 2008-10-21 16:10 ` Fabien Marteau
0 siblings, 0 replies; 3+ messages in thread
From: Fabien Marteau @ 2008-10-21 16:10 UTC (permalink / raw)
To: Jean Delvare; +Cc: i2c-GZX6beZjE8VD60Wz+7aTrA
[-- Attachment #1.1: Type: text/plain, Size: 940 bytes --]
>
>
> Documentation/i2c/dev-interface says:
>
> So let's say you want to access an i2c adapter from a C program. The
> first thing to do is "#include <linux/i2c-dev.h>". Please note that
> there are two files named "i2c-dev.h" out there, one is distributed
> with the Linux kernel and is meant to be included from kernel
> driver code, the other one is distributed with i2c-tools and is
> meant to be included from user-space programs. You obviously want
> the second one here.
>
>
> Apparently you missed this paragraph.
>
Yes, in fact I looked for i2c-dev.h in the wrong tree (lm-sensor). I
realize that they are i2c-tools special tree for this. That work fine know.
Thank you
FabM
>
> As a side note, if you only need to test your bus driver, the
> i2cdetect, i2cget, i2cset and i2cdump utilities from the i2c-tools
> package should be a good start, maybe you don't need to write your own
> utility.
>
> --
> Jean Delvare
>
>
>
[-- Attachment #1.2: Type: text/html, Size: 1602 bytes --]
[-- Attachment #2: Type: text/plain, Size: 157 bytes --]
_______________________________________________
i2c mailing list
i2c-GZX6beZjE8VD60Wz+7aTrA@public.gmane.org
http://lists.lm-sensors.org/mailman/listinfo/i2c
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-10-21 16:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-21 9:44 Simple read byte data compilation problem Fabien Marteau
[not found] ` <ce62e9d00810210244p3194a50fj3b6b19209465ac7e-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-10-21 12:59 ` Jean Delvare
[not found] ` <20081021145956.4a65467e-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-10-21 16:10 ` Fabien Marteau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox