Доброго времени суток!
Начал изучать OMAP3 под управлением Linux и столкнулся с проблемой:
Пытаюсь записать данные по I2C с помощью простенькой программы:
CODE
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <linux/i2c-dev.h>
#include <linux/i2c.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char** argv)
{
int file;
char filename[40];
int addr = 0x4a;
sprintf(filename,"/dev/i2c-1");
if ((file = open(filename, O_RDWR)) < 0) {
printf("Failed to open the bus.");
/* ERROR HANDLING; you can check errno to see what went wrong */
exit(1);
}
if (ioctl(file, I2C_SLAVE, addr) < 0) {
switch (errno)
{
case ENOTTY: printf("1 \n"); break;
case EINVAL: printf("2 \n"); break;
case EBUSY: printf("3 \n"); break;
default: printf("0 \n");
}
printf("Failed to acquire bus access and/or talk to slave.\n");
/* ERROR HANDLING; you can check errno to see what went wrong */
exit(1);
}
char buf[2] = {0};
int reg = 0xEE;
buf[0] = reg;
buf[1] = 0x22;
if (write(file, buf, 2) != 2) {
/* ERROR HANDLING: i2c transaction failed */
printf("Failed to write to the i2c bus.\n");;
printf("\n\n");
}
}
Затыкается на ioctl с ошибкой EBUSY.
Подскажите в чем может быть проблема???
Сообщение отредактировал IgorKossak - May 4 2011, 17:25
Причина редактирования: [codebox] !!!