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!
Solved! Go to Solution.
Thank you Diego!
I'm using a LPCXpresso LPC1347 board with MCUXpresso IDE v11.4.0 and LPCOpen v2.05.
I tried your function:
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:
Chip_UART_Send only sends the first character but not the first byte of my array
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.
Thank you Diego!
I'm using a LPCXpresso LPC1347 board with MCUXpresso IDE v11.4.0 and LPCOpen v2.05.
I tried your function:
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:
Chip_UART_Send only sends the first character but not the first byte of my array