Sending a byte using UART

cancel
Showing results for 
Search instead for 
Did you mean: 

Sending a byte using UART

Jump to solution
96 Views
emimad
Contributor II

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 Kudos
1 Solution
75 Views
emimad
Contributor II

Thank you Diego!

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

I tried your function:

Spoiler
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

View solution in original post

0 Kudos
2 Replies
86 Views
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 Kudos
76 Views
emimad
Contributor II

Thank you Diego!

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

I tried your function:

Spoiler
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

View solution in original post

0 Kudos