2020-09-29 04:52 AM
#include <stdio.h>
#include <sys/ioctl.h> // ioctl
#include <fcntl.h> // open
#include <unistd.h> // read/write usleep
#include <time.h>
#include <netinet/in.h> // htons
#include <linux/i2c-dev.h>
#include "smbus.h"
#define ADDRESS 0x53 // AT24C32's address on I2C bus
int main() {
int fd;
if ((fd = open("/dev/i2c-2", O_RDWR)) < 0) { printf("Couldn't open device! %d\n", fd); return 1; }
if (ioctl(fd, I2C_SLAVE, ADDRESS) < 0) { printf("Couldn't find device on address!\n"); return 1; }
write(fd,0x0000,0x01);
usleep(500);
close(fd);
return 0;
}
Solved! Go to Solution.
2020-09-30 04:44 AM
Hello Mpraj.19,
Please have a look to the STSW-ST25DV007 software package providing a Linux user space driver for the ST25DV-I2C, available here:
This software package comes with a User Manual for easy ramp-up.
It must provide what you need to access ST25DV-I2C on a Linux platform.
Regards
2020-09-29 07:04 AM
Hi,
would be good if you could share what you want to achieve as opposed what you observe....
Above snippet looks a bit weird as the write() will probably try to read its 1 byte data from address NULL resulting in a fault.
Regards, Ulysses
2020-09-29 08:42 AM
I have to write 15 bytes in eeprom of tag ic
2020-09-30 12:57 AM
Hi,
that is only first part answered - what you wan to do. Second is: What you observe. Does the program create log output? Please also feed back the return code of the write(call). What are your observations? And look again into the signature of the function - I think it is not used correctly.
Regards, Ulysses
2020-09-30 01:38 AM
root@var-som-mx6:/home/user/Mangal# cc i2c.c
root@var-som-mx6:/home/user/Mangal# ./a.out
root@var-som-mx6:/home/user/Mangal# i2cdump -y -r 0-0xF 2 0x53 c
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
2020-09-30 01:43 AM
as above you can see that i want to write 0x01 at 0x0000 address of St25dv04k but when i execute it not show that value at that address
2020-09-30 02:08 AM
Hi,
as written before, I am unsure about your API usage:
write(2) — Linux manual page
ssize_t write(int fd, const void *buf, size_t count);
following https://www.kernel.org/doc/Documentation/i2c/dev-interface:
I think you will need to issue something like:
buf[0] = 0x00; // address byte
buf[1] = 0x00; // address bye
buf[2] = 0x01; // data byte
if (write(fd, buf, 3) != 3) {
printf ("ERROR HANDLING: i2c transaction failed\n");
}
If your system is not standard Linux / it still doesn't work then please look into the actual signals on SDA/SCL.
Regards, Ulysses
2020-09-30 04:42 AM
Hello Mpraj.19,
Please have a look to the STSW-ST25DV007 software package providing a Linux user space driver for the ST25DV-I2C, available here:
This software package comes with a User Manual for easy ramp-up.
It must provide what you need to access ST25DV-I2C on a Linux platform.
Regards
2020-09-30 04:44 AM
Hello Mpraj.19,
Please have a look to the STSW-ST25DV007 software package providing a Linux user space driver for the ST25DV-I2C, available here:
This software package comes with a User Manual for easy ramp-up.
It must provide what you need to access ST25DV-I2C on a Linux platform.
Regards
2020-10-01 12:22 AM
if we want to read that written data from same address i.e. 0000 how to read it ?
can you send me read sample code for that