lpcware

LPC13xx  UART unexpected communication stop

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by grzegorzw on Tue Dec 30 01:53:51 MST 2014
Hello Guys.
It is my first Post.
I am writing to ask you about a help. ;), because i didn't find someting like that in Forum.

I try to program Uart in LPC 1342. I have to communicate LPC1342 microprocessor  with PC (QT application ) .
Communication from LPC1342 to PC host working ok, but only when i send some frame from microprocesor to PC, but when I want to start comunication from PC to LPC too, after 30 sekonds comunication stops, and nothing happen in microprocesor.
It looks like some kind of idle state, or i operate by pointer in some wrong space in memory. But it is only interrupt active. and i don't interpret data
Microprocesor doesn't send and recived anything though PC still send freame to LPC, what I can see on oscilloscope. In my program in microprocesor i don't do anyhing with recived data. I only read a single 8 bits from RBR register, in interrupt.
I don't know if something changes but i use FDDI Transceiver.
Below i would like to add Interrupt code, and UART inicialization, and Uart inicjalization in Qt.
Interesting thing is that in my previous project on LPC1769, the same communication work OK.
Please halp me what is wrong.


void UART_IRQHandler(void)
{
uint8_t IIRValue, LSRValue;
uint8_t Dummy = Dummy;
//uint8_t tempdata;


IIRValue = LPC_UART->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_UART->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 */
UARTStatus = LSRValue;
Dummy = LPC_UART->RBR;/* Dummy read on RX to clearinterrupt, 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 */
asd = LPC_UART->RBR;
}
}
else if (IIRValue == IIR_RDA)/* Receive Data Available */
{/* Receive Data Available */
asd = LPC_UART->RBR; //UARTBuffer[UARTCount++] = LPC_UART->RBR;
}
else if (IIRValue == IIR_CTI)/* Character timeout indicator */
{/* Character Time-out indicator */
UARTStatus |= 0x100;/* Bit 9 as the CTI error */
}
else if (IIRValue == IIR_THRE)/* THRE, transmit holding register empty */
{
/* THRE interrupt */
LSRValue = LPC_UART->LSR;/* Check status in the LSR to see if valid data in U0THR or not */
if (LSRValue & LSR_THRE){
UARTTxEmpty = 1;
}
else
UARTTxEmpty = 0;
}

//was_irq = true;
}



void UARTInit(uint32_t baudrate)
{
  uint32_t Fdiv;
  uint32_t regVal;

  UARTTxEmpty = 1;
  UARTCount = 0;
 
  NVIC_DisableIRQ(UART_IRQn);

  LPC_IOCON->PIO1_6 &= ~0x07;    /*  UART I/O config */
  LPC_IOCON->PIO1_6 |= 0x01;
                  /* UART RXD */
  LPC_IOCON->PIO1_7 &= ~0x07;
  LPC_IOCON->PIO1_7 |= 0x01;     /* UART TXD */

  /* Enable UART clock */
  LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12);
  LPC_SYSCON->UARTCLKDIV = 0x1;     /* divided by 1 */

// LPC_UART->LCR = 0x83;             /* 8 bits, no Parity, 1 Stop bit */
LPC_UART->LCR = 0x87;             /* 8 bits, no Parity, 2 Stop bit */
   //LPC_UART->LCR = 0x8F;             /* 8 bits, Parity, 2 Stop bit */


  regVal = LPC_SYSCON->UARTCLKDIV;
  Fdiv = (((SystemFrequency/LPC_SYSCON->SYSAHBCLKDIV)/regVal)/16)/baudrate ;/*baud rate */

  LPC_UART->DLM = Fdiv / 256;
  LPC_UART->DLL = Fdiv % 256;
  LPC_UART->LCR = 0x03;/* DLAB = 0 */
  LPC_UART->FCR = 0x07;/* Enable and reset TX and RX FIFO. */


  //LPC_UART->FCR |= (1 << 0);
//  LPC_UART->FCR  |= (1 << 6);
//  LPC_UART->FCR |= (1 << 7);


  /* Read to clear the line status. */
  regVal = LPC_UART->LSR;

  /* Ensure a clean start, no data in either TX or RX FIFO. */
// CodeRed - added parentheses around comparison in operand of &
  while (( LPC_UART->LSR & (LSR_THRE|LSR_TEMT)) != (LSR_THRE|LSR_TEMT) );
  while ( LPC_UART->LSR & LSR_RDR )
  {
regVal = LPC_UART->RBR;/* Dump data from RX FIFO */
  }

  /* Enable the UART Interrupt */
  NVIC_EnableIRQ(UART_IRQn);

#if TX_INTERRUPT
  LPC_UART->IER = IER_RBR | IER_THRE | IER_RLS;/* Enable UART interrupt */
#else
  LPC_UART->IER = IER_RBR | IER_RLS;/* Enable UART interrupt */
#endif
  return;
}



void MainWindow::OpenSerialPort(void)
{
    foreach (info, QSerialPortInfo::availablePorts())
    {
        ui->comboBox->addItem(info.portName());
    }
    serial = new QSerialPort(this);
    serial->setBaudRate(QSerialPort::Baud9600);
    serial->setDataBits(QSerialPort::Data8);
    serial->setParity(QSerialPort::NoParity);
    serial->setStopBits(QSerialPort::TwoStop);
    serial->setFlowControl(QSerialPort::NoFlowControl);
}





Outcomes