资源简介
NFC的驱动代码,芯片型号为PN532,使用C语言编写,使用串口通信
代码片段和文件信息
void NFC_set(void)
{
//按住镇痛和通道再开机可进入设置状态,有3秒钟时间
//镇静和+打开NFC功能
//镇静和-关闭NFC功能
UFIX8 temp=0;
UFIX32 i=0;
UFIX16 num_temp=0num_temp2=0;
if(KEY_ZT==0 && KEY_CH==0 && KEY_ZJ==1 && KEY_ADD==1 && KEY_DEC==1) //0420
{
while(gNFC.iDelay_cnt < 1000) //5ms*600=3s
{
i++;
speak();
if(KEY_ZT==1 && KEY_CH==1 && KEY_ZJ==0 && KEY_ADD==0 && KEY_DEC==1)
{ //SET ON
temp = 1;
break;
}
}
}
num_temp = STMFLASH_ReadHalfWord(NFC_ID_POSITION);
num_temp2 = STMFLASH_ReadHalfWord(NFC_ID_POSITION+2);
if(num_temp==0xFFFF && num_temp2==0xFFFF)
{
temp = 1;
}
gNFC.bNFC_EN = 1; // test
gNFC.ID_new_set = 0;
gNFC.write_ok_cnt = 0;
gNFC.bShow_ID_SUM_all_en = 1;
gNFC.bSave_ID_en = 0;
gNFC.bID_scanf = 0;
gNFC.bSingle_batch = 1;
gNFC.bWrite_ok = 1;
gNFC.bScan_EN = 1;
gNFC.nfc_step = 1; //wakeupread
// temp = 1; //test
if(temp) //0420
{
gNFC.bNFC_EN = 0;
}
//NFC INIT
if(gNFC.bNFC_EN)
{
USART1_Init(); //USART1 Init STM32 <--> PN532
delay2();
delay2();
delay2();
NFC_Init();
}
num_temp = STMFLASH_ReadHalfWord(NFC_DEVICE_POSITION);
num_temp2 = STMFLASH_ReadHalfWord(NFC_DEVICE_POSITION+2);
if(num_temp==0xFFFF && num_temp2==0xFFFF)
{
gNFC.cDevice_num = 0;
}
else
{
gNFC.cDevice_num = (UFIX8)num_temp2;
}
}
void NFC_Main_Steps(void)
{
UFIX8 i = 0;
//process nfc step by command STM32->PN532
//NFC????????
if(gNFC.nfc_step != 0){
// wake_up 1
if(gNFC.nfc_step == 1){
NFC_communication_flag = 0x00;
NFC_find_time_counter = 1;
NFC_wakeup();
gNFC.nfc_step ++;
}
// wake_up 2
else if(gNFC.nfc_step == 2){
// NFC command waiting
if(NFC_find_time_counter > 60){ //5ms*60=300ms
NFC_find_time_counter = 0;
gNFC.nfc_step = 1;
}
//NFC command response
if(NFC_communication_flag&(NFC_bit_RXstate)){
NFC_communication_flag = NFC_communication_flag&(~NFC_bit_RXstate);
if(NFC_RXBuf[1] == 0x15){ //wakeup ok 0x000x000xFF0x020xFE0xD50x150x160x00
gNFC.cProcess_step = 1; //wakeup ok
gNFC.nfc_step++;
}
else{
gNFC.nfc_step = 1;
}
}
}
// findtag 1
else if(gNFC.nfc_step == 3){
NFC_communication_flag = NFC_communication_flag&(~NFC_bit_RXstate);
NFC_communication_flag = NFC_communication_flag&(~NFC_bit_OldTAGstate);
NFC_findtag();
gNFC.nfc_step ++;
}
// findtag 2
else if(gNFC.nfc_step == 4){
//NFC command response
if(NFC_communication_flag&(NFC_bit_RXstate)){
NFC_communication_flag = NFC_communication_flag&(~NFC_bit_RXstate);
if(NFC_RXBuf[1] == NFC_TXBuf[1] + 1){ //返回命令0x4B
//tag on-line
gNFC.nfc_step ++;
}
else{
// restart
gNFC.nfc_step = 3;
}
}
}
//readtag 1
else if(gNFC.nfc_step == 5){
NFC_communication_flag = NFC_communication_flag&(~NFC_bit_RXstate);
NFC_communicati
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6114 2018-10-16 17:39 NFC之pn532\app_NFC.c
文件 2406 2018-10-16 17:36 NFC之pn532\Driver_PN532_USART1.c
目录 0 2018-10-16 17:41 NFC之pn532
----------- --------- ---------- ----- ----
8520 3
- 上一篇:JMAIL邮件发送C++
- 下一篇:读取sgy卷头,道头及数据
评论
共有 条评论