UART1 Tx issue with more than 16 bytes

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

UART1 Tx issue with more than 16 bytes

1,749 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by c0deland on Thu Mar 07 03:35:51 MST 2013
Hello everybody.
I saw that this topic has been discussed in other threads but still, I couldn't find a solution for this problem. I'm using a LPC176x and I'm trying to send data (more than 16 bytes at once) over uart1. Unfortunately I cant get it work. I'm using an uart driver provided by nxp. Here is the code I'm using for init and send.
Int32U UART1Init( void )
{
  PINSEL0_bit.P0_15 = 1;       // TxD1
  PINSEL1_bit.P0_16 = 1;       // RxD1

  U1LCR = 0x83;   // 8 bits, no Parity, 1 Stop bit 
  U1FDR_bit.DIVADDVAL = 3;
  U1FDR_bit.MULVAL = 4;
  U1DLM = 0;      // Baudrate = 9600 bps
  U1DLL = 93;
  U1LCR = 0x03;   // DLAB = 0 
  U1FCR_bit.RTLS = 2;   // Trigger level 2 - 8 characters
  U1FCR |= 0x07;   // Enable and reset TX and RX FIFO. 

  U1IER = IER_RBR | IER_RLS | IER_THRE; // Enable UART1 interrupt 

  NVIC_IntEnable(NVIC_UART1);

  return (TRUE);
}
and for send...

void UART1Send(Int8U *BufferPtr, Int32U len)
{
  Int32U i;
  UART1RxCount = 0;
  for (i=0; i<len; i++)
    UART1TxBuffer = BufferPtr;
  UART1TxEmpty = 0;  
  UART1TxLen = len;
  for (i=0; ((i<16) && (i<len)); i++)
    U1THR = UART1TxBuffer;
  UART1TxLeft = len-i;
  U1IER |= IER_THRE;  // Enable UART0 tx interrupt 
  while (UART1TxEmpty == 0);
  return;
}
I tried to send with UART1Send(...)  but it always sends only 16 bytes.
Any ideeas how can I solve this?
Thank you
0 项奖励
回复
5 回复数

1,676 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by c0deland on Thu Mar 07 09:03:45 MST 2013
Thank you.
Based on the Sendchar example, I have modified the UART1Send function. Now I have:
  int i=0;
  while(BufferPtr!=0)
   {
     U1THR = BufferPtr;
     U1IER |= IER_THRE;  
     while ((U1LSR & LSR_THRE) == 0);
     i++;
   }
Seems that it works.
Thank you
0 项奖励
回复

1,676 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by serge on Thu Mar 07 05:26:14 MST 2013
My guess is that he will send 11 nonsense bytes...
0 项奖励
回复

1,676 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by stalisman on Thu Mar 07 04:37:24 MST 2013
there is also the slight fact that he only ever sends 16 bytes before returning with len reduced by 16.

Theer is also the question of what happens if he sends only 5 bytes say,  what will Len be then?
0 项奖励
回复

1,676 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by serge on Thu Mar 07 04:19:38 MST 2013
And what is the uart interrupt routine doing? :confused:
Anyway I noticed that you are using UART1 and in your comments i see UART0

Quote:
U1IER |= IER_THRE;  // Enable UART[COLOR=red]0[/COLOR] tx interrupt


:rolleyes: Probably a typo?

And why are you always sending 16 bytes even if len is less?
And why not using DMA?
0 项奖励
回复

1,676 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Mar 07 04:17:01 MST 2013

Quote: c0deland
I tried to send with UART1Send(...)  but it always sends only 16 bytes.
Any ideeas how can I solve this?



You are filling 16 byte FIFO without reading back its status

Easiest way to avoid this is wait until it's empty

// ***********************
// Function to send character over UART
void UART0_Sendchar(char c)
{
    while( ([COLOR=Red]LPC_UART0->LSR & LSR_THRE) == 0 [/COLOR]);    // Block until tx empty
    LPC_UART0->THR = c;
}
0 项奖励
回复