Sending a byte using UART

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Sending a byte using UART

ソリューションへジャンプ
1,937件の閲覧回数
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,916件の閲覧回数
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,927件の閲覧回数
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,917件の閲覧回数
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 件の賞賛