UART Handshaking with RTS/CTS

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

UART Handshaking with RTS/CTS

1,002 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vineetrvce on Tue Jan 03 03:10:36 MST 2012
Hello,
I am trying to use RTS/CTS signals to implement UART handshaking. I have initialized the UART in the following way:

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 */

[COLOR=Red]  /* Enable Handshaking pins */
  LPC_IOCON->PIO0_7 &= ~0x07;    /* UART I/O config */
  LPC_IOCON->PIO0_7 |= 0x01;     /* UART CTS */
  LPC_IOCON->PIO1_5 &= ~0x07;    /* UART I/O config */
  LPC_IOCON->PIO1_5 |= 0x01;     /* UART RTS */
  LPC_UART->MCR = 0xC0;          /* Enable Auto RTS and Auto CTS. */[/COLOR]

  /* 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 */
  regVal = LPC_SYSCON->UARTCLKDIV;

  Fdiv = (((SystemCoreClock*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. */

  /* 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 CONFIG_UART_ENABLE_INTERRUPT==1
#if CONFIG_UART_ENABLE_TX_INTERRUPT==1
  LPC_UART->IER = IER_RBR | IER_THRE | IER_RLS;/* Enable UART interrupt */
#else
  LPC_UART->IER = IER_RBR | IER_RLS;/* Enable UART interrupt */
#endif
#endif
  return;
}

Basically I have added the code marked in Red from the demo code. My handshake does not seem to work.

The connection is shown in the attached file.

Also note that I am able to get the loopback working without handshake.

Could anyone share their views on this issue.

Regards,
Vineet.
0 Kudos
Reply
2 Replies

817 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vineetrvce on Fri Jan 06 06:55:41 MST 2012
HI again,
  I tried changing the code to

LPC_UART->FCR = 0x07; /* Enable and reset TX and RX FIFO. */

to

LPC_UART->FCR = 0xC7; /* Enable and reset TX and RX FIFO. */

but no luck.

Even with threshold at 1, atleast 1 byte should have been received.

I am just doing a loopback in the main code as follows:


//
//  ForeEver Loop
//
    for (;;)
    {
    if ( UARTCount != 0 )
    {
      LPC_UART->IER = IER_THRE | IER_RLS;/* Disable RBR */
      UARTSend( (uint8_t *)UARTBuffer, UARTCount );
      UARTCount = 0;
      LPC_UART->IER = IER_THRE | IER_RLS | IER_RBR;/* Re-enable RBR */
    // delay();
    }
}


Regards,
Vineet.
0 Kudos
Reply

817 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by serge on Thu Jan 05 03:24:28 MST 2012
Did i miss the part where you set the trigger level?

Quote:

Example: Suppose the UART operating in type ‘550 mode has the trigger level in U0FCR
set to 0x2, then, if Auto-RTS is enabled, the UART will deassert the RTS output as soon
as the receive FIFO contains 8 bytes (Table 127 on page 126). The RTS output will be
reasserted as soon as the receive FIFO hits the previous trigger level: 4 bytes.



Sorry if i am wrong here but i am an oldschool manual reading newbie.

Serge
0 Kudos
Reply