与nfc串行缓冲通信8051

时间:2015-11-23 06:41:51

标签: serial-port microcontroller keil 8051

我遇到串行通信微控制器8051的问题。我的硬件MCU带有att7035au和模块-1350M CJH NFC读卡器。我已经测试了pc和mcu接收和传输usb-ttl / rs232顺利。成功发送1个字符和长度数据,没有错误。但是在尝试使用NFC模块的mcu之间进行通信之后,在从NFC接收数据期间出现错误。我使用中断来接收数据。

示例: mcu send(十六进制数据):

02 55 00 03 03 E0 B7

NFC接收数据mcu并发送反馈:

02 55 00 02 FF AA

mcu从NFC接收数据(02 55 00 02 FF AA)但接收

02 55 00 02 FF 05

有什么问题?为什么MCU读取接收数据错误。

我的代码配置:

BWPR = 0xcf;
BWPR = 0xbc;
PLLCFG = 0x87;  
CLKCFG |= 0x04;
EA = 1;     
//Serial config 0   
SCON0 = 0x50 ;                  //SCON: serail mode 1, 8-bit UART
PCON|=0x80;                     //PCON.7 (SMOD)  Indicate  Baud rate double 
SMOD_1=1;                       //ADCON.7 
S0RELL=0xfd;                    //115200bps
S0RELH=0x03;
TI=0;
RI=0;
ES0 = 1 ;       

编辑添加代码中断:

void    UART_0(void)    interrupt   4
{
    if(SCON0&0x01){     //RI=1
        SCON0=SCON0&0xfc;       //RI=0
        card_id[RECE_NUMB]=SBUF0;
        if(RECE_NUMB==6){
            if(card_id[1]==0x02&&card_id[2]==0x55&&card_id[5]==0xff){
                f_ReceiveSucceed=1;
                SCON0&=0xef;                 //disable receive
            }
        }
        ++RECE_NUMB; 
    }
    SCON0=0x50;      
}

代码main(void):

while(1)
{ 
//...
//lines of code to send NFC
//...

if(f_ReceiveSucceed)
    {
        f_ReceiveSucceed=0;
        SerialCommunication();                      
    }           
}

如果收到,所以我用usb-ttl发送到serialcommunication()监控数据串行

void SerialCommunication(void){
    unsigned char count;
    ES0 = 0;
    for(count=0;count<=50;count++)
    { 
        SBUF0=card_id[count];
        while(TI==0);
        TI=0;
    }
    ES0 = 1;
    clear();
    SCON0=0x50;  //open receive

}

void clear(void)
{
    unsigned char r;
    for(r=0;r<50;r++){
        card_id[r]=0x00;
    }
    RECE_NUMB=0;
}

0 个答案:

没有答案