This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem with LPC1768 UART

Hi
I have some problem with LPC1768 UART1 and FIFO.

1. I use RTX project and in initializing Uart send a string and with receive an response start my tasks. but in receive sequence I RECEIVE ONLY LAST CHARACTER ?????????

for example I send "Hello Jack" and when response "Thank you" ,the only character that recive is "u" !!!!!!
but when i tack a few delay between response ,all character receive correctly .

for example i response "T"_delay_"h"_delay_"a".....

2. in Condition

#define BUF_EMPTY(serBuf)      (serBuf.rdIdx == serBuf.wrIdx)
while (!BUF_EMPTY(out));                     // Block until space is available if none

when
serBuf.rdIdx=serBuf.wrIdx=0
it work well

but if serBuf.wrIdx and serBuf.rdIdx != 0 it not work and micro goto infinitive condition???

my code is:

/*----------------------------------------------------------------------------
  serial port 1 interrupt
 *---------------------------------------------------------------------------*/
extern "C" void UART1_IRQHandler(void) {

        volatile unsigned long iir;

  iir = LPC_UART1->IIR;                                                                                                                                      // Interrupt ID Register

  if ((iir & 0x4) || (iir & 0xC)) {                     // RDA or CTI pending
    while (LPC_UART1->LSR & 0x01) {                      // Rx FIFO is not empty
      BUF_WR(in, LPC_UART1->RBR);                       // Read Rx FIFO to buffer
    }
  }
  else if ((iir & 0x2)) {                               // TXMIS pending
                if (BUF_COUNT(out) != 0) {
                        LPC_UART1->THR = BUF_RD(out);                     // Write to the Tx FIFO
                        txRestart = 0;
                }
                else {
                        txRestart = 1;
                }
  }

  lineState = ((LPC_UART1->MSR << 8) | LPC_UART1->LSR) & 0xE01E;     // update linestate
}


/*----------------------------------------------------------------------------
  serial port 1 interrupt
 *---------------------------------------------------------------------------*/
void UART1_IRQHandler(void)
{
  volatile unsigned long iir;

  iir = LPC_UART1->IIR;

  if ((iir & 0x4) || (iir & 0xC)) {            // RDA or CTI pending
    while (LPC_UART1->LSR & 0x01) {                 // Rx FIFO is not empty
      SER_BUF_WR(ser_in, LPC_UART1->RBR);           // Read Rx FIFO to buffer
    }
  }
  if ((iir & 0x2)) {                           // TXMIS pending
    if (SER_BUF_COUNT(ser_out) != 0) {
      LPC_UART1->THR = SER_BUF_RD(ser_out);         // Write to the Tx FIFO
      ser_txRestart = 0;
    }
    else {
      ser_txRestart = 1;
    }
  }
  ser_lineState = ((LPC_UART1->MSR<<8)|LPC_UART1->LSR) & 0xE01E;    // update linestate
  return;
}

/*----------------------------------------------------------------------------
  write data to the serial port
 *---------------------------------------------------------------------------*/
int HWSerial::Write (const char *buffer, int *length) {
  int bytesToWrite, bytesWritten;

  // Write *length bytes
  bytesToWrite = *length;
  bytesWritten = bytesToWrite;

  //while (!BUF_EMPTY(out));                     // Block until space is available if none
  while (bytesToWrite) {
      BUF_WR(out, *buffer++);                  // Read Rx FIFO to buffer
      bytesToWrite--;
  }

  if (txRestart) {
    txRestart = 0;
    LPC_UART1->THR = BUF_RD(out);                       // Write to the Tx Register
  }

  return (bytesWritten);
}

Parents Reply Children
No data