这是我测试环境中的代码。它只是简单地将输入的数据回复(回送)到通过串行端口连接的终端应用程序。到目前为止一切顺利。
现在,我需要根据需求/协议使用该数据和流程。
但是,正如我期望的那样,我正在努力使用数据UART0Buffer
。
(变量UART0Buffer
填充在UART中断中)
我发送例如终端上的“ 7E0007AA010203040506CC” 并且出于某种原因,代码按四个步骤将其按顺序返回给终端应用程序
;1通过进程#1
37
2通过流程#2
00
3通过进程#1
30 30 30 37 41 41 30 31 30 32 30 33 30 34 30
4通过流程#2
A1
您还可以注意到,答复(回显)的数据与我从终端发送的数据不同。
此外,如果我完全删除“ Process#2”行, 我可以得到适当的回声;
37 45 30 30 30 37 41 41 30 31 30 32 30 33 30 34 30 35 30 36 43 43
我在这里真正想念的是什么?
int main()
{
SystemInit(); /* Clock and PLL configuration */
UARTInit(0,57600); /* baud rate setting */
while(1)
{
if ( UART0Count != 0 )
{
LPC_UART0->IER = IER_THRE | IER_RLS; /* Disable RBR */
UARTSend( 0,(uint8_t *)UART0Buffer,UART0Count ); // Process #1
UART0Count = 0;
// I need to call a function here in order to process data in UART0Buffer
// like checking/using STX,CHKSUM and DATA.
// A test,if I can manage to use the data in pieces
UARTSend( 0,(uint8_t *)UART0Buffer[0],1); // Process #2
LPC_UART0->IER = IER_THRE | IER_RLS | IER_RBR; /* Re-enable RBR */
}
}
}
void UARTSend( uint32_t portNum,uint8_t *BufferPtr,uint32_t Length )
{
if ( portNum == 0 )
{
while ( Length != 0 )
{
/* THRE status,contain valid data */
while ( !(UART0TxEmpty & 0x01) );
LPC_UART0->THR = *BufferPtr;
UART0TxEmpty = 0; /* not empty in the THR until it shifts out */
BufferPtr++;
Length--;
}
}
}
编辑: 由于dude已经解释了“进程#2”的错误用法,请忽略它。它以某种方式破坏了事情。但是,我的问题仍然存在。尽管我可以通过“ Process#1”得到回显,但是我无法读取和使用数据!任何指针将不胜感激。
编辑:
接收:
void UART0_IRQHandler (void)
{
uint8_t IIRValue,LSRValue;
uint8_t Dummy = Dummy;
IIRValue = LPC_UART0->IIR;
IIRValue >>= 1; /* skip pending bit in IIR */
IIRValue &= 0x07; /* check bit 1~3,interrupt identification */
if ( IIRValue == IIR_RLS ) /* Receive Line Status */
{
LSRValue = LPC_UART0->LSR;
/* Receive Line Status */
if ( LSRValue & (LSR_OE|LSR_PE|LSR_FE|LSR_RXFE|LSR_BI) )
{
/* There are errors or break interrupt */
/* Read LSR will clear the interrupt */
UART0Status = LSRValue;
Dummy = LPC_UART0->RBR; /* Dummy read on RX to clear
interrupt,then bail out */
return;
}
if ( LSRValue & LSR_RDR ) /* Receive Data Ready */
{
/* If no error on RLS,normal ready,save into the data buffer. */
/* Note: read RBR will clear the interrupt */
UART0Buffer[UART0Count] = LPC_UART0->RBR;
UART0Count++;
if ( UART0Count == BUFSIZE )
{
UART0Count = 0; /* buffer overflow */
}
}
}
else if ( IIRValue == IIR_RDA ) /* Receive Data Available */
{
/* Receive Data Available */
UART0Buffer[UART0Count] = LPC_UART0->RBR;
UART0Count++;
if ( UART0Count == BUFSIZE )
{
UART0Count = 0; /* buffer overflow */
}
}
else if ( IIRValue == IIR_CTI ) /* Character timeout indicator */
{
/* Character Time-out indicator */
UART0Status |= 0x100; /* Bit 9 as the CTI error */
}
else if ( IIRValue == IIR_THRE ) /* THRE,transmit holding register empty */
{
/* THRE interrupt */
LSRValue = LPC_UART0->LSR; /* Check status in the LSR to see if
valid data in U0THR or not */
if ( LSRValue & LSR_THRE )
{
UART0TxEmpty = 1;
}
else
{
UART0TxEmpty = 0;
}
}
}