Sending a byte using UART

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

Sending a byte using UART

跳至解决方案
1,945 次查看
emimad
Contributor III

Hi all!

I'm trying to send some bytes through UART but I'm having some problems, probably because my old programming memories.

uint8_t array[]={0x80, 0x30, 0x31, 0x50};

for(i=0;i<4;i++){

Chip_UART_SendByte(LPC_USART, array[i]);

}

 

I'm sure it's an stupid question... but after check many examples I can't send my array byte by byte

 

Thanks in advance!

0 项奖励
1 解答
1,924 次查看
emimad
Contributor III

Thank you Diego!

I'm using a LPCXpresso LPC1347 board with MCUXpresso  IDE v11.4.0 and LPCOpen v2.05.

I tried your function:

破坏者
uint8_t array[]={0x80, 0x30, 0x31, 0x50};

Chip_UART_Send(LPC_USART, "UART_Send!\n\r", 12);
Chip_UART_Send(LPC_USART, (const uint8_t *) &array[i], 10);
Chip_UART_Send(LPC_USART, (const uint8_t *) array[i], 10);

Chip_UART_SendBlocking(LPC_USART, "\n\rUART_SendBlocking\n\r", 21);
Chip_UART_SendBlocking(LPC_USART, (const uint8_t *) &array[i], 10);
Chip_UART_SendBlocking(LPC_USART, (const uint8_t *) array[i], 10);

/* Transmit a byte array through the UART peripheral (non-blocking) */
int Chip_UART_Send(LPC_USART_T *pUART, const void *data, int numBytes)
{
int sent = 0;
uint8_t *p8 = (uint8_t *) data;

/* Send until the transmit FIFO is full or out of bytes */
while ((sent < numBytes) && ((Chip_UART_ReadLineStatus(pUART) & UART_LSR_THRE) != 0))
{
Chip_UART_SendByte(pUART, *p8);
p8++;
sent++;
}

return sent;
}

/* Transmit a byte array through the UART peripheral (blocking) */
int Chip_UART_SendBlocking(LPC_USART_T *pUART, const void *data, int numBytes)
{
int pass, sent = 0;
uint8_t *p8 = (uint8_t *) data;

while (numBytes > 0) {
pass = Chip_UART_Send(pUART, p8, numBytes);
numBytes -= pass;
sent += pass;
p8 += pass;
}

return sent;
}

And this is the output:

 Captura.jpg

Chip_UART_Send only sends the first character but not the first byte of my array

在原帖中查看解决方案

0 项奖励
2 回复数
1,935 次查看
diego_charles
NXP TechSupport
NXP TechSupport

Hi @emimad 

I hope you are doing well!

Could you let me know  which LPC board/MCU  and LPC drivers are you using?

Are you able to see any  part of your transmitted data array in the TX pin?  Or fails completely?

As a quick comment,  I would better call that function as below :

 

/* Transmit a byte array through the UART peripheral (non-blocking) */
int Chip_UART_Send(LPC_USART_T *pUART, const void *data, int numBytes)
{
  int sent = 0;
  uint8_t *p8 = (uint8_t *) data;

  /* Send until the transmit FIFO is full or out of bytes */
  while ((sent < numBytes) &&
    ((Chip_UART_ReadLineStatus(pUART) & UART_LSR_THRE) != 0)) 
  {
     Chip_UART_SendByte(pUART, *p8);
     p8++;
     sent++;
  }
  return sent;
}

 

This is done in the LPC4347 LPCopen drivers. 

And  make sure that the RX pins and the UART are properly clocked and configured as the UM mentions. 

All the best , 

Diego. 

0 项奖励
1,925 次查看
emimad
Contributor III

Thank you Diego!

I'm using a LPCXpresso LPC1347 board with MCUXpresso  IDE v11.4.0 and LPCOpen v2.05.

I tried your function:

破坏者
uint8_t array[]={0x80, 0x30, 0x31, 0x50};

Chip_UART_Send(LPC_USART, "UART_Send!\n\r", 12);
Chip_UART_Send(LPC_USART, (const uint8_t *) &array[i], 10);
Chip_UART_Send(LPC_USART, (const uint8_t *) array[i], 10);

Chip_UART_SendBlocking(LPC_USART, "\n\rUART_SendBlocking\n\r", 21);
Chip_UART_SendBlocking(LPC_USART, (const uint8_t *) &array[i], 10);
Chip_UART_SendBlocking(LPC_USART, (const uint8_t *) array[i], 10);

/* Transmit a byte array through the UART peripheral (non-blocking) */
int Chip_UART_Send(LPC_USART_T *pUART, const void *data, int numBytes)
{
int sent = 0;
uint8_t *p8 = (uint8_t *) data;

/* Send until the transmit FIFO is full or out of bytes */
while ((sent < numBytes) && ((Chip_UART_ReadLineStatus(pUART) & UART_LSR_THRE) != 0))
{
Chip_UART_SendByte(pUART, *p8);
p8++;
sent++;
}

return sent;
}

/* Transmit a byte array through the UART peripheral (blocking) */
int Chip_UART_SendBlocking(LPC_USART_T *pUART, const void *data, int numBytes)
{
int pass, sent = 0;
uint8_t *p8 = (uint8_t *) data;

while (numBytes > 0) {
pass = Chip_UART_Send(pUART, p8, numBytes);
numBytes -= pass;
sent += pass;
p8 += pass;
}

return sent;
}

And this is the output:

 Captura.jpg

Chip_UART_Send only sends the first character but not the first byte of my array

0 项奖励