nfc i2c测试

来源:互联网 发布:千寻位置网络 编辑:程序博客网 时间:2024/06/05 03:15

记录一下NFC的学习。i2c的测试程序:

#include <stdio.h>

#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <time.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <linux/pn544.h>


#define _read_sample_test_size 0x4




int main(int argc, char *argv[]) {


int ret = 0;
int i = 0;
int fp = 0;
unsigned char send_reset[] = {0x05, 0xF9, 0x04, 0x00, 0xC3, 0xE5};//RSET Frame
unsigned char recv_response[40] = {0};

printf("pn544 iic driver test... ...\n");
if ((ret = (fp = open("/dev/pn544", O_RDWR))) < 0) {
printf("pn544 open error retcode = %d, errno = %d\n", ret, errno);
exit(0);
}


//hardware reset
ioctl(fp, PN544_SET_PWR, 1);
ioctl(fp, PN544_SET_PWR, 0);
ioctl(fp, PN544_SET_PWR, 1);


//write one RSET frame
if ((ret = (write(fp, send_reset, sizeof(send_reset))))<0){
printf("pn544 write error retcode = %d, errno = %d\n", ret, errno);
goto err_;
}
printf("PC->NFC: ");
for (i=0; i<sizeof(send_reset); i++){
printf("%.2X ", recv_response[i]);
}



//read pn544 responses(expected 0x03 e6 17 a7)
while (1){
if ((ret = (read(fp, &recv_response[0], _read_sample_test_size))) < 0) {
printf("\npn544 read error retcode = %d, errno = %d", ret, errno);
}
else{
printf("\nNFC->PC: ");
for (i=0;i<_read_sample_test_size;i++){
printf("%.2X ", recv_response[i]);}
break;
}
sleep(1);
}


err_:
close(fp);
return 0;

}

mk文件:

LOCAL_PATH:= $(call my-dir)


include $(CLEAR_VARS)
LOCAL_SRC_FILES:= pn544_app.c


LOCAL_MODULE:= pn544_app


include $(BUILD_EXECUTABLE)


还有头文件:

/*
 * PN544 power control via ioctl
 * PN544_SET_PWR(0): power off
 * PN544_SET_PWR(1): power on
 * PN544_SET_PWR(2): reset and power on with firmware download enabled
 */
#define PN544_SET_PWR _IOW(PN544_MAGIC, 0x01, unsigned int)


struct pn544_i2c_platform_data{
unsigned int irq_gpio;
unsigned int ven_gpio;
unsigned int firm_gpio;
};

0 0
原创粉丝点击