int main() {
int fd;
unsigned char buffer[3];
unsigned char buffer1[2];
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;
}
buffer[0] = 0x00;
buffer[1] = 0x00;
buffer[2] = 0x65;
if (write(fd, buffer, 3) != 3)
{
printf("ERROR HANDLING: i2c transcations failed\n");
}
else
printf("i2c write success\n");
usleep(5000);
buffer1[0] = 0x00;
buffer1[1] = 0x00;
//buffer1[2] = 0x65;
if(read(fd, buffer1, 2) != 2)
{
printf("Failed to read from the i2c bus.\n\n");
}
else {
printf("Successful read\n");
printf("Value: %02x\n\n", buffer1[0]);
printf("Value: %02x\n\n", buffer1[1]);
}
close(fd);
return 0;
}
//////////////////////
q] what to write in above code to read value from register address of 2 byte?
q] is this right approach to read and write ? if not then what chage i need to do in above code for write in user area?
q] what ndef sequence byte i need to write in above code for send 'text data' ?
q] my main aim is to write data in nfc tag ic st25dv04k. that ic is work as slave. our master is second i.mx6 board. when tag connected to slave ic . when master comes near this tag i need to send written text data to master. so what to approach in above code?
i hope you not send any link. i want code development help. i don't want to use any driver.
Thanks for help and support.
Hi V16be1p11
one can look at nfc examples on
https://github.com/NXPNFCLinux/nxp-pn5xx
https://www.kernel.org/doc/Documentation/nfc/nfc-pn544.txt
Best regards
igor
Dear supporter,
there is many difference between tag ic.
i.e. 1] type 5 ----------tag
2] ndef format and iso standard ------ ISO 15693
so in this context how to do code is big trouble for me ?
i have write below code but i not get correct response from tag
#include <stdio.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <time.h>
#include <netinet/in.h>
#include <linux/i2c-dev.h>
/* NDEF Text Record */
unsigned char NDEF_DATA[] =
{
/*NDEF Text Record*/
0x03, 0x0E, //NDEF message, 14 byte message
0xD1, //NDEF Record header: MB = 1b, ME = 1b, CF = 0b, SR = 1b, IL = 0b, TNF = 001b
0x01, 0x0A, //type length, payload length
0x54, //Type = Text
0x02, //Language code size
0x65, 0x6E, // Language = English, 'e', 'n',
/*Payload data = " EEwiki"*/
' ', 'E', 'E', 'w', 'i', 'k', 'i',
};
#define ADDRESS 0x53
int main() {
int fd;
unsigned char buffer[3];
unsigned char buffer1[2];
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;
}
buffer[0] = 0x00;
buffer[1] = 0x00;
buffer[2] = NDEF_DATA[0];
if (write(fd, buffer, 3) != 3)
{
printf("ERROR HANDLING: i2c transcations failed\n");
}
else
printf("i2c write success\n");
usleep(5000);
buffer[0] = 0x00;
buffer[1] = 0x01;
//buffer[2] = 0x00;
buffer[2] = NDEF_DATA[1];
if (write(fd, buffer, 3) != 3)
{
printf("ERROR HANDLING: i2c transcations failed\n");
}
else
printf("i2c write success\n");
usleep(5000);
buffer[0] = 0x00;
buffer[1] = 0x02;
//buffer[2] = 0x00;
buffer[2] = NDEF_DATA[2];
if (write(fd, buffer, 3) != 3)
{
printf("ERROR HANDLING: i2c transcations failed\n");
}
else
printf("i2c write success\n");
usleep(5000);
buffer[0] = 0x00;
buffer[1] = 0x03;
//buffer[2] = 0x00;
buffer[2] = NDEF_DATA[3];
if (write(fd, buffer, 3) != 3)
{
printf("ERROR HANDLING: i2c transcations failed\n");
}
else
printf("i2c write success\n");
usleep(5000);
buffer[0] = 0x00;
buffer[1] = 0x04;
//buffer[2] = 0x00;
buffer[2] = NDEF_DATA[4];
if (write(fd, buffer, 3) != 3)
{
printf("ERROR HANDLING: i2c transcations failed\n");
}
else
printf("i2c write success\n");
usleep(5000);
buffer[0] = 0x00;
buffer[1] = 0x05;
//buffer[2] = 0x00;
buffer[2] = NDEF_DATA[5];
if (write(fd, buffer, 3) != 3)
{
printf("ERROR HANDLING: i2c transcations failed\n");
}
else
printf("i2c write success\n");
usleep(5000);
buffer[0] = 0x00;
buffer[1] = 0x06;
//buffer[2] = 0x00;
buffer[2] = NDEF_DATA[6];
if (write(fd, buffer, 3) != 3)
{
printf("ERROR HANDLING: i2c transcations failed\n");
}
else
printf("i2c write success\n");
usleep(5000);
buffer[0] = 0x00;
buffer[1] = 0x07;
//buffer[2] = 0x00;
buffer[2] = NDEF_DATA[7];
if (write(fd, buffer, 3) != 3)
{
printf("ERROR HANDLING: i2c transcations failed\n");
}
else
printf("i2c write success\n");
usleep(5000);
if (write(fd, buffer, 3) != 3)
{
printf("ERROR HANDLING: i2c transcations failed\n");
}
else
printf("i2c write success\n");
usleep(5000);
buffer[0] = 0x00;
buffer[1] = 0x08;
//buffer[2] = 0x00;
buffer[2] = NDEF_DATA[8];
if (write(fd, buffer, 3) != 3)
{
printf("ERROR HANDLING: i2c transcations failed\n");
}
else
printf("i2c write success\n");
usleep(5000);
buffer[0] = 0x00;
buffer[1] = 0x09;
//buffer[2] = 0x00;
buffer[2] = NDEF_DATA[9];
if (write(fd, buffer, 3) != 3)
{
printf("ERROR HANDLING: i2c transcations failed\n");
}
else
printf("i2c write success\n");
usleep(5000);
buffer[0] = 0x00;
buffer[1] = 0x0A;
//buffer[2] = 0x00;
buffer[2] = NDEF_DATA[10];
if (write(fd, buffer, 3) != 3)
{
printf("ERROR HANDLING: i2c transcations failed\n");
}
else
printf("i2c write success\n");
usleep(5000);
buffer[0] = 0x00;
buffer[1] = 0x0B;
//buffer[2] = 0x00;
buffer[2] = NDEF_DATA[11];
if (write(fd, buffer, 3) != 3)
{
printf("ERROR HANDLING: i2c transcations failed\n");
}
else
printf("i2c write success\n");
usleep(5000);
buffer[0] = 0x00;
buffer[1] = 0x0C;
//buffer[2] = 0x00;
buffer[2] = NDEF_DATA[12];
if (write(fd, buffer, 3) != 3)
{
printf("ERROR HANDLING: i2c transcations failed\n");
}
else
printf("i2c write success\n");
usleep(5000);
buffer[0] = 0x00;
buffer[1] = 0x0D;
//buffer[2] = 0x00;
buffer[2] = NDEF_DATA[13];
if (write(fd, buffer, 3) != 3)
{
printf("ERROR HANDLING: i2c transcations failed\n");
}
else
printf("i2c write success\n");
usleep(5000);
buffer[0] = 0x00;
buffer[1] = 0x0E;
//buffer[2] = 0x00;
buffer[2] = NDEF_DATA[14];
if (write(fd, buffer, 3) != 3)
{
printf("ERROR HANDLING: i2c transcations failed\n");
}
else
printf("i2c write success\n");
usleep(5000);
buffer[0] = 0x00;
buffer[1] = 0x0F;
//buffer[2] = 0x00;
buffer[2] = NDEF_DATA[15];
if (write(fd, buffer, 3) != 3)
{
printf("ERROR HANDLING: i2c transcations failed\n");
}
else
printf("i2c write success\n");
usleep(5000);
close(fd);
return 0;
}
so what to do to successfully program it?