Xmc 4200 uart

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User15757
Level 1
Level 1
First like received 5 replies posted First question asked
Does anyone have a working UART project using the XMC 4200 ? The Dave sample projects do not seem to have this version as a sample project.

Thanks.
0 Likes
5 Replies
DRubeša
Employee
Employee
First solution authored First like received
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.

#include 
#include

#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
0 Likes
User15757
Level 1
Level 1
First like received 5 replies posted First question asked
Hello,

Thanks for your reply. So I have indeed been playing around with the XMC 4500's UART examples and changing the pin configurations. While I can get the code to build and compile, I don't see anything on my serial communication terminal. The way that I have configured the pins is by looking at the Distance2Go radar (device I am using) and XMC 4200 microcontroller data sheets. I have used Pins 0_0 as the UART RX and P0_1 as the UART TX. Any further ideas?

#include
#include

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

#define UART_TX P0_1
#define UART_RX P0_0

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_UART_CH_CONFIG_t uart_config =
{
.data_bits = 8U,
.stop_bits = 1U,
.baudrate = 115200U
};


int main(void)
{
XMC_UART_CH_Init(XMC_UART0_CH0, &uart_config);
XMC_UART_CH_SetInputSource(XMC_UART1_CH1, XMC_UART_CH_INPUT_RXD, USIC1_C1_DX0_P0_0);
XMC_UART_CH_Start(XMC_UART0_CH0);
XMC_GPIO_Init(UART_TX,&uart_tx);
XMC_GPIO_Init(UART_RX,&uart_rx);
uint32_t index;


/* Send a message via UART periodically */
for (index = 0; index < sizeof(message) - 1; index++)
{
XMC_UART_CH_Transmit(XMC_UART1_CH1, message[index]);
}

}
0 Likes
DRubeša
Employee
Employee
First solution authored First like received
Hi,

have a look at the XMC4100/4200 Data sheet and check the Port I/O Function Table where you can find connection of each pin with the peripherals...it looks like this for the selected pins:

3282.attach

And here you can see that pins P0.0 and P0.1 are connected to a USIC module 1 channel 1 (USIC1C1). So inside of the main function you should initialize and start different channel.

Fix that and see how it goes...other configuration looks fine.

Best regards,
Deni
0 Likes
User15944
Level 1
Level 1
First like received First reply posted First question asked
#include
#include

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

#define UART_TX P0_1
#define UART_RX P0_0


/*UART Cofiguration*/
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_UART_CH_CONFIG_t uart_config =
{
.data_bits = 8U,
.stop_bits = 1U,
.baudrate = 115200U
};


int main()
{
/*UART Initialization*/
XMC_UART_CH_Init(XMC_UART1_CH0, &uart_config);
XMC_UART_CH_SetInputSource(XMC_UART1_CH1, XMC_UART_CH_INPUT_RXD, USIC1_C1_DX0_P0_0);
XMC_UART_CH_Start(XMC_UART1_CH0);
XMC_GPIO_Init(UART_TX,&uart_tx);
XMC_GPIO_Init(UART_RX,&uart_rx);
uint32_t index;

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



}


Still not able to see serial data. I used XMC_UART1_CH1 because from the data sheet P0.0 and P0.1 is connected to U1C1 from the data sheet.

Did you manage to solve this problem? @User15944 

0 Likes