Quantcast
Channel: Infineon Forums
Viewing all articles
Browse latest Browse all 9892

Xmc 4200 uart

$
0
0
HI...
here is the basic UART project that transmits the message on the terminal. Would also like to highlight that this example is exactly the same as one provided inside of XMCLib package under XMC4500 series/UART/UART_TRANSMIT example. I´ve just changed the LED define while it´s connected to different pin.

Code:

#include <xmc_gpio.h>
#include <xmc_uart.h>

#define TICKS_PER_SECOND 1000
#define TICKS_WAIT 1000

const uint8_t message[] = "Hello world!!\n";

#define LED1    P2_1
#define UART_TX P1_5
#define UART_RX P1_4

XMC_GPIO_CONFIG_t uart_tx =
{
  .mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT2,
  .output_strength = XMC_GPIO_OUTPUT_STRENGTH_MEDIUM
};

XMC_GPIO_CONFIG_t uart_rx =
{
  .mode = XMC_GPIO_MODE_INPUT_TRISTATE
};

XMC_GPIO_CONFIG_t led =
{
  .mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL,
  .output_strength = XMC_GPIO_OUTPUT_STRENGTH_MEDIUM
};

XMC_UART_CH_CONFIG_t uart_config =
{
  .data_bits = 8U,
  .stop_bits = 1U,
  .baudrate = 115200U
};

void SysTick_Handler(void)
{
  static uint32_t ticks = 0;
  uint32_t index;

  ticks++;
  if (ticks == TICKS_WAIT)
  {
          XMC_GPIO_ToggleOutput(LED1);

          for (index = 0; index < sizeof(message) - 1; index++)
          {
            XMC_UART_CH_Transmit(XMC_UART0_CH0, message[index]);
          }
          ticks = 0;
  }
}

int main(void)
{
  XMC_UART_CH_Init(XMC_UART0_CH0, &uart_config);
  XMC_UART_CH_SetInputSource(XMC_UART0_CH0, XMC_UART_CH_INPUT_RXD, USIC0_C0_DX0_P1_4);
  XMC_UART_CH_Start(XMC_UART0_CH0);
  XMC_GPIO_Init(UART_TX,&uart_tx);
  XMC_GPIO_Init(UART_RX,&uart_rx);
  XMC_GPIO_Init(LED1,&led);

  /* Send a message via UART periodically */
  SysTick_Config(SystemCoreClock / TICKS_PER_SECOND);

  while(1)
  {
        /* Infinite loop */
  }
}

Best regards,
Deni

Viewing all articles
Browse latest Browse all 9892

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>