November 22, 2024, 10:23:32 PM

LPC 1766 uart3

Started by fshah, March 19, 2014, 04:54:40 PM

Previous topic - Next topic

fshah

Hi
   i need to receive data from uart3 (UEXT)and send to uart0. but the uart3 seems completely dead. i followed the configuration as it is stated in the manual and used the example from olimex board 1768 eg.


PCONP |= 0x02000000;       

PINSEL0 |= 0x00000050;       /* RxD0 and TxD0 */
PINSEL9 |= 0x0F000000;       /* RxD3 and TxD3 */
_____________________________________________________
#if (Fpclk / (Fcclk / 4)) == 1
  PCLKSEL0 = 0x00000000;  /* PCLK is 1/4 CCLK */
  PCLKSEL1 = 0x00000000;
#endif
#if (Fpclk / (Fcclk / 4)) == 2
  PCLKSEL0 = 0xA8AEAAAA;  /* PCLK is 1/2 CCLK */
  PCLKSEL1 = 0xAAAAAAAA;
#endif
#if (Fpclk / (Fcclk / 4)) == 4
  PCLKSEL0 = 0x55555555;  /* PCLK is the same as CCLK */
  PCLKSEL1 = 0x55555555;
#endif
____________________________________________________________
 
  U3LCR = 0x83;   /* 8 bits, no Parity, 1 Stop bit */
  Fdiv0 = ( Fpclk / 16 ) / baudrate ;  /*baud rate */
  Fdiv3 = Fdiv0;
 
  U3DLM = Fdiv3 / 256;
  U3DLL = Fdiv3 % 256;
 
 
  U0LCR = 0x83;   /* 8 bits, no Parity, 1 Stop bit */
 
  U0DLM = Fdiv0 / 256;
 
  U0DLL = Fdiv0 % 256;

  U3LCR = 0x03;   /* DLAB = 0 */
  U3FCR = 0x07;   /* Enable and reset TX and RX FIFO. */

  U0LCR = 0x03;   /* DLAB = 0 */
  U0FCR = 0x07;   /* Enable and reset TX and RX FIFO. */

  NVIC_IntEnable(NVIC_UART3);
  NVIC_IntPri(NVIC_UART3,HIGHEST_PRIORITY); /* HIGHEST_PRIORITY = 0x01 */
 
  NVIC_IntEnable(NVIC_UART0);
  NVIC_IntPri(NVIC_UART0,SECOND_PRIORITY);  /*SECOND_PRIORITY = 0x02 */

   
  U3IER = IER_RBR | IER_THRE | IER_RLS; /* Enable UART3 interrupt */
  U0IER = IER_RBR | IER_THRE | IER_RLS; /* Enable UART0 interrupt */

   for now i just want to simply send data from uart0 to uart3 and get back the data from uart3 to uart0 and see on terminal. for that i did as follow.

int main (void)
{
  BYTE data = 0;
  BYTE datab = 0;
 
  TargetResetInit();

  UARTInit(9600);               /* baud rate setting */
while(1)
  {
    if ( UART0Count != 0 )
    {
      U0IER = IER_THRE | IER_RLS;     /* Disable RBR */
     
      data = UART0Buffer[0];
      U3THR = data;
     
      // next data byte
      if (UART0Count > 0)
      {
        UART0Count--;
      }
      else
      {
        UART0Count = 0;
      }
     

      U0IER = IER_THRE | IER_RLS | IER_RBR; /* Re-enable RBR */
     
    }
   
     if ( UART3Count != 0 )
    {
      U3IER = IER_THRE | IER_RLS;     /* Disable RBR */
     
      datab = UART3Buffer[0];
      U0THR = datab;
      if (UART3Count > 0)
      {
        UART3Count--;
      }
      else
      {
        UART3Count = 0;
      }
       U3IER = IER_THRE | IER_RLS | IER_RBR; /* Re-enable RBR */
     
    }
  }
  return 0;
}

i am quite beginner about embedded programming so sorry if i have really stupid question.



fshah

so just for information.
The program is ok. My LPC1766 board has some problem. i checked the same program with another LPC1766 board and it is working fine.

thanks