UART XMCLIB code unable to communicate

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

cross mob
Not applicable
I have an XMC4500 relax kit.
I have an application to read ADC values and send them over UART to PC.
I have used the UART APP generated code and it works fine.
UART RXD - P1.4
UART TXD - P1.5
I was attempting to write the UART code by myself using XMCLIB but have not succeeded so far.
I have pasted my code bellow :

#include
#include
#include

#define LED1 P1_0
#define LED2 P1_1

uint8_t indexTX = 0;
uint8_t indexRX = 0;
uint8_t message[] = "Hello World!!!\n";
uint8_t dataRecieved[80];
size_t messageTXLen;
XMC_USIC_CH_t *uart = XMC_UART0_CH0;

void USIC0_0_IRQHandler(void)
{
uint8_t readTemp;
if(XMC_UART_CH_GetStatusFlag(uart) == XMC_UART_CH_STATUS_FLAG_TRANSMITTER_FRAME_FINISHED)
{
if(indexTX < messageTXLen)
{
XMC_UART_CH_Transmit(uart, message[indexTX++]);
XMC_UART_CH_ClearStatusFlag(uart, XMC_UART_CH_STATUS_FLAG_TRANSMITTER_FRAME_FINISHED);
}
}
if(XMC_UART_CH_GetStatusFlag(uart) == XMC_UART_CH_STATUS_FLAG_RECEIVE_FRAME_FINISHED)
{
readTemp = (uint8_t)XMC_UART_CH_GetReceivedData(uart);
if(readTemp != ';')
{
if(indexRX < 80)
{
message[indexRX++] = readTemp;
XMC_UART_CH_ClearStatusFlag(uart, XMC_UART_CH_STATUS_FLAG_RECEIVE_FRAME_FINISHED);
}
}
}
}

int main(void)
{

XMC_GPIO_CONFIG_t LEDConfig;

const XMC_GPIO_CONFIG_t tx_config =
{
.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT2,
.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH,
.output_strength = XMC_GPIO_OUTPUT_STRENGTH_STRONG_SOFT_EDGE
};

const XMC_GPIO_CONFIG_t rx_config = {
.mode = XMC_GPIO_MODE_INPUT_TRISTATE,
.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH,
.output_strength = XMC_GPIO_OUTPUT_STRENGTH_STRONG_SOFT_EDGE
};

messageTXLen = strlen(message);

XMC_UART_CH_CONFIG_t uart_config = {
.baudrate = 9600U,
.oversampling = 16U,
.data_bits = 8U,
.frame_length = 8U,
.stop_bits = 1U,
.parity_mode = XMC_USIC_CH_PARITY_MODE_NONE
};

/*Configure RX*/
XMC_GPIO_Init(P1_4, &rx_config);

/*Configure TX*/
XMC_GPIO_Init(P1_5, &tx_config);

/*Initialize and configure UART0 on channel 0 */
XMC_UART_CH_Init(uart, &uart_config);

/*Set input source path*/
XMC_USIC_CH_SetInputSource(uart, XMC_USIC_CH_INPUT_DX0, 1U);

/*Configure transmit FIFO*/
//XMC_USIC_CH_TXFIFO_Configure(uart, 16U, XMC_USIC_CH_FIFO_SIZE_16WORDS, 1U);

/*Configure receive FIFO*/
//XMC_USIC_CH_RXFIFO_Configure(uart, 0U, XMC_USIC_CH_FIFO_SIZE_16WORDS, 15U);

XMC_UART_CH_EnableEvent(uart, XMC_UART_CH_EVENT_STANDARD_RECEIVE);
XMC_UART_CH_EnableEvent(uart, XMC_UART_CH_EVENT_TRANSMIT_SHIFT);

/*Start UART */
XMC_UART_CH_Start(uart);

__enable_irq();

XMC_UART_CH_Transmit(uart, message[indexTX++]);

//Relax Kit LED Operation
LEDConfig.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL;
LEDConfig.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH;
LEDConfig.output_strength = XMC_GPIO_OUTPUT_STRENGTH_MEDIUM;

XMC_GPIO_Init(LED1, &LEDConfig);
XMC_GPIO_Init(LED2, &LEDConfig);
XMC_GPIO_ToggleOutput(LED1);


/* Placeholder for user application code. The while loop below can be replaced with user application code. */
while(1U)
{

}
}



Kindly review the code and inform me where I went wrong.
I also want to know how to select transmit pin as the user manual list P1.5 or P1.7 or P5.1 or P1.5.HW0_OUT for USIC0_CH0.DOUT0 just as we have a dedicated function to set SetInputSource.

Thanking You,
IK.
0 Likes
1 Reply
Rick_Nardone
Employee
Employee
Hi Ishaan,

There are some examples included with the XMC Library. The following example may be useful for you: F:\XMC_Peripheral_Library_v2.1.4\XMCLib\examples\XMC4500_series\UART\UART_TRANSMIT

Best,

Rick
0 Likes