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

cross mob
Odri
Level 2
Level 2
First solution authored Welcome! 5 replies posted
Hi

Im doing some code with XMC1300 boot kit.

In this code im using the usic module as uart but i cant receive any data....

If someone can give me the soluction I will appreciate to much

externally I put together pins TxD and RxD so the sended data shuold be the received one.

#include "xmc_gpio.h"
#include "xmc_uart.h"
#include "xmc_scu.h"

XMC_GPIO_CONFIG_t led1_config;
XMC_GPIO_CONFIG_t rx_pin_config;
XMC_GPIO_CONFIG_t tx_pin_config;
XMC_UART_CH_CONFIG_t uart_config;
XMC_SCU_CLOCK_CONFIG_t clock_config;

int main(void)
{
/* Configure Clock */
clock_config.pclk_src = XMC_SCU_CLOCK_PCLKSRC_MCLK; /*PCLK = MCLK*/
clock_config.fdiv = 0; /**< Fractional divider */
clock_config.idiv = 0; /**MCLK = 32MHz */

/* Configure LED1 */
led1_config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL;
XMC_GPIO_Init(XMC_GPIO_PORT0,6, &led1_config);

/* UART configuration */
uart_config.data_bits = 8U;
uart_config.stop_bits = 1U;
uart_config.baudrate = 9600;
uart_config.oversampling = 16U;
uart_config.frame_length = 8U;
uart_config.parity_mode = XMC_USIC_CH_PARITY_MODE_NONE;

/* Configure RX pin */
rx_pin_config.mode = XMC_GPIO_MODE_INPUT_PULL_UP;
XMC_GPIO_Init(XMC_GPIO_PORT2,1, &rx_pin_config);

XMC_UART_CH_SetInputSource(XMC_UART0_CH0,XMC_UART_CH_INPUT_RXD,USIC0_C0_DX0_P2_1);


/* Configure UART channel */

XMC_UART_CH_Init(XMC_UART0_CH0, &uart_config);
/* Start UART channel */

XMC_UART_CH_Start(XMC_UART0_CH0);

/* Configure TX pin */
tx_pin_config.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH;
tx_pin_config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT6;
XMC_GPIO_Init(XMC_GPIO_PORT2,0, &tx_pin_config);

while(1)
{
uint8_t a='U';
XMC_UART_CH_Transmit(XMC_UART0_CH0, a);

uint8_t received_data = 0;

if((XMC_UART_CH_GetStatusFlag(XMC_UART0_CH0) & XMC_UART_CH_STATUS_FLAG_RECEIVE_INDICATION) == 1U)
{
XMC_UART_CH_ClearStatusFlag(XMC_UART0_CH0, XMC_UART_CH_STATUS_FLAG_RECEIVE_INDICATION);
received_data = XMC_UART_CH_GetReceivedData(XMC_UART0_CH0);
if (received_data == a)XMC_GPIO_ToggleOutput(XMC_GPIO_PORT0,6);
}
}
}
0 Likes
0 Replies