|
本帖最后由 cyj_0220 于 2013-5-24 15:00 编辑
初始化代码- LPC_PINCON->PINSEL0 |= (1<<20); //pin P0.10 used as TXD2
- LPC_PINCON->PINSEL0 |= (1<<22); //pin P0.11 used as RXD2
- LPC_SC->PCONP |=(1<<24); //uart2 power on
- LPC_UART2->LCR = 0X83; //enable set baud
- usfdiv= (FPCLK>>4)/usbaud; //set baud
- LPC_UART2->DLM = (usfdiv >> 8);
- LPC_UART2->DLL = (usfdiv & 255);
- LPC_UART2->LCR=0X03; //lock baud
- LPC_UART2->FCR =0X06;
- LPC_UART2->IER = 0X01; //enable receive interrupt
- NVIC_EnableIRQ(UART2_IRQn); //enable irq in nvic
复制代码 中断代码- void UART2_IRQHandler(void)
- {
- UINT8 ucIIRVal = 0;
- UINT8 ucLSRVal = 0;
- UINT8 ucdummy = 0;
- UINT8 ucrecv = 0;
- ucdummy = ucdummy; //avoid wrong
- ucIIRVal = LPC_UART2->IIR; //read IIR register
- ucIIRVal >>= 1; // skip pending bit in IIR
- ucIIRVal &= 0x07; //check bit 1~3 ,interrupt identification
- switch (ucIIRVal)
- {
- //
- //receive line status
- //
- case IIR_RLS :
- {
- ucLSRVal = LPC_UART2->LSR;
- if(ucLSRVal & (LSR_OE|LSR_PE|LSR_FE|LSR_RXFE|LSR_BI))
- {
- //
- //There are errors or break interrupt
- // Read LSR will clear the interrupt
- //
- ulUART2Status = ucLSRVal;
- ucdummy = LPC_UART2->RBR; //Dummy read on RX to clear interrupt, then bail out
- return;
- }
- if ( ucLSRVal & LSR_RDR ) //Receive Data Ready?
- {
- //
- //If no error on RLS, normal ready, save into the data buffer.
- // Note: read RBR will clear the interrupt
- //
- ucrecv = LPC_UART2->RBR;
- }
- }break;
- //
- //Receive Data Available
- //
- case IIR_RDA :
- {
- ucrecv = LPC_UART2->RBR;
- }break;
- //
- //Character timeout indicator
- //
- case IIR_CTI :
- {
- ulUART2Status |= 0x100; //Bit 9 as the CTI error
- }break;
- //
- //THRE interrupt,transmit holding register empty
- //
- case IIR_THRE :
- {
- ucLSRVal = LPC_UART2->LSR; //Check status in the LSR to see if valid data in U0THR or not
- if ( ucLSRVal & LSR_THRE )
- {
- g_UART2TxEmptyFlag = TRUE;
- }
- else
- {
- g_UART2TxEmptyFlag = FALSE;
- }
- }break;
- default : break;
- }
- EnQueue((Queue_Type *)&SIMRxQueue,ucrecv);
- UART_SendByte(2,ucrecv);
-
- }
复制代码 1.1234567890
abcd (a前面有一个回车符)
2.1234567890abcd (a前面无回车符)
第一种格式在收到回车符后,串口接收不到abcd
第二种格式可以正常接收
也就是说如果数据中有回车符,串口2收到回车符后面的数据也不会进中断 |
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|