问题所在
0x2A, 0x42, 0x78, 0x250x25字节。星期五晚上调试结果
我们编写了另一个回显例程;它只读取它得到的内容并将其写回。
我们在发布模式下构建了它(根据这里另一个人的建议)
我写了一个例行公事,把同样的号码发出去25次,看看我能得到什么。
在那之后,我公司的价值和发送它25次,并循环。
结果附加在此消息的末尾。
我不能拿回第一个空字节。基于各种因素,我现在不担心这个问题。
接下来的五轮,我会把所有东西都拿回来
我会尝试包括所有相关的源代码,希望它不是一个墙的文本。如果需要更多的代码来理解这一点,请询问。
这是所讨论的UART的init代码。我可以包括
//*****************************************************************//
void initUART1(void) // UART1 for MCU1/2 communication
{
U1MODE=0; //// Mode Register, Manual DS61168D page 180
U1MODEbits.FRZ=0;
U1MODEbits.SIDL=0;
U1MODEbits.IREN=0;
U1MODEbits.RTSMD=0;
U1MODEbits.UEN=0b00; //// Just TX/RX, No CTS/RTS
U1MODEbits.WAKE=1;
U1MODEbits.LPBACK=0;
U1MODEbits.ABAUD=0;
U1MODEbits.RXINV=0;
U1MODEbits.BRGH=1;
U1MODEbits.PDSEL=0b00;
U1MODEbits.STSEL=0;
U1STA=0;
U1STAbits.ADM_EN=0;
U1STAbits.UTXINV=0;
U1STAbits.URXEN=1;
U1STAbits.UTXBRK=0;
U1STAbits.UTXEN=1;
U1STAbits.ADDEN=0;
U1STAbits.OERR=0;
//// Status register, Manual DS61168D page 183
//U1BRG=21; //// 21 for 921600 (80 MIPS)
U1BRG=172; //// 172 for 115200 (80 MIPS)
IFS0bits.U1RXIF=0;
IPC6bits.U1IP=5;
IPC6bits.U1IS=3;
IEC0bits.U1RXIE=1;
U1MODEbits.ON=1;
}
//*****************************************************************//这是处理此特定UART的中断服务例程。
//*********************************************************//
void __ISR(_UART1_VECTOR, ipl5) IntUart1Handler(void) //MCU communication port
{
if(INTGetFlag(INT_SOURCE_UART_RX(UART1))) //if it's a rx interrupt
{
U1RxBuf=UARTGetDataByte(UART1);
switch (CmdRecording)
{
case 0:
if(U1RxBuf=='*')
{
CmdRecording=1; //set the cmd recording flag
Command_U1[0]=U1RxBuf;
TimeOut=1; //time out=1 means the timeout for MCU1 command receiver is enabled
initT3(0x0100); //time out=0 means the timeout for MCU1 command receiver is enabled
}
else
{
putcharUART1('$');
putcharUART1('e');
putcharUART1('2');
putcharUART1('%');
}
break;
case 1:
CmdRecording=2; //set the cmd recording flag
Command_U1[1]=U1RxBuf;
break;
case 2:
CmdRecording=3; //set the cmd recording flag
Command_U1[2]=U1RxBuf;
break;
case 3:
CmdRecording=0; //reset the cmd recording flag
Command_U1[3]=U1RxBuf;
if(U1RxBuf=='%') //if this is the last command byte
{
if((Command_U1[1]=='O'))
{
CMD_Err=0; //clear error
CMD_OK=1; //send cmd OK;
}
else if((Command_U1[1]=='e'))
{
CMD_OK=0; //clear OK
CMD_Err=1; //send cmd Err;
}
else
Command_flag=1;
}
else
{
Command_flag=0;
}
disableT3(0); //the command receiving is done, disable the time out #0 (command receving time out)
TimeOut=0; //the command receiving is done, disable the time out
break;
default:
break;
}
INTClearFlag(INT_SOURCE_UART_RX(UART1));
}
if ( INTGetFlag(INT_SOURCE_UART_TX(UART1)) ) //if it's a tx interrupt
{
INTClearFlag(INT_SOURCE_UART_TX(UART1));
}
}
//***********************************************//这是我在通过"echo“系统运行字节时看到的数据;即读取一个字节的例程,它写入一个字节。
PIC-32的运行速度为80 MHz,UART的运行速度为115200 bps,所以我并不担心速度。
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03
04 04 04 04 04 04 04 04 04 04 04 04 04 04 04 04 04 04 04 04 04 04 04 04 04
05 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05发布于 2013-03-07 18:50:28
看起来UART可能有一个4字节的FIFO,在FIFO满之前不会产生中断。我对这个部分并不熟悉,但通常您可以编程UART在特定FIFO级别或在n字符超时之后生成一个中断,这样就可以读取非完全FIFO中的数据。此外,如果是这样的话,您的ISR应该循环,直到FIFO被清空,而不是简单地读取单个字符。
https://stackoverflow.com/questions/15277816
复制相似问题