olehansen
Newbie level 1
Hi all
I am having an evaluation board from analog devices https://www.analog.com/en/analog-to...gital-converters/ad7747/products/product.html. It is an 24-bit capatcitance -to digital converter with temperature sensor.
This board uses a I2c communiucation bus, but I can't get it to work. Does anyone have a simple example code written in c/c++ for linux?
I have attached my program below. When I run it the write section fails. Could anyone help me, please?
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/i2c-dev.h>
int main(void)
{
int rv;
int file;
char *filename = "/dev/i2c-3";
if ((file = open(filename, O_RDWR)) < 0) {
printf("Failed to open the i2c bus");
}
if (ioctl(file, I2C_SLAVE, 0x48) < 0) {
printf("Failed to acquire bus access and/or talk to slave.\n");
}
int buf[3] = {0};
buf[0] = 0x48;
buf[1] = 0xA0;
buf[2] = 0x01;
// wirte section
if (rv = write(file, buf, 3) !=3)
{
printf("Error %d", rv);
}
}
Best regards
Ole Hansen
I am having an evaluation board from analog devices https://www.analog.com/en/analog-to...gital-converters/ad7747/products/product.html. It is an 24-bit capatcitance -to digital converter with temperature sensor.
This board uses a I2c communiucation bus, but I can't get it to work. Does anyone have a simple example code written in c/c++ for linux?
I have attached my program below. When I run it the write section fails. Could anyone help me, please?
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/i2c-dev.h>
int main(void)
{
int rv;
int file;
char *filename = "/dev/i2c-3";
if ((file = open(filename, O_RDWR)) < 0) {
printf("Failed to open the i2c bus");
}
if (ioctl(file, I2C_SLAVE, 0x48) < 0) {
printf("Failed to acquire bus access and/or talk to slave.\n");
}
int buf[3] = {0};
buf[0] = 0x48;
buf[1] = 0xA0;
buf[2] = 0x01;
// wirte section
if (rv = write(file, buf, 3) !=3)
{
printf("Error %d", rv);
}
}
Best regards
Ole Hansen