kdw
Joined: 05 May 2006 Posts: 1461
|
Posted: 02.09.2011, 14:03 Post subject: I2C nutzen ... |
|
|
Hallo Forum.
Zunächst einmal müssen die erforderlichen Module im Dateisystem des eSOM/9263 abgelegt und geladen werden:
Code: | root@emblinux:~$ insmod <path_to_module>/i2c-core.ko
root@emblinux:~$ insmod <path_to_module>/i2c-dev.ko
root@emblinux:~$ insmod <path_to_module>/i2c-algo-bit.ko
root@emblinux:~$ insmod <path_to_module>/i2c-gpio.ko |
Dann kann man I2C nutzen. Der folgenden Code zeigt, wie man abfragen kann, ob die Treiber geladen wurden:
Code: | #include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>
int main(void) {
int fd;
//open device
if ((fd = open("/dev/i2c0",O_RDWR)) < 0) {
printf( "Fehler I2C open errno:%d %s",
errno, strerror(errno));
return 1;
}
//do somethings
//close device
close(fd);
return 0;
} |
Gruß
KDW |
|