cancel
Showing results for 
Search instead for 
Did you mean: 

what is problem when i write 0x01 at 0x0000 address of st25dv04k?

Mpraj.19
Associate II

#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;

}

1 ACCEPTED SOLUTION

Accepted Solutions
Ronald B.
Associate III

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:

https://www.st.com/content/st_com/en/products/embedded-software/st25-nfc-rfid-software/stsw-st25dv007.html#overview

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

View solution in original post

9 REPLIES 9
Ulysses HERNIOSUS
ST Employee

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

I have to write 15 bytes in eeprom of tag ic ​

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

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   ................

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

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

Ronald B.
Associate III

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:

https://www.st.com/content/st_com/en/products/embedded-software/st25-nfc-rfid-software/stsw-st25dv007.html#overview

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

Ronald B.
Associate III

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:

https://www.st.com/content/st_com/en/products/embedded-software/st25-nfc-rfid-software/stsw-st25dv007.html#overview

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

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