lpcware

UART TXD

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by Lba0129 on Fri Mar 13 05:15:23 MST 2015
Hi I have copy some code from the net, and then rearrange it to my project.
I would like to have a TX debug pin. And I set up the uart and sends the data to the uart. But nothing happens on PIO_04, any ideas ?

Here is my code.
void uart0Init(uint32_t baudRate)
{
  uint32_t clk;
  const uint32_t UARTCLKDIV=1;
  GPIOSetPortBitDir(PORT0, TXD_PIN, SET_AS_OUTPUT);
  LPC_SWM->PINENABLE0 |= (1<<0);  //Disable ACIMP

  LPC_SWM->PINASSIGN0 = (0xffffff00 + TXD_PIN);
  /* Setup the clock and reset UART0 */
  LPC_SYSCON->UARTCLKDIV = UARTCLKDIV;
//  ctl_mask_isr(UART0_IRQn);//NVIC_DisableIRQ(UART0_IRQn);
  LPC_SYSCON->SYSAHBCLKCTRL |=  (1 << 14);
  LPC_SYSCON->PRESETCTRL    &= ~(1 << 3);
  LPC_SYSCON->PRESETCTRL    |=  (1 << 3);

  /* Configure UART0 */
  clk = SystemCoreClock/UARTCLKDIV;
  LPC_USART0->CFG = UART_DATA_LENGTH_8 | UART_PARITY_NONE | UART_STOP_BIT_1;
  LPC_USART0->BRG = clk / 16 / baudRate - 1;
  LPC_SYSCON->UARTFRGDIV = 0xFF;
  LPC_SYSCON->UARTFRGMULT = (((clk / 16) * (LPC_SYSCON->UARTFRGDIV + 1)) /
    (baudRate * (LPC_USART0->BRG + 1))) - (LPC_SYSCON->UARTFRGDIV + 1);

  /* Clear the status bits */
  LPC_USART0->STAT = UART_STATUS_CTSDEL | UART_STATUS_RXBRKDEL;

  /* enable rx interrupts (http://jaromir.xf.cz/phone/phone1.html) */
// LPC_USART0->INTENSET = (1 << 0);
   
  /* Enable UART0 interrupt */
//  ctl_unmask_isr(UART0_IRQn);//NVIC_EnableIRQ(UART0_IRQn);

  /* Enable UART0 */
  LPC_USART0->CFG |= UART_ENABLE;  
}

void uart0SendChar(char buffer)
{
  /* Wait until we're ready to send */
  while (!(LPC_USART0->STAT & UART_STATUS_TXRDY));
  LPC_USART0->TXDATA = buffer;
}

void uart0SendByte(uint8_t buffer)
{
    /* Wait until we're ready to send */
    while (!(LPC_USART0->STAT & UART_STATUS_TXRDY));
    LPC_USART0->TXDATA = buffer;
}

void uart0Send(char *buffer, uint32_t length)
{
  while (length != 0)
  {
    uart0SendChar(*buffer);
    buffer++;
    length--;
  }
}

Best regadrs
Lars

Outcomes