hi..
I am using LPC2387 board. By using sample code of UART1 i am trying to store data in buffer. I am sending Data using .exe Data sent by .exe is in byte. but I cant store this data in buffer. Can any one help me to figure out from this problem. below is the code.
void UART1Handler (void) __irq { BYTE IIRValue, LSRValue; BYTE Dummy = Dummy; IENABLE; /* handles nested interrupt */ IIRValue = U1IIR; IIRValue >>= 1; /* skip pending bit in IIR */ IIRValue &= 0x07; /* check bit 1~3, interrupt identification */ if ( IIRValue == IIR_RLS ) /* Receive Line Status */ { LSRValue = U1LSR; /* 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 */ UART1Status = LSRValue; // Dummy = U1RBR; /* Dummy read on RX to clear // interrupt, then bail out */ IDISABLE; VICVectAddr = 0; /* Acknowledge Interrupt */ 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 */ UART1Buffer[UART1Count] = U1RBR; UART1Count++; if ( UART1Count == BUFSIZE ) { UART1Count = 0; /* buffer overflow */ } } } else if ( IIRValue == IIR_RDA ) /* Receive Data Available */ { /* Receive Data Available */ UART1Buffer[UART1Count] = U1RBR; UART1Count++; // if (UART1Count > 90) // { // UART1Count++; // } if ( UART1Count == BUFSIZE ) { UART1Count = 0; /* buffer overflow */ } } else if ( IIRValue == IIR_CTI ) /* Character timeout indicator */ { /* Character Time-out indicator */ UART1Status |= 0x100; /* Bit 9 as the CTI error */ } else if ( IIRValue == IIR_THRE ) /* THRE, transmit holding register empty */ { /* THRE interrupt */ LSRValue = U1LSR; /* Check status in the LSR to see if valid data in U0THR or not */ if ( LSRValue & LSR_THRE ) { UART1TxEmpty = 1; } else { UART1TxEmpty = 0; } } IDISABLE; VICVectAddr = 0; /* Acknowledge Interrupt */ } if ( PortNum == 1 ) { #if EA_BOARD_LPC24XX PINSEL7 |= 0x0000000F; /* P3.16 TXD1, P3.17 RXD1 */ #else /* Default is Keil MCB2300 board */ PINSEL0 |= 0x40000000; /* Enable TxD1 P0.15 */ PINSEL1 |= 0x00000001; /* Enable RxD1 P0.16 */ #endif U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */ Fdiv = ( Fpclk / 16 ) / baudrate ; /*baud rate */ U1DLM = Fdiv / 256; U1DLL = Fdiv % 256; U1LCR = 0x03; /* DLAB = 0 */ U1FCR = 0x07; /* Enable and reset TX and RX FIFO. */ if ( install_irq( UART1_INT, (void *)UART1Handler, HIGHEST_PRIORITY ) == FALSE ) { return (FALSE); } U1IER = IER_RBR | IER_THRE | IER_RLS; /* Enable UART0 interrupt */ return (TRUE); } return( FALSE ); } void UARTSend( DWORD portNum, BYTE *BufferPtr, DWORD Length ) { if ( portNum == 0 ) { while ( Length != 0 ) { /* THRE status, contain valid data */ while ( !(UART0TxEmpty & 0x01) ); U0THR = *BufferPtr; UART0TxEmpty = 0; /* not empty in the THR until it shifts out */ BufferPtr++; Length--; } } else { while ( Length != 0 ) { /* THRE status, contain valid data */ while ( !(UART1TxEmpty & 0x01) ); U1THR = *BufferPtr; UART1TxEmpty = 0; /* not empty in the THR until it shifts out */ // BufferPtr++; Length--; } } return; } int main (void) { // UARTInit(0, 115200); /* baud rate setting */ UARTInit(1, 115200); /* baud rate setting */ while (1) { /* Loop forever */ // if ( UART0Count != 0 ) // { // U0IER = IER_THRE | IER_RLS; /* Disable RBR */ // UARTSend( 0, (BYTE *)UART0Buffer, UART0Count ); // UART0Count = 0; // U0IER = IER_THRE | IER_RLS | IER_RBR; /* Re-enable RBR */ // } if ( UART1Count != 0 ) { U1IER = IER_THRE | IER_RLS; /* Disable RBR */ UARTSend( 1, (BYTE *)UART1Buffer, UART1Count ); UART1Count = 0; U1IER = IER_THRE | IER_RLS | IER_RBR; /* Re-enable RBR */ } } return 0; }
Please help me to get out from this problem. I have spent two days behind this problem but still don't get its solution. It will be very helpful to me.
Thanks